The frequency from FFT given sample rate

199 Views Asked by At

I have a dataset with some data that's recorded daily. I have a strong sinusoidal trend I want to extract using FFT in MATLAB. However, I don't exactly get what it is I'm seeing. The frequency output of the FFT or DFT is expressed in cycles per unit of the sampling rate, so an output of 4 should then be 4 times per day. However, the trend I'm seeing is only one time per year. Can someone explain how I would go about extracting this frequency from the data? See the graphs below:

The data in question https://i.stack.imgur.com/fIXkU.jpg

FFT of the data https://i.stack.imgur.com/28X4S.jpg

1

There are 1 best solutions below

0
On BEST ANSWER

The FFT gives you the components of the signal as sinusoids, whose frequencies are multiples of a base frequency given by the data you are feeding (assuming the whole signal is one period). If you have $n$ samples per year and your signal is $N$ samples long, then the frequency of the $k$th coefficient of the FFT is $kn/N$ (in $year^{-1}$). Note that coefficients of the FFT are symmetrical wrt $N/2$. To find the coefficients of low frequencies, look at the first few coefficients of the FFT (the first is the mean of the signal, if you have the factor $1/N$ in the direct FFT - this depends on the implementation).

Since you have a sample over a whole number of periods it should be easy to find the frequency: you should get a high coefficient at $k=3$ (which corresponds to the frequency you are looking for). The plot may be more readable if you plot vertical bars instead of joining points. Things get messy when the sample is not a whole number of periods, then the high coefficients are scattered around the one you are looking for.

Here is an example in R, that should be easy to reproduce in Matlab

N <- 300
k <- seq(0, N-1)
x <- cos(2*pi*k/N*3)
plot(x, type="l")
z <- fft(x)
plot(abs(z[1:10]), type="h")

x <- cos(2*pi*k/N*3.61)
plot(x, type="l")
z <- fft(x)
plot(abs(z[1:10]), type="h")

The first two plot show the signal and the first coefficients of the FFT for a case similar to yours, but simplified: there is only one frequency. The peak is at $4$ because the plot starts indexing at $1$ (so it's actually the $3$th coefficient.

enter image description here enter image description here

Then let's have a look at a less simple frequency. Now a single sinusoid yields many coefficients.

enter image description here enter image description here