1
\$\begingroup\$

How do we interpret frequency from fft command in matlab? When I apply fft to a sampled function(@ Fs) and I get peaks at some values in the fft array. How do I know what frequency in Hertz does it correspond to?

\$\endgroup\$
1
  • \$\begingroup\$ watch out for the fact that MATLAB arrays are 1-based, not 0-based, so the DC (zero frequency) term is in array[1], not array[0] \$\endgroup\$
    – Neil_UK
    Commented Jul 3, 2019 at 17:05

1 Answer 1

4
\$\begingroup\$

The output of the fft function will go from 0 Hz to fs/2, then -fs/2 to almost 0. If you ignore the 2nd half (for purely real signals), the following works well:

For n samples at a sampling rate of fs, you can create a frequency axis, f with the following formula:

f = (0:n-1)/n*fs

This gives you freqs from fs/2 to almost fs, but if you overlook that...

The other option is to use the fftshift command on the fft output and revise the formula

f = (0:n-1)/n*fs-fs/2

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.