Reputation: 1577
I am trying to do an inverse FFT in Matlab, but I can't seem to get the inverse working correctly. Here is my code:
data = [-0.0005
-0.0004
-0.0003
-0.0002
-0.0001
-0.0000
0.0001
0.0001
0.0001
0.0002
0.0002
0.0002
0.0002
0.0002
0.0002
0.0002
0.0002
0.0002
0.0003
0.0004
0.0005
0.0006
0.0007
0.0009
0.0010
0.0011
0.0011
0.0012
0.0011
0.0011
0.0011
0.0010 ];
%plot data
figure(1)
plot(data)
%FFT
N = 100;
X = fft(data, N);
F = [-N/2:N/2-1]/N;
F = F/0.0125;
X = fftshift(X);
figure(2)
plot(F, abs( X ) )
%inverse FFT
y = ifft(X);
figure(3)
plot(F,y)
Figure 1 and 3 should be identical, but are not in any way. I made sure not to take ifft
of the absolute value of fft
, so it's not clear to me what is wrong.
Upvotes: 0
Views: 223
Reputation: 65430
Since you shifted the spectrum using fftshift
, you have to "unshift" the spectrum prior to taking the inverse Fourier transform
y = ifft(fftshift(X));
Upvotes: 1