I am having a hard time understanding what should be a simple concept. I have constructed a vector in MATLAB that is real and symmetric. When I take the FFT in MATLAB, the result has a significant imaginary component, even though the symmetry rules of the Fourier transform say that the FT of a real symmetric function should also be real and symmetric. My example code:
我很难理解什么应该是一个简单的概念。我在MATLAB中构建了一个真实和对称的向量。当我在MATLAB中使用FFT时,结果有一个重要的虚数分量,即使傅里叶变换的对称规则说,一个实对称函数的FT也应该是实的和对称的。我的示例代码:
N = 1 + 2^8;
k = linspace(-1,1,N);
V = exp(-abs(k));
Vf1 = fft(fftshift(V));
Vf2 = fft(ifftshift(V));
Vf3 = ifft(fftshift(V));
Vf4 = ifft(ifftshift(V));
Vf5 = fft(V);
Vf6 = ifft(V);
disp([isreal(Vf1) isreal(Vf2) isreal(Vf3) isreal(Vf4) isreal(Vf5) isreal(Vf6)])
Result:
结果:
0 0 0 0 0 0
No combinations of (i)fft
or (i)fftshift
result in a real symmetric vector. I've tried with both even and odd N (N = 2^8
vs. N = 1+2^8
).
没有(i)fft或(i)fftshift的组合导致一个真正的对称向量。我已经尝试了偶数和奇数N (N = 2 8 vs. N = 1+2 8)。
I did try looking at k+flip(k)
and there are some residuals on the order of eps(1)
, but the residuals are also symmetric and the imaginary part of the FFT is not coming out as fuzz on the order of eps(1)
, but rather with magnitude comparable to the real part.
我确实尝试过看k+flip(k),在eps(1)的顺序上有一些残差,但是残差也是对称的,FFT的虚部并不是像eps(1)那样的模糊,而是与实部相当。
What blindingly obvious thing am I missing?
我错过了什么显而易见的东西?
Blindingly obvious thing I was missing:
很明显,我错过了:
The FFT is not an integral over all space, so it assumes a periodic signal. Above, I am duplicating the last point in the period when I choose an even N
, and so there is no way to shift it around to put the zero frequency at the beginning without fractional indexing, which does not exist.
FFT不是对所有空间的积分,所以它假设一个周期信号。上面,我重复了最后一个点,当我选择一个偶数的时候,所以没有办法把它转到零频率,在开始时没有分数索引,这是不存在的。
A word about my choice of k
. It is not arbitrary. The actual problem I am trying to solve is to generate a model FTIR interferogram which I will then FFT to get a spectrum. k
is the distance that the interferometer travels which gets transformed to frequency in wavenumbers. In the real problem there will be various scaling factors so that the generating function V will yield physically meaningful numbers.
关于k的选择,不是任意的。我要解决的实际问题是生成一个FTIR模型,然后我将得到一个频谱。k是干涉仪在波数中变换的距离。在实际问题中,会有各种各样的比例因子,使生成的函数V产生物理意义的数字。
4 个解决方案
#1
5
@Yvon is absolutely right with his comment about symmetry. Your input signal looks symmetrical, but it isn't because symmetry is related to origin 0. Using linspace in Matlab for constructing signals is mostly a bad choice. Trying to repair the results with fftshift is a bad idea too.
@Yvon对对称的评论是绝对正确的。你的输入信号看起来是对称的,但这并不是因为对称与原点相关。在Matlab中使用linspace来构造信号是一个很糟糕的选择。尝试用fftshift来修复结果也是一个坏主意。
Use instead:
使用:
k = 2*(0:N-1)/N - 1;
and you will get the result you expect. However the imaginary part of the transformed values will not be perfectly zero. There is some numerical noise.
你会得到你期望的结果。然而,转换后的值的虚部不会完全为零。有一些数值噪音。
>> max(abs(imag(Vf5)))
ans =
2.5535e-15
Answer to Yvon's question:
Yvon的问题的答案:
Why? >> N = 1+2^4 N = 17 >> x=linspace(-1,1,N) x = -1.0000 -0.8750 -0.7500 -0.6250 -0.5000 -0.3750 -0.2500 -0.1250 0 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 1.0000 >> y=2*(0:N-1)/N-1 y = -1.0000 -0.8824 -0.7647 -0.6471 -0.5294 -0.4118 -0.2941 -0.1765 -0.0588 0.0588 0.1765 0.2941 0.4118 0.5294 0.6471 0.7647 0.8824 – Yvon 1
为什么?> > N = 1 + 2 ^ 4 N = 17 > > x = linspace(1,N)x = 0 -1.0000 -0.8750 -0.7500 -0.6250 -0.8750 -0.7500 -0.6250 -0.8750 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 0.6250 > > y = 2 *(0:N - 1)/ N - 1 y = -1.0000 -0.8824 -0.7647 -0.6471 -0.5294 -0.7647 -0.2941 -0.1765 -0.0588 -0.6471 0.1765 0.2941 0.4118 0.5294 0.6471 0.7647 0.8824 - Yvon 1
Your example is not a symmetric (even) function, but an antisymmetric (odd) function. However, this makes no difference.
您的示例不是对称的(甚至是)函数,而是一个反对称(奇)函数。然而,这没什么区别。
For a antisymmetric function of length N the following statement is true:
对于一个长度为N的反对称函数,下面的语句是正确的:
f[i] == -f[-i] == -f[N-i]
The index i runs from 0 to N-1.
从0到N-1的指数。
Let us see was happens with i=2. Remember, count starts with 0 and ends with 16.
让我们看看i=2的情况。记住,计数以0开始,以16结束。
x[2] = -0.75
-x[N-2] == -x[17-2] == -x[15] = (-1) 0.875 = -0.875
x[2] != -x[N-2]
y[2] = -0.7647
-y[N-2] == -y[15] = (-1) 0.7647
y[2] == y[N-2]
The problem is, that the origin of Matlab vectors start at 1. Modulo (periodic) vectors start with origin 0. This difference leads to many misunderstandings.
问题是,Matlab向量的原点是1。模(周期)向量始于原点0。这种差异导致了许多误解。
Another way of explanation why linspace(-1,+1,N) is not correct:
另一种解释为什么linspace(-1,+1,N)是不正确的:
Imagine you have a vector which holds a single period of a periodic function, for instance a Cosinus function. This single period is one of a infinite number of periods. The first value of your Cosinus vector must not be same as the last value of your vector. However,that is exactly what linspace(-1,+1,N) does. Doing so, results in a sequence where the last value of period 1 is the same value as the first sample of the following period 2. That is not what you want. To avoid this mistake use t = 2*(0:N-1)/N - 1. The distance t[i+1]-t[i] is 2/N and the last value has to be t[N-1] = 1 - 2/N and not 1.
假设你有一个向量,它包含一个周期函数的一个周期,例如一个余弦函数。这个周期是无限个周期中的一个。Cosinus向量的第一个值不能与向量的最后一个值相同。然而,这正是linspace(-1,+1,N)所做的。这样做,结果是一个序列,其中第1周期的最后一个值与第2周期的第一个样本值相同。那不是你想要的。为了避免这个错误,使用t = 2*(0:N-1)/N -1。t[i+1]-t[i]是2/N,最后一个值是t[N-1] = 1 - 2/N而不是1。
Answer to Yvon's second comment
回答Yvon的第二个评论。
Whatever you put in an input vector of a DFT/FFT, by theory it is interpreted as a periodic function. But that is not the point.
无论你输入一个DFT/FFT的输入向量,理论上它被解释为一个周期函数。但这不是重点。
DFT performs an integration.
DFT进行集成。
fft(m) = Sum_(k=0)^(N-1) (x(k) exp(-i 2 pi m k/N )
The first value x(k=0) describes the amplitude of the first integration interval of length 1/N. The second value x(k=1) describes the amplitude of the second integration interval of length 1/N. And so on.
第一个值x(k=0)描述了长度为1/N的第一个积分区间的幅值。第二个值x(k=1)描述了长度为1/N的第二次积分区间的幅值。等等。
The very last integration interval of the symmetric function ends with same value as the first sample. This means, the starting point of the last integration interval is k=N-1 = 1-1/N. Your input vector holds the starting points of the integration intervals.
对称函数的最后一个积分区间以与第一个样本相同的值结束。这意味着,最后一个积分区间的起始点是k=N-1 = 1-1/N。你的输入向量包含积分区间的起始点。
Therefore, the last point of symmetry k=N is a point of the function, but it is not a starting point of an integration interval and so it is not a member of the input vector.
因此,对称k=N的最后一点是函数的一个点,但它不是积分区间的起始点,因此它不是输入向量的一个元素。
#2
8
It's
这是
Vf = fftshift(fft(ifftshift(V)));
That is, you need ifftshift
in time-domain so that samples are interpreted as those of a symmetric function, and then fftshift
in frequency-domain to again make symmetry apparent.
也就是说,你需要在时域上进行ifftshift,使样本被解释为对称函数的样本,然后在频域上进行fftshift,从而再次使对称变得明显。
This only works for N
odd. For N
even, the concept of a symmetric function does not make sense: there is no way to shift the signal so that it is symmetric with respect to the origin (the origin would need to be "between two samples", which is impossible).
这只适用于N个奇数。对于N,对称函数的概念是没有意义的:没有办法改变信号,使它对原点对称(原点需要“两个样本之间”,这是不可能的)。
For your example V
, the above code gives Vf
real and symmetric. The following figure has been generated with semilogy(Vf)
, so that small as well as large values can be seen. (Of course, you could modify the horizontal axis so that the graph is centered at 0 frequency as it should; but anyway the graph is seen to be symmetric.)
对于您的示例V,上面的代码给出了Vf的真实和对称。下面的图是用符号学(Vf)生成的,因此可以看到小的和大的值。(当然,你可以修改水平轴,使图以0频率为中心;不管怎样,这个图是对称的。
#3
2
You have a problem when implementing the concept "symmetry". A purely real, even (or "symmetric") function has a Fourier transform function that is also real and even. "Even" is the symmetry with respect to the y-axis, or the t=0 line.
在实现“对称”这个概念时,您遇到了一个问题。一个纯实的,甚至(或“对称的”)函数有一个傅里叶变换函数,它也是实的,甚至是。“甚至”是关于y轴的对称,或者t=0的直线。
When implementing a signal in Matlab, however, you always start from t=0. That is, there is no way to "define" the signal starting from before the origin of time.
然而,当在Matlab中实现一个信号时,你总是从t=0开始。也就是说,没有办法从时间的起源之前“定义”信号。
Searching the Internet for a while lead me to this - Correct use of fftshift and ifftshift at input to fft and ifft.
在互联网上搜索一段时间,引导我正确地使用fftshift和ifftshift来输入fft和ifft。
As Luis has pointed out, you need to perform ifftshift
before feeding the signal into fft
. The reason has never been documented in Matlab, but only in that thread. For historical reasons, outputs AND inputs of fft
and ifft
are swapped. That is, instead of ordered from -N/2
to N/2-1
(the natural order), the signal in time or frequency domain is ordered from 0
to N/2-1
and then -N/2
to -1
. That means, the correct way to code is fft( ifftshift(V) )
, but most people ignore this at most times. Why it's got silently ignored rather than raising huge problems is that most concerns have been put on the amplitude of signal, not phase. Since circular shifting does not affect amplitude spectrum, this is not a problem (even for the Matlab guys who have written the documentations).
正如Luis指出的,在将信号输入fft之前,需要执行ifftshift。这个原因在Matlab中从未被记录过,但只是在这个线程中。由于历史原因,fft和ifft的输出和输入被交换。也就是说,不是从-N/2到N/2-1(自然顺序),时间或频率域的信号从0到N/2-1,然后-N/2到-1。这意味着,正确的编码方式是fft(ifftshift(V)),但是大多数人在大多数情况下都忽略了这一点。为什么它会默默地被忽视而不是引发巨大的问题呢?大多数的关注都是在信号的幅度上,而不是在相位上。由于循环移位不会影响振幅谱,所以这不是问题(即使是编写文档的Matlab人员)。
To check the amplitude equality -
检查振幅是否相等。
Vf2 = fft(ifftshift(V));
Vf5 = fft(V);
Va2 = abs(fftshift(Vf2));
Va5 = abs(fftshift(Vf5));
>> min(abs(Va2-Va5)<1e-10)
ans =
1
To see how badly wrong in phase -
看看这相位有多糟。
Vp2 = angle(fftshift(Vf2));
Vp5 = angle(fftshift(Vf5));
Anyway, as I wrote in the comment, after copy&pasting your code into a fresh and clean Matlab, it gives 0 1 0 1 0 0
.
无论如何,正如我在评论中所写的,在将代码复制并粘贴到一个新的、干净的Matlab之后,它给出了0 1 0 1 0 0。
To your question about N=even and N=odd, my opinion is when N=even, the signal is not symmetric, since there are unequal number of points on either side of the time origin.
对于你关于N=偶数和N=奇数的问题,我的观点是当N=偶数时,信号是不对称的,因为在时间原点的任意一边都有不相等的点个数。
#4
2
Just add the following line after "k = linspace(-1,1,N);"
只需在“k = linspace(-1,1,N)”后面添加以下一行;
k(end)=[];
it will remove the last element of the array. This is defined to be symmetric array.
它将删除数组的最后一个元素。这被定义为对称数组。
also consider that isreal(complex(1,0)) is false!!! The isreal function just checks for the memory storage format. so 1+0i is not real in the above example.
也要考虑到isreal(complex(1,0))是假的!!!isreal函数只检查内存存储格式。所以1+0i在上面的例子中是不真实的。
You have define your function in order to check for real numbers (like this)
你已经定义了你的函数来检查实数(像这样)
myisreal=@(x) all((abs(imag(x))<1e-6*abs(real(x)))|(abs(x)<1e-8));
Finally your source code should become something like this:
最后,你的源代码应该变成这样:
N = 1 + 2^8;
k = linspace(-1,1,N);
k(end)=[];
V = exp(-abs(k));
Vf1 = fft(fftshift(V));
Vf2 = fft(ifftshift(V));
Vf3 = ifft(fftshift(V));
Vf4 = ifft(ifftshift(V));
Vf5 = fft(V);
Vf6 = ifft(V);
myisreal=@(x) all((abs(imag(x))<1e-6*abs(real(x)))|(abs(x)<1e-8));
disp([myisreal(Vf1) myisreal(Vf2) myisreal(Vf3) myisreal(Vf4) myisreal(Vf5) myisreal(Vf6)]);
#1
5
@Yvon is absolutely right with his comment about symmetry. Your input signal looks symmetrical, but it isn't because symmetry is related to origin 0. Using linspace in Matlab for constructing signals is mostly a bad choice. Trying to repair the results with fftshift is a bad idea too.
@Yvon对对称的评论是绝对正确的。你的输入信号看起来是对称的,但这并不是因为对称与原点相关。在Matlab中使用linspace来构造信号是一个很糟糕的选择。尝试用fftshift来修复结果也是一个坏主意。
Use instead:
使用:
k = 2*(0:N-1)/N - 1;
and you will get the result you expect. However the imaginary part of the transformed values will not be perfectly zero. There is some numerical noise.
你会得到你期望的结果。然而,转换后的值的虚部不会完全为零。有一些数值噪音。
>> max(abs(imag(Vf5)))
ans =
2.5535e-15
Answer to Yvon's question:
Yvon的问题的答案:
Why? >> N = 1+2^4 N = 17 >> x=linspace(-1,1,N) x = -1.0000 -0.8750 -0.7500 -0.6250 -0.5000 -0.3750 -0.2500 -0.1250 0 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 1.0000 >> y=2*(0:N-1)/N-1 y = -1.0000 -0.8824 -0.7647 -0.6471 -0.5294 -0.4118 -0.2941 -0.1765 -0.0588 0.0588 0.1765 0.2941 0.4118 0.5294 0.6471 0.7647 0.8824 – Yvon 1
为什么?> > N = 1 + 2 ^ 4 N = 17 > > x = linspace(1,N)x = 0 -1.0000 -0.8750 -0.7500 -0.6250 -0.8750 -0.7500 -0.6250 -0.8750 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 0.6250 > > y = 2 *(0:N - 1)/ N - 1 y = -1.0000 -0.8824 -0.7647 -0.6471 -0.5294 -0.7647 -0.2941 -0.1765 -0.0588 -0.6471 0.1765 0.2941 0.4118 0.5294 0.6471 0.7647 0.8824 - Yvon 1
Your example is not a symmetric (even) function, but an antisymmetric (odd) function. However, this makes no difference.
您的示例不是对称的(甚至是)函数,而是一个反对称(奇)函数。然而,这没什么区别。
For a antisymmetric function of length N the following statement is true:
对于一个长度为N的反对称函数,下面的语句是正确的:
f[i] == -f[-i] == -f[N-i]
The index i runs from 0 to N-1.
从0到N-1的指数。
Let us see was happens with i=2. Remember, count starts with 0 and ends with 16.
让我们看看i=2的情况。记住,计数以0开始,以16结束。
x[2] = -0.75
-x[N-2] == -x[17-2] == -x[15] = (-1) 0.875 = -0.875
x[2] != -x[N-2]
y[2] = -0.7647
-y[N-2] == -y[15] = (-1) 0.7647
y[2] == y[N-2]
The problem is, that the origin of Matlab vectors start at 1. Modulo (periodic) vectors start with origin 0. This difference leads to many misunderstandings.
问题是,Matlab向量的原点是1。模(周期)向量始于原点0。这种差异导致了许多误解。
Another way of explanation why linspace(-1,+1,N) is not correct:
另一种解释为什么linspace(-1,+1,N)是不正确的:
Imagine you have a vector which holds a single period of a periodic function, for instance a Cosinus function. This single period is one of a infinite number of periods. The first value of your Cosinus vector must not be same as the last value of your vector. However,that is exactly what linspace(-1,+1,N) does. Doing so, results in a sequence where the last value of period 1 is the same value as the first sample of the following period 2. That is not what you want. To avoid this mistake use t = 2*(0:N-1)/N - 1. The distance t[i+1]-t[i] is 2/N and the last value has to be t[N-1] = 1 - 2/N and not 1.
假设你有一个向量,它包含一个周期函数的一个周期,例如一个余弦函数。这个周期是无限个周期中的一个。Cosinus向量的第一个值不能与向量的最后一个值相同。然而,这正是linspace(-1,+1,N)所做的。这样做,结果是一个序列,其中第1周期的最后一个值与第2周期的第一个样本值相同。那不是你想要的。为了避免这个错误,使用t = 2*(0:N-1)/N -1。t[i+1]-t[i]是2/N,最后一个值是t[N-1] = 1 - 2/N而不是1。
Answer to Yvon's second comment
回答Yvon的第二个评论。
Whatever you put in an input vector of a DFT/FFT, by theory it is interpreted as a periodic function. But that is not the point.
无论你输入一个DFT/FFT的输入向量,理论上它被解释为一个周期函数。但这不是重点。
DFT performs an integration.
DFT进行集成。
fft(m) = Sum_(k=0)^(N-1) (x(k) exp(-i 2 pi m k/N )
The first value x(k=0) describes the amplitude of the first integration interval of length 1/N. The second value x(k=1) describes the amplitude of the second integration interval of length 1/N. And so on.
第一个值x(k=0)描述了长度为1/N的第一个积分区间的幅值。第二个值x(k=1)描述了长度为1/N的第二次积分区间的幅值。等等。
The very last integration interval of the symmetric function ends with same value as the first sample. This means, the starting point of the last integration interval is k=N-1 = 1-1/N. Your input vector holds the starting points of the integration intervals.
对称函数的最后一个积分区间以与第一个样本相同的值结束。这意味着,最后一个积分区间的起始点是k=N-1 = 1-1/N。你的输入向量包含积分区间的起始点。
Therefore, the last point of symmetry k=N is a point of the function, but it is not a starting point of an integration interval and so it is not a member of the input vector.
因此,对称k=N的最后一点是函数的一个点,但它不是积分区间的起始点,因此它不是输入向量的一个元素。
#2
8
It's
这是
Vf = fftshift(fft(ifftshift(V)));
That is, you need ifftshift
in time-domain so that samples are interpreted as those of a symmetric function, and then fftshift
in frequency-domain to again make symmetry apparent.
也就是说,你需要在时域上进行ifftshift,使样本被解释为对称函数的样本,然后在频域上进行fftshift,从而再次使对称变得明显。
This only works for N
odd. For N
even, the concept of a symmetric function does not make sense: there is no way to shift the signal so that it is symmetric with respect to the origin (the origin would need to be "between two samples", which is impossible).
这只适用于N个奇数。对于N,对称函数的概念是没有意义的:没有办法改变信号,使它对原点对称(原点需要“两个样本之间”,这是不可能的)。
For your example V
, the above code gives Vf
real and symmetric. The following figure has been generated with semilogy(Vf)
, so that small as well as large values can be seen. (Of course, you could modify the horizontal axis so that the graph is centered at 0 frequency as it should; but anyway the graph is seen to be symmetric.)
对于您的示例V,上面的代码给出了Vf的真实和对称。下面的图是用符号学(Vf)生成的,因此可以看到小的和大的值。(当然,你可以修改水平轴,使图以0频率为中心;不管怎样,这个图是对称的。
#3
2
You have a problem when implementing the concept "symmetry". A purely real, even (or "symmetric") function has a Fourier transform function that is also real and even. "Even" is the symmetry with respect to the y-axis, or the t=0 line.
在实现“对称”这个概念时,您遇到了一个问题。一个纯实的,甚至(或“对称的”)函数有一个傅里叶变换函数,它也是实的,甚至是。“甚至”是关于y轴的对称,或者t=0的直线。
When implementing a signal in Matlab, however, you always start from t=0. That is, there is no way to "define" the signal starting from before the origin of time.
然而,当在Matlab中实现一个信号时,你总是从t=0开始。也就是说,没有办法从时间的起源之前“定义”信号。
Searching the Internet for a while lead me to this - Correct use of fftshift and ifftshift at input to fft and ifft.
在互联网上搜索一段时间,引导我正确地使用fftshift和ifftshift来输入fft和ifft。
As Luis has pointed out, you need to perform ifftshift
before feeding the signal into fft
. The reason has never been documented in Matlab, but only in that thread. For historical reasons, outputs AND inputs of fft
and ifft
are swapped. That is, instead of ordered from -N/2
to N/2-1
(the natural order), the signal in time or frequency domain is ordered from 0
to N/2-1
and then -N/2
to -1
. That means, the correct way to code is fft( ifftshift(V) )
, but most people ignore this at most times. Why it's got silently ignored rather than raising huge problems is that most concerns have been put on the amplitude of signal, not phase. Since circular shifting does not affect amplitude spectrum, this is not a problem (even for the Matlab guys who have written the documentations).
正如Luis指出的,在将信号输入fft之前,需要执行ifftshift。这个原因在Matlab中从未被记录过,但只是在这个线程中。由于历史原因,fft和ifft的输出和输入被交换。也就是说,不是从-N/2到N/2-1(自然顺序),时间或频率域的信号从0到N/2-1,然后-N/2到-1。这意味着,正确的编码方式是fft(ifftshift(V)),但是大多数人在大多数情况下都忽略了这一点。为什么它会默默地被忽视而不是引发巨大的问题呢?大多数的关注都是在信号的幅度上,而不是在相位上。由于循环移位不会影响振幅谱,所以这不是问题(即使是编写文档的Matlab人员)。
To check the amplitude equality -
检查振幅是否相等。
Vf2 = fft(ifftshift(V));
Vf5 = fft(V);
Va2 = abs(fftshift(Vf2));
Va5 = abs(fftshift(Vf5));
>> min(abs(Va2-Va5)<1e-10)
ans =
1
To see how badly wrong in phase -
看看这相位有多糟。
Vp2 = angle(fftshift(Vf2));
Vp5 = angle(fftshift(Vf5));
Anyway, as I wrote in the comment, after copy&pasting your code into a fresh and clean Matlab, it gives 0 1 0 1 0 0
.
无论如何,正如我在评论中所写的,在将代码复制并粘贴到一个新的、干净的Matlab之后,它给出了0 1 0 1 0 0。
To your question about N=even and N=odd, my opinion is when N=even, the signal is not symmetric, since there are unequal number of points on either side of the time origin.
对于你关于N=偶数和N=奇数的问题,我的观点是当N=偶数时,信号是不对称的,因为在时间原点的任意一边都有不相等的点个数。
#4
2
Just add the following line after "k = linspace(-1,1,N);"
只需在“k = linspace(-1,1,N)”后面添加以下一行;
k(end)=[];
it will remove the last element of the array. This is defined to be symmetric array.
它将删除数组的最后一个元素。这被定义为对称数组。
also consider that isreal(complex(1,0)) is false!!! The isreal function just checks for the memory storage format. so 1+0i is not real in the above example.
也要考虑到isreal(complex(1,0))是假的!!!isreal函数只检查内存存储格式。所以1+0i在上面的例子中是不真实的。
You have define your function in order to check for real numbers (like this)
你已经定义了你的函数来检查实数(像这样)
myisreal=@(x) all((abs(imag(x))<1e-6*abs(real(x)))|(abs(x)<1e-8));
Finally your source code should become something like this:
最后,你的源代码应该变成这样:
N = 1 + 2^8;
k = linspace(-1,1,N);
k(end)=[];
V = exp(-abs(k));
Vf1 = fft(fftshift(V));
Vf2 = fft(ifftshift(V));
Vf3 = ifft(fftshift(V));
Vf4 = ifft(ifftshift(V));
Vf5 = fft(V);
Vf6 = ifft(V);
myisreal=@(x) all((abs(imag(x))<1e-6*abs(real(x)))|(abs(x)<1e-8));
disp([myisreal(Vf1) myisreal(Vf2) myisreal(Vf3) myisreal(Vf4) myisreal(Vf5) myisreal(Vf6)]);