Robochameleon  v1.0
spectra.m
Go to the documentation of this file.
1 
2 function [ f, spectrum ] = spectra(y, Fs , plotS)
3 
4 L=length(y);
5 NFFT = 2^nextpow2(L); % Next power of 2 from length of y
6 % NFFT = 2^14;
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
10 
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))])
16 
17  xlim([0 Fs/2*1e-9])
18  grid on
19  ylabel('dBm')
20  xlabel('GHz')
21  box on
22 end
23 end
24 
function spectra(in y, in Fs, in plotS)
Returns the single-sided amplitude spectrum and plots (optional)