Possible fine-detail error in Matlab fft?

15 views (last 30 days)
Tran Trung Luu
Tran Trung Luu on 15 Mar 2021
Commented: David Freiman on 19 Feb 2022
Dear all,
I often work with FFT and I like the fft function from Matlab a lot:
However, recently I encoutered a possible problem with the current implementation of Matlab:
In the standard calculation of the frequency axis that I extracted from the above link:
f = Fs*(0:(L/2))/L;
Fs is the sampling frequency and L is the length of the signal, it seems that the frequency step (the distance between two consecutive frequencies in the frequency axis) is Fs/L. This is usually not a problem if L is large enough, for example in this case. However, when I deal with small L, for example L = 5, then I realize that the frequency step is actually not the inverse of the total time window, which it should theoretically be. If I want to do this theoretically perfect, I had to use Fs/(L-1) but then this is not compatible with how the fft is done in Matlab, i.e. I got inconsistency of frequency peaks' position. It seems to me that the fft was not implemented with "perfect theoretical consideration".
Could you please advise/comment? Or you think I missed something?
Thanks and best regards,
Trung

Answers (1)

Prabhan Purwar
Prabhan Purwar on 21 Mar 2021
Hi,
As the frequency resolution is defined as Fs/L, both the implementation and example seem rightly scaled and working as expected. If you can provide the calculations and steps you have tried, documents you have referred it will be helpful in resolving and understanding the issue more clearly.
Thanks
  2 Comments
David Freiman
David Freiman on 19 Feb 2022
Hi Trung,
I recently had a similar question and came across this post. I believe the resolution to this issue lies in the fact that for a discrete time signal as you describe above, with N=3, the time window is actually 3 * dt, because each sample point represents a time of dt.
In the past I have made the mistake of calculating the time window as t(N) - t(1). As you pointed out above, this would barely be noticeable for a large N of, say, 1000. However, when recently checking some code with a very low number of samples, N, I realized that the time window should be calculated as:
T = N * dt = N / Fs
So delta F would be 1 / T = Fs / N
Please let me know if you have any questions or see any errors in my logic.
Thank you,
Dave

Sign in to comment.

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by