the Length of signal in calculating FFT
Asked Answered
P

2

6

I want to ask some questions related to the last question of mine so I don't want to post in another thread. My question contains a code, I therefore can't post it as a comment. So I have to edit my old question into a new one. Please take a look and help. Thank you.

I'm new to FFT and DSP and I want to ask you some questions about calculating FFT in Matlab. The following code is from Matlab help, I just removed the noise.

  1. Can I choose the length of signal L different from NFFT?

  2. I'm not sure if I used window correctly. But when I use window (hanning in the following code), I can't get the exact values of amplitudes?

  3. When L and NFFT get different values, then the values of amplitudes were different too. How can I get the exact value of amplitude of input signal? (in the following code, I used a already known signal to check if the code work correctly. But in case, I got the signal from a sensor and I dont know ahead its amplitude, how can I check?)

I thank you very much and look forward to hearing from you :)

Fs = 1000;                    % Sampling frequency
T = 1/Fs;                     % Sample time
L = 512;                     % Length of signal
NFFT=1024;                   % number of fft points
t = (0:L-1)*T;                % Time vector
x = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);    input signal
X = fft(hann(L).*x', NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,2*abs(X(1:NFFT/2+1)))     % Plot single-sided amplitude spectrum.
Pneumonectomy answered 20/8, 2012 at 15:21 Comment(0)
I
1

You need to apply a window function prior to the FFT to get consistent results with frequency components that have non-integral number of periods within your sampling window.

You might also want to consider using periodogram instead of using the FFT directly - it takes care of window functions and a lot of the other housekeeping for you.

Integration answered 20/8, 2012 at 16:6 Comment(0)
G
2

L is the number of samples in your input signal. If L < NFFT then the difference is zero-padded.

I would recommend you do some reading on the effect of zero-padding on FFTs. Typically it is best to use L = NFFT as this will give you the best representation of your data.

An excepted answer on the use of zero-padding and FFTs is given here: https://dsp.stackexchange.com/questions/741/why-should-i-zero-pad-a-signal-before-taking-the-fourier-transform

In your experiment you are seeing different amplitudes because you will have different amount of spectral leakage with each different L.

Gulp answered 20/8, 2012 at 16:7 Comment(6)
Thanks Markus. I don't know if it works correctly with NFFT=L ? and I heard that if NFFT=2^nextpow(L), the program will work much faster. Is it correct?Pneumonectomy
I have a sensor to record acoustic emission signal as a raw signal at a sample rate at 3MHz from two different process. Then I got a time-base signals. And now I want to compare these signals, using FFT. My questions seem to be stupid, but I'm a student and not specially in DSP. Thanks for your help. Could you please explain to me, what I have to do to analyze these signal?Pneumonectomy
@Mai: did you see the other answer (from me) ? You need to apply a window function and you should also consider using MATLAB's periodogram function instead of using FFT directly.Integration
Mai, Matlab's FFT function will work faster if the length of the FFT is a power-of-2 in length, however padding your input signal to the next power-of-2 does not improve the data and Matlab can handle other FFT lengths. When you increase the length of the FFT you get greater frequency resolution which results in reduced leakage between neighbouring bins. Paul R suggested using windowing - this is also a good way to reduce the spectral leakage and Matlab has many windowing functions for you to try.Gulp
Thank you, Markus and Paul R :)Pneumonectomy
hi Paul, as I know, Periodogram is a function to calculate power spectral density PSD. And PSD is the average of the Fourier transform magnitude squared, over a large time interval ?Pneumonectomy
I
1

You need to apply a window function prior to the FFT to get consistent results with frequency components that have non-integral number of periods within your sampling window.

You might also want to consider using periodogram instead of using the FFT directly - it takes care of window functions and a lot of the other housekeeping for you.

Integration answered 20/8, 2012 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.