FFT, dominant frequency doesnt match time domain?

Hi
I have mutiple (relativly) noisy sine waves that i need to analyse (signal at 256Hz). A major assumption in my project is that i am aware of the frequency. So i ran an FFT in order to detremine the amplitudes. However, i seem to run into an issue with some sinewaves, were the expected frequencies are not correct. This following code seems to have an impact before i run the fft on the signal.
tendIn=size(y,2)/256;
tendFFT=tendIn-mod(tendIn,Tw);
tendFFTindex=(tendFFT*256)-mod(tendFFT*256,2);
y=y(1:tendFFTindex);
For example: I expect a dominant sine wave frequency of 0.2Hz and when i leave the code above it shows just that. But when i plot it in time domain it seems that frequncy is off (and so is the ampltiude). Now if i comment the above code and run the FFT on the data directly i seem to acheive the right frequency (which would make my assumption that the frequency is 0.2Hz incorrect).
This occurs on some of the sinewaves. I want to go with my gut instinct and trust that the time domian is correct (and my assumption is wrong) but the above code seems to make sense so i dont know were i went wrong.
Note: This wave may or maynot be impacted by reflected wave (same sinewave reflected).However, all sinewaves would be effected yet not all have this promblem.
Thanks

4 Comments

OK, ya got me---what is the above supposed to be doing/representing?
W/o the actual signal, not sure what we're able to tell...
So the above code cuts some of the last signal points to ensure full sine waves. So for example if signal has 3.2 sinewaves at the assumed freqeuncy (from period Tw), then its cuts it down to 3 sinewaves. Does that make sense?
So attach a .mat file or the code to generate/illustrate the specific cases with what you think is a problem...we still can't diagnose what we can't see.
Sorry, I had to rewrite some of the code. I have attached the code. Hope it demonstrates my point.
Thank you

Sign in to comment.

 Accepted Answer

Your problem is simply that the dominant frequency isn't the same as one of the frequency bin midpoints depending on the number of elements in the FFT
When the sample frequency is fixed at 256 Hz, then the frequency resolution is Fs/L and that may not be precisely divisible by 0.2000 Hz.
In your first case it is, in the second it isn't.
To see what's happening, plot the PSDs and compare --
You see both estimated the frequency as close as they could, just in the first case the center frequency is precisely centered on 0.2 Hz, in the second the closest frequency bin to 0.2 Hz is 0.1875 Hz so there's power in noncomputed bins on either side. Similarly, owing to the noise, you see spreading of energy around the nominal 0.2 Hz in the even case as well; the integral of the two peaks for the total power will be pretty similar.
You would probably get better results if you also were to use a windowing function and then if it is true that you do always know precisely the input signal frequency, then use NFFT to match the bin center frequency to the known frequency.
Your resulting time trace is out of whack because you used the bin center frequency which is off by enough that it really shows up over a number of cycles.

4 Comments

dpb
dpb on 11 Jun 2021
Edited: dpb on 11 Jun 2021
That is, the moral of the story is that FFT will ESTIMATE to the best of its ability the frequency of the input signal, but only can report values as close as the nearest bin spacing to the actual input frequency.
The user has to recognize the limitations of just how close bin spacing is and treat the returned frequency and peak appropriately.
As noted, it may be advangeous to use other values for NFFT besides length(input) if certain specific frequencies are known to be wanted, precisely, such that bins will match up with those.
Also, for such high sampling rates and low frequencies of interest, you might investigate the ZOOM FFT that does a mix/translation to get the resolution but over a narrower range to shift the input signal frequency into a baseband region.
So far, TMW hasn't introduced zoom FFT into base product or Signal Processing (why???) but is in the DSP TB that I don't have.
dpb
dpb on 11 Jun 2021
Edited: dpb on 11 Jun 2021
One last comment -- it would undoubtedly be instructive to do the above exercise on the noise-free signal as well...
Intresting. I have accepted this answer.
Further questions if you wish to answer:
Just to confirm my understanding the intial code that minimises the signal to fit whole sine waves is the correct process?
Also, if the "real" frequency is slightly off from the bin centre, then from the plots such "real" frequency for this signal should be closer to 0.185Hz than 0.2Hz, as the 0.185Hz is a better fit?
Could you possibly explain why it appears that there is more spread and less amptlitude in case(1) than (2), yet in the noise-free figure the case(1) has less spread and more ampltiude? My opinion based on the above answer and limited knowldge would be that the incorrect bin size spacing (case(2)) would result in less accurate modelling of signal noise, as it results in adding the spread to the 0.185Hz bin. Is this understanding correct?
Thank You
You have to integrate the whole peak to get the total energy, not just use the single bin point estimate.

Sign in to comment.

More Answers (0)

Asked:

on 10 Jun 2021

Commented:

dpb
on 11 Jun 2021

Community Treasure Hunt

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

Start Hunting!