IFFT on symmetric spectral data giving complex result?
7 views (last 30 days)
Show older comments
Christian Taylor
on 11 Nov 2024
Commented: Bruno Luong
on 11 Nov 2024
I have a single sided frequency spectrum which I am attempting to convert into a real time domain signal using the matlab IFFT function. I understand that I need to ensure the spectrum is complex conjugate symmetric in order for the output of the IFFT function to be purely real, however that doesn't seem to have worked and I can't see what I'm doing wrong. The relevant code I'm using is as follows:
twoSidedSpectrum = [singleSpectrum(1:end); flipud(conj(singleSpectrum(2:end)));
timeSignal = ifft(twoSidedSpectrum);
Note that singleSpectrum is odd in length, therefore twoSidedSpectrum is odd in length also. I would have though this would produce a purely real ifft output?
0 Comments
Accepted Answer
Bruno Luong
on 11 Nov 2024
Edited: Bruno Luong
on 11 Nov 2024
assert(isreal(singleSpectrum(1)), 'first element must be real');
twoSidedSpectrum = [singleSpectrum(1:end); flipud(conj(singleSpectrum(2:end)));
timeSignal = ifft(twoSidedSpectrum);
6 Comments
Paul
on 11 Nov 2024
Bruno's comment with implicit zero padding seems to be faster than my comment with explicit zero padding.
I wonder if that's because ifft is smart enough to realize that it does not need to fully construct the full vector in the implicit case for the particular X and NFFT input.
rng(100);
N = 1e7;
X = [rand; rand(N,1)+1j*rand(N,1)]; % odd case
f1 = @() ifft([X;zeros(N,1)],'symmetric'); % explicit
f2 = @() ifft(X,2*numel(X)-1,'symmetric'); % implicit
isequal(f1(),f2())
timeit(f1)
timeit(f2)
Bruno Luong
on 11 Nov 2024
I wonder if that's because ifft is smart enough to realize that it does not need to fully construct the full vector in the implicit case for the particular X and NFFT input
It must be the case. Whenn I interface FFTW they have all such options and more. Matlab uses tthe same library.
More Answers (0)
See Also
Categories
Find more on Spectral Measurements 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!