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

조회 수: 5 (최근 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 CenterFile Exchange에서 Discrete 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