Sampling frequency in fft analysis.

Dear Friends, i have daily(one day one value) data for 5 years. How to give the time (sampling frequency) in fft analysis. Here i attaching the code. Please correct it and give me suggestions. Here attaching the data also (txt), Thanking you
X=xlsread('data.xlsx');
xfft = fft(X(:,2));
n=length('enter the length of fft');
DT = X(2,1)-X(1,1);
% sampling frequency
Fs = 1/DT;
DF = Fs/size(X,1);
freq = 0:DF:Fs/2;
xfft = xfft(1:length(xfft)/2+1);
plot(freq,abs(xdft));
xlabel ('Frequency');
ylabel ('power');
title('S-fft')

 Accepted Answer

FFT algorithm doesn't care what the sampling rate is; your rate is 1/Day so that's the frequency. You can convert to any other frequency you desire of per year by dividing by average of 365.25 day/year or to conversely to hourly or whatever by multiplying by the appropriate scaling factor in the computation of dF for Fs.
See the example at
doc fft
for the way to compute the sampling frequency and normalize to the length of the FFT vis a vis the sample length; note that the computation is totally independent of the actual x value; the frequency axis is purely dependent upon the units you choose.

2 Comments

Thank you, So we can give sampling frequency depends on our data and our desire. Can i find any example fft codes for different time scales. Sorry for my poor communication skills.
dpb
dpb on 16 Oct 2017
Edited: dpb on 16 Oct 2017
That's the point -- there is nothing in the fft itself that has anything whatsoever to do with the actual sample rate; that's totally dependent upon your externally set sampling rate vector for display/plotting.
Of course, for the resulting amplitude peaks to be at the correct frequency, you have to make the sample dt correspond to the actual sampling rate of the data. But, starting from there you can change scale by converting any one time measurement to its equivalent in different units but that's simply unit conversion and again has nothing to do with the FFT itself.
1 day*24 hr/day-->24 hr*60sec/hr-->1440 sec*1000 msec/sec-->1.44E6 msec--> ...
1 day/7 day/week-->0.14286 week/52 week/yr-->0.00275 yr ...
It's simply a scaling factor whichever direction you wish to go from wherever you start into whatever units you wish. Frequency then is simply the reciprocal of time units.

Sign in to comment.

More Answers (0)

Asked:

on 15 Oct 2017

Edited:

dpb
on 16 Oct 2017

Community Treasure Hunt

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

Start Hunting!