2 function [ f, spectrum ] =
spectra(y, Fs , plotS)
5 NFFT = 2^nextpow2(L); % Next power of 2 from length of y
7 Y = fft(y,NFFT)/L; % FFT divided by the length to get the power
8 f = Fs/2*linspace(0,1,NFFT/2+1);% Frequency vector
9 spectrum=2*abs(Y(1:NFFT/2+1)); % Single-sided amplitude spectrum
11 if (plotS && any(spectrum))
12 % s would now be the power spectral density in dBm
13 s = 10*log10(spectrum.*conj(spectrum)*1e3);
14 plot(f*1e-9, s, 'color', [78 101 148]/255, 'LineWidth',1.2)
15 ylim([mean(s) max(s(100:end))])
function spectra(in y, in Fs, in plotS)
Returns the single-sided amplitude spectrum and plots (optional)