This is a question about an example for the software Matlab, but I still chose to ask it here, since I suspect that the question is more about the math involved than the software itself.
I want to use Matlab's Fast Fourier Transform (FFT) algorithm to find out how the frequencies are distributed in a soundsample. However, there is one thing that is bugging me in the example Mathworks has on their website over here. It's probably really obvious, but I just can't seem to understand why they are doing this one thing.
In the example they first create a sample of two sinusoidal waves together with simple white noise. Then they try to extract to frequencies of these two waves from the sample with the help of the FFT-algorithm:
1 NFFT = 2^nextpow2(L); % Next power of 2 from length of y 2 Y = fft(y,NFFT)/L; 3 f = Fs/2*linspace(0,1,NFFT/2+1); 4 % Plot single-sided amplitude spectrum. 5 plot(f,2*abs(Y(1:NFFT/2+1))) 6 title('Single-Sided Amplitude Spectrum of y(t)') 7 xlabel('Frequency (Hz)') 8 ylabel('|Y(f)|')
Now, here is what I don't understand. On line 2 they divide the the transform by L, the amount of samples used, to get Cn, the amplitude of the wave e^inx, right? Then why do they need to multiply this amplitude by 2 on line 5 before they can get the original amplitudes of the two waves.