FFT / IFFT question .
Show older comments
I have a 4000 points time history rectangular pulse described as
t=linspace(0,0.4,4000);
for i=1:4000 if t(i)>=0&t(i)<=0.01 r(i)=1e5; else r(i)=0; end end
in the frequency domain i have :
y=r; L=length(y); Fs=L/0.4; NFFT = L; % Next power of 2 from length of y Y = fft(y,NFFT); f = Fs/2*linspace(0,1,NFFT/2);
The issue is :
If i use ifft(Y) i got the original time history (obviously) - no problem
but if i take half of the frequency domain vector and use ifft with the symmetric argument i got messed up time hystory . WHY ????
J=Y(1:NFFT/2+1); TD=ifft(J, 'symmetric');
TD is not the original time domain pulse . What am i missing here ?
Accepted Answer
More Answers (1)
Knut
on 5 Dec 2011
Actually:
>> ifft([1 2 3 2 1], 'symmetric')
ans =
2.2000 -0.5236 -0.0764 -0.0764 -0.5236
>> ifft([1 2 3 NaN inf], 'symmetric')
ans =
2.2000 -0.5236 -0.0764 -0.0764 -0.5236
2 Comments
Wayne King
on 5 Dec 2011
Hi Knut, that is correct, but that is not what the OP was doing. He was trying to do this.
rng default;
x = randn(8,1);
xdft = fft(x);
% Now truncate the DFT to only include DC up to and including the Nyquist
ifft(xdft(1:5),'symmetric');
That does not work. The OP was attempting to just provide ifft() from DC to the Nyquist.
Knut
on 5 Dec 2011
Ah, I made the same error myself once. The "logical" way for the symmetric option to work would be that you only supplied the non-redundant vector, and I think that is how the underlying FFTW library works anyways. But in MATLAB it seems that we have to make a dummy vector 2x its needed length, before it gets internally stripped (?) down to 1x prior to calling FFTW.
I was hoping to speedup an application by doing minimal preprocessing before the call to IFFT, when only the non-redundantcoefficients were available to me.
Categories
Find more on Transforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!