IFFT on symmetric spectral data giving complex result?

9 vues (au cours des 30 derniers jours)
Christian Taylor
Christian Taylor le 11 Nov 2024
Commenté : Bruno Luong le 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?

Réponse acceptée

Bruno Luong
Bruno Luong le 11 Nov 2024
Modifié(e) : Bruno Luong le 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 commentaires
Paul
Paul le 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())
ans = logical
1
timeit(f1)
ans = 1.1295
timeit(f2)
ans = 0.8026
Bruno Luong
Bruno Luong le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by