How to plot period on a x axis of a fourier transformed dataset?
3 views (last 30 days)
Show older comments
Hi,
I have performed a Fourier transform on tide gauge data and I've successfully run the code and produced a plot of frequency (cycles per day) and amplitude (m). In the plot (attached), the largest amplitudes occur at ~2 cycles per day (12 hr and 12.42 hr periods). I would like to plot the period on the x axis and the amplitude on the y axis. How might I accomplish this?
Thanks so much!
Anna
---
dt = 1;
sec_per_day = 24*60*60;
Fs = 1/3600;
t = 0:dt:length(data);
fft_tides = fft(Height);
n = length(fft_tides);
P = abs(fft_tides);
P = P(1:n/2+1);
P = P.^2/(Fs*n);
freq = 0:Fs/length(data):Fs/2;
freq = freq*3600*24; % cycles per day, for plotting purposes
%% gives amplitudes in m P2 = abs(fft_tides)/n;
P2 = 2*P2(1:n/2+1);
figure(1) plot(freq,P2)
xlabel('Frequency, (cycles/day)')
ylabel('Amplitude (m)')
title('FFT Sample example')
0 Comments
Accepted Answer
Star Strider
on 24 Oct 2017
I am not certain what you want.
The period is 1/F, where ‘F’ is frequency, so one way to accomplish that would be to add after the plot:
xt = get(gca, 'XTick');
xp = 1./xt;
set(gca, 'XTick',xt, 'XTickLabel',xp)
If you want increasing values of the period on the x-axis (rather than decreasing as this would plot), use this instead:
set(gca, 'XTick',xt, 'XTickLabel',xp*100, 'XDir','reverse')
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!