0
$\begingroup$

I am having troubles applying the IFFT function to some data I have. I already had a look here Complex conjugate and IFFT and here What assumptions should be used to invert spectrum into time domain data? but it still does not work.

This is the code:

% amplitude: data related to the signal amplitude
% phase: data related to the signal phase
% freq: frequencies (from 5 to 100 Hz)

response = complex(amplitude,phase);

NFFT = length(response); % odd number
symmetric = zeros(NFFT,1); 

for i = 1:NFFT
symmetric(i) = conj(response(mod(NFFT-i+1,NFFT)+1));
end

response_tot = [response; symmetric];

% Plot simmetry
response_tot = fftshift(response_tot);
f_plot = 100*(-NFFT:(NFFT-1))/NFFT;
figure()
plot(f_plot,response_tot)

% Time signal
time_sig = ifft(ifftshift(response_tot));

fs = 2*max_f; % twice the max frequency in the signal
t_plot = 0:1/fs:NFFT/fs; % time vector to plot the time response

figure()
plot(t_plot,time_sig(1:NFFT+1))

Is this the right way to prepare the data for the ifft?

Because the output does not look right to me.

$\endgroup$
  • $\begingroup$ I think you misinterpreted the function complex. It takes its first argument as real and its second argument as imaginary part of the complex number it returns. What you want is response = amplitude .* exp(1i*phase) $\endgroup$ – Deve Dec 11 '14 at 8:29
  • $\begingroup$ That part gave me some problems actually. I have the original plot of the frequency response and the one calculated using complex is equal to the orginal one, whereas if I use amplitude .* exp(1i*phase) I get a negative peak that should not be there. $\endgroup$ – Rhei Dec 12 '14 at 14:07
  • $\begingroup$ I was just thinking...is there any difference in calculating the symmetric part of the vector if N is odd or even? $\endgroup$ – Rhei Dec 12 '14 at 14:15
1
$\begingroup$

The first component of the FFT is the DC component. The other NFFT-1 should be symmetric.
If NFFT is even, that means that

response(NFFT/2-k)=conj(response(NFFT/2+k))

for $k=1,\ldots,NFFT/2-1$ and response(NFFT/2) is arbitrary.
If NFFT is odd then

response((NFFT+1)/2-k)=conj(response((NFFT+1)/2+k+1))

for $k=0,\ldots,(NFFT-1)/2-1$.

However, MATLAB allows you to ignore all that by using the 'symmetric' argument of ifft:

response_tot = [response; zeros(NFFT-1,1)]; % assuming NFFT is odd
time_sig = ifft(response_tot,'symmetric');
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.