how to obtain the frequency when doing the fourier trasform

2 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 2 Jul 2020
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.
.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!