IFFT on symmetric spectral data giving complex result?

54 次查看(过去 30 天)
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?

采纳的回答

Bruno Luong
Bruno Luong 2024-11-11,14:14
编辑:Bruno Luong 2024-11-11,14:22
assert(isreal(singleSpectrum(1)), 'first element must be real');
twoSidedSpectrum = [singleSpectrum(1:end); flipud(conj(singleSpectrum(2:end)));
timeSignal = ifft(twoSidedSpectrum);
  6 个评论
Paul
Paul 2024-11-11,19:55
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())
ans = logical
1
timeit(f1)
ans = 1.1295
timeit(f2)
ans = 0.8026
Bruno Luong
Bruno Luong 2024-11-11,20:16
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Spectral Measurements 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by