MATLAB: Multiple Power Spectral Density spectra on one plot

MATLABmultiple plotsperiodogrampsd

Hello,
I have calculated the PSD spectrum of a signal and displayed it from 0-500Hz using the following code:
periodogram(M3A,[],'onesided',512,1000)
I would like to display the spectrum up to 2000Hz, and then plot another spectrum on the same graph for comparison.
Please could someone point me in the right direction?
Best Regards
Andy

Best Answer

Hi Andy, sorry now I understand. You can do this:
% I'll just create an example
Fs = 44100;
t = 0:1/Fs:1-1/Fs;
M3AnO = cos(2*pi*1000*t)+randn(size(t));
M3A = cos(2*pi*500*t)+filter(1,-0.9,rand(size(t)));
[Pxx1,Fxx] = periodogram(M3AnO,[],length(M3AnO),Fs);
[Pxx2,Fxx] = periodogram(M3A,[],length(M3A),Fs);
plot(Fxx,10*log10(Pxx1)); hold on;
plot(Fxx,10*log10(Pxx2),'r'); hold on;
set(gca,'xlim',[0 2000]);
legend('M3AnO','M3A','Location','NorthEast');
xlabel('Hz'); ylabel('dB/Hz');