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.
complex
. It takes its first argument as real and its second argument as imaginary part of the complex number it returns. What you want isresponse = amplitude .* exp(1i*phase)
$\endgroup$complex
is equal to the orginal one, whereas if I useamplitude .* exp(1i*phase)
I get a negative peak that should not be there. $\endgroup$