- What happens if I choose the length of signal L > NFFT? and what's about choosing L different form NFFT?
Did you read the documentation? http://www.mathworks.com/help/techdoc/ref/fft.html
Y = fft(X,n) returns the n-point DFT. fft(X) is equivalent to fft(X, n) where n is the size of X in the first nonsingleton dimension. If the length of X is less than n, X is padded with trailing zeros to length n. If the length of X is greater than n, the sequence X is truncated. When X is a matrix, the length of the columns are adjusted in the same manner.
So it just ignores the signal after n samples.
2 In the following code, I'm not sure if I used window correctly.
Yep. You just multiply the window by the signal:
But when I use window (hanning in the following code), I can't get the exact values of amplitudes?
Yes, It attenuates anything at the ends of the window, so the amplitude varies depending on when the window hits the signal. If there's a huge peak in the signal, but it happens at the end of the window, it gets multiplied by 0. If it happens in the middle of the window, it gets multiplied by 1.
For signals that are stationary across the window, then it doesn't matter when the window is applied to the signal, right? So you can just multiply by a constant (2 for a Hann window, I think, because the area under the window is 0.5) to get the true amplitude.
Also, if you use overlapped windows and certain windows (constant-overlap-add (COLA) constraint), I believe you can combine them to get the true amplitude for any waveform, even non-stationary ones. https://ccrma.stanford.edu/~jos/sasp/Overlap_Add_Decomposition.html
3 When L and NFFT get different values (I mean when I change L and NFFT,) then the values of amplitudes were different too. How can I get the exact value of amplitude of input signal?
The signal is stationary, so it shouldn't really matter how much of it you measure. To get the true amplitude you probably need to divide by N, depending on matlab's implementation. https://gist.github.com/236567