how to obtain the frequency when doing the fourier trasform

조회 수: 1 (최근 30일)
giacomo labbri
giacomo labbri 2020년 7월 2일
댓글: Star Strider 2020년 7월 3일
Hi,
I am applying the fast fourier trasform to a timeseries. When I plot the transform (or better its absolute value) I would like to have on the x axis a range of frequency but I am not sure how to calculate that.
I am working with data that are each minute and are registered in a timetable.
Thanks in advance,
Giacomo

채택된 답변

Star Strider
Star Strider 2020년 7월 2일
Assuming that the data are regularly sampled, so that the sampling intervals are the same for all of them, I usually do something like this:
y = ...; % Signal (Vector Or Matrix)
t = ...; % Time Vector
Fs = 1/mean(diff(t)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
ym = y - mean(y); % Subtract Column Means From All Columns (Eliminates D-C Offset Effect)
L = numel(t); % Signal Lengths
FTy = fft(ym)/L; % Fourier Transform (Scaled For Length)
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTy(Iv,:))*2)
grid
This calculates and plots a one-sided Fourier transform. You will need to supply ‘t’ and ‘y’. The code should be reasonably robust.
.

추가 답변 (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