This calculation of the frequency vector for the displayed Fourier transform is not the easiest to understand:
The frequency vector generally extends from 0 Hz (the units are actually cycles/(independent variable unit)) to ½ the sampling frequency, called the Nyquist frequency. In this instance, the fft l;ength is the same as the signal length ‘L’ so that is used to calculate the frequency vector. It extends from 0 to ‘L/2’ appropriately.
Going further:
f = Fs*[0 1 2 3 (L/2)]/L
f =
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1673146/image.png)
so the ‘f’ vector goes from 0 to the Nyquist frequency.in steps of ‘Fs/L’ (the default increment for the colon, : operator being 1). The Nyquist frequency is the highest frequency at which a sampled signal can uniquely be described.
This then gets into sampling theory and details that are best left to texttbooks on digital signal processing. That quickly gets complicated, so I will stop here and encourage you to pursue that on your own.
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
X = S + 2*randn(size(t));
plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L
f =
0 0.6667 1.3333 2.0000 2.6667 3.3333 4.0000 4.6667 5.3333 6.0000 6.6667 7.3333 8.0000 8.6667 9.3333 10.0000 10.6667 11.3333 12.0000 12.6667 13.3333 14.0000 14.6667 15.3333 16.0000 16.6667 17.3333 18.0000 18.6667 19.3333
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
title('Single-Sided Amplitude Spectrum of X(t)')
EDIT — (18 Apr 2024 at 20:19)
Clarification added.
.