How to plot period on a x axis of a fourier transformed dataset?

4 ビュー (過去 30 日間)
Anna Hayden
Anna Hayden 2017 年 10 月 24 日
回答済み: Star Strider 2017 年 10 月 24 日
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')

採用された回答

Star Strider
Star Strider 2017 年 10 月 24 日
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 件)

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by