MATLAB Answers

real data FFT and reconstruction - frequency base issues

22 views (last 30 days)
VMat on 7 Oct 2016
Answered: David Goodmanson on 28 Jun 2021
Hello, and thanks for your time on the following.
I wish to perform FFT and reconstruct the signal 'eta' generated by the script available at
Three main issues:
  1. Sampling rate and frequency interval to produce and plot FFT are not correct
  2. Struggling with signal reconstruction, no clue on how to obtain the original (random) signal
  3. plots axes values appear completely out of scope...
Went through lots of pertinent web posts and trials before asking here. Could you please guide me through to a meaningful solution? And possibly point out to the conceptual errors.
Many thanks.
% t is the time series, defined in the above script
fs = 1/Ts; % Ts is defined in the above script
x = eta; % eta is the original signal for transform and reconstruction
X = fft(x);
n = length(x); % so length of frequency series equal to length of time series to plot X correctly
c = (-1 * fs) / 2:fs / n:fs / 2 - fs / n; % generates the frequency series to plot X in frequency domain
%%pseudo code for plotting
% original signal
% magnitude
% phase response
% real part of Fourier spectrum
% reconstructed signal
% reconstruction by magnitude
% reconstruction by phase
  1 Comment
vimal kumar chawda
vimal kumar chawda on 24 Jun 2021
your information is not complete, can you please rephrase the data and questions

Sign in to comment.

Answers (1)

David Goodmanson
David Goodmanson on 28 Jun 2021
Hi Vmat.
I believe that with 'rec' you may be confusing the time and frequency domains. The code below uses rec for the time domain quantity and rec_f for the freq domain quantity.
First of all, both the time and frequency axes depend only on Ts, so if the scaling seems wrong you will have to go back to the original paper and verify Ts. The frequency scale c is correct, although typographically I think something like in the code below is clearer.
For the magnitude in the frequency domain you may want to use
X = fft(x)/n;
which is common. That will require multiplying the ifft by n in order to make up for the 1/n.
It simply does not work to do an ifft on either magnitude or phase separately in order to reconstruct something in the time domain. It only works to do the ifft on the complex quantity, rec_f in this case.
Ts = 1e-3; % arbitrary
fs = 1/Ts;
n = 1000;
t = (0:n-1)*Ts;
x = sin(100*(t/Ts).^2/n^2);
plot(t,x); grid on
X = fft(x);
% generates the frequency series to plot X in frequency domain
c = -fs/2 : fs/n : fs/2-fs/n;
mag = abs(X);
ph = angle(X);
rec_f = mag.*exp(i*ph);
% original signal
plot(t,x); grid on
% frequency domain plots
% note that since x is real, mag and real are even functions of f and
% angle and imag are odd functions of f
% magnitude
plot(c,fftshift(abs(X))); grid on
% phase response
plot(c,fftshift(angle(X))); grid on
% real part of Fourier spectrum
plot(c,fftshift(real(X))); grid on
% imaginary part of Fourier spectrum
plot(c,fftshift(imag(X))); grid on
% reconstruction in time domain
rec = ifft(rec_f);
plot(t,x,t,rec,'o'); grid on % compare

Community Treasure Hunt

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

Start Hunting!

Translated by