real data FFT and reconstruction - frequency base issues
22 views (last 30 days)
Show older comments
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 http://benjaminbiegel.com/files/oceanWaveGeneration.zip
Three main issues:
- Sampling rate and frequency interval to produce and plot FFT are not correct
- Struggling with signal reconstruction, no clue on how to obtain the original (random) signal
- 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.
ATTEMPT CODE
% 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
mag=abs(X);
ph=angle(X);
rec=mag.*exp(i*ph);
rec=ifft(rec);
%%pseudo code for plotting
% original signal
plot(t,x)
% magnitude
plot(c,fftshift(abs(X))
% phase response
plot(c,angle(X))
% real part of Fourier spectrum
plot(c,real(X))
% reconstructed signal
plot(t,rec)
% reconstruction by magnitude
plot(ifftshift(ifftn(mag)))
% reconstruction by phase
plot(ifft(exp(1i*ph)))
1 Comment
vimal kumar chawda
on 24 Jun 2021
your information is not complete, can you please rephrase the data and questions
Answers (1)
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);
figure(1)
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
figure(1)
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
figure(2)
plot(c,fftshift(abs(X))); grid on
% phase response
figure(3)
plot(c,fftshift(angle(X))); grid on
% real part of Fourier spectrum
figure(4)
plot(c,fftshift(real(X))); grid on
% imaginary part of Fourier spectrum
figure(5)
plot(c,fftshift(imag(X))); grid on
% reconstruction in time domain
rec = ifft(rec_f);
figure(6)
plot(t,x,t,rec,'o'); grid on % compare
0 Comments
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!