MATLAB Answers

Why do I receive results mismatch in the FFT signal while using MATLAB built in FFT function? How can I able to rectify this?

24 ビュー (過去 30 日間)
Gopinath Karuppannan
Gopinath Karuppannan 2021 年 6 月 4 日
編集済み: pepe 2021 年 6 月 22 日
I am imposing a signal such as 60cos(21t) + 40cos(42t) + 20cos(63t). So I am supposed to get the following amplitude and frequency from the FFT signal.
1) Frequency (21), Amplitude (60)
2) Frequency (42), Amplitude (40)
3) Frequency (63), Amplitude (20).
The following script used to obtain the above FFT results:
%% FFT Macro
Start_time = 0;
End_time = 10;
Fs=(1/dt)/2; % Sampling frequency/2
range = End_time-Start_time;
FFT_zone = 1/range; % frequency resolution
NPL = ((range)/dt)+1; % Number of points for local run
IS = (Start_time/dt)+1;
Ns = IS+NPL-1;
Ns1 = (((range)/dt)-150);
columns = 2;
for i=1:columns-1
eval(['Vector_selected1=Rin.signal(:,' num2str(i) ');']); % selection of the run #i
eval(['Vector_selected2=Vector_selected1(' num2str(IS) ':' num2str(Ns) ');']); % selection of the time range for FFT
eval(['FFT_wzd_Run_signal=abs(fft(Vector_selected2))/Ns1;']); % FFT calculated in magnitude ( amplitude Y - axis)
[r,c] = size(Rin.Frequency_vector);
Rin.xx11(1,1) = 0;
%% Just for reference ( i have not given complete steps of plotting macro, error is not in this point)
plot(Rin.t,Rin.signal,'r','LineWidth',2); % subplot 1
plot(Rin.Frequency_vector,(Rin.xx11*2),'r','LineWidth',2); % subplot 2
The following signals are obtained by using the macro.
In the first signal, i am getting the FFT amplitude are almost closer to my expectation. But in the second signal, the FFT amplitudes are deviates from my expectation. In Inputs, The only deviation between both signals are start time and end time.
For signal 1 --> Start time = 0, End time = 10
For signal 2 --> Start time = 4, End time = 6.
Total available signal time = 10 s.
Eventhough both siganl are same, due to the zoomed windowing time leads to the deviation in FFT amplitudes. So i need to avoid this issue.
Kindly help me out on this.
Thanks in advance.

回答 (2 件)

dpb 2021 年 6 月 4 日
If the fundamental frequency doesn't precisely match the frequency bins of the FFT, then the energy will be spread over multiple bins around that center frequency. To get the full power of the peak in that case you must integrate the peak, not just take the value of the peak at the peak frequency.
A few prior Answers may be of interest as well---
Somewhere, sometime, I illustrated the effect of changing the sampling frequency so the output frequency doesn't quite match the input frequencies as does in the example at doc fft but I don't seem to find that particular Answer at the moment. It's not hard to do however, just change the input frequency in the generated signal to not be an exact match of one of the frequency bins with the same sampling parameters or change the sample rate a little to shift where the frequency bins lie and observe the change from a single bin spike to one that has energy in several bins.
  18 件のコメント
dpb 2021 年 6 月 19 日
While it may not help, I doubt it hurts, either... :)
I don't otomh have any idea how to interpret the results without, though...what does it mean unscaled other than purely relative when the magnitudes are dependent upon the length of the input series? What specific analysis would be better for it, you think?
For example, say the input signal of OP's were the input from an accelerometer from a perfectly noise-free machine and if we had sampled for 1 second or, wanting more averaging-out of any noise that might be present, 2 seconds. If we computed the PSD for those two measurements and didn't normalize by the sample length, we would get something like:
Now, while both of those are the same in general (although we'll note the peak spreading in the first owing to the frequency binning not being really well matched with the lower frequency so the actual peak itself is quite under-estimated, if we do integrate we'll be able to estimate the total energy reasonably well), the second tells us we've got something much more dastardly going on in the machine than does the first--but that's not so, it's the same signal.
How can that result be desirable by not normalizing the FFT by the sample length to compensate for the fact the FFT algorithm itself returns the values scaled by the number of samples?
I grant there being alternatives of whether to then scale to the peak or rms value, etc., etc., as to what specifically is the actual scaling/units, but I just can't see the objection to putting both on the same footing with the factor L.


pepe 2021 年 6 月 22 日
編集済み: pepe 2021 年 6 月 22 日
your signal does not have any noise. The way to correct the problem is to correct your time vector. You seem to have:
dt=0.001; t=[0 : dt : 10];
This means that you have 10001 miliseconds. Each time point represents itself and the interval in front of it. The correct way to have 10 seconds (and make your waves have an exact integer number of periods in your signal) is this:
dt=0.001; t=[0 : dt : 10-dt];
Edit your code accordingly.




Community Treasure Hunt

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

Start Hunting!

Translated by