Search code examples
matlabmatlab-figurefrequencyspectrumspectral-density

Multiple PSD in same graph - Matlab


I intend to plot multiple Power Spectral Densities on the same graph. I am using the following to plot the power spectral density for a single signal.

hss = dsp.SpectrumAnalyzer('SampleRate', Fs); 
step(hss,rx);
release(hss);

However, if I were to plot another signal in the same spectrum analyzer using hold on doesn't seem to help

hss = dsp.SpectrumAnalyzer('SampleRate', Fs); 
step(hss,rx); hold on;
step(hss,tx);
release(hss);

Could someone guide me on how to go about with this.

EDIT: Here's a snippet of my code:

Fs = 12e6;
data = randi([0 1],1000,1);
%% OQPSK Modulate data
hMod = comm.OQPSKModulator('BitInput',true); 
tx = step(hMod, data);
%% Add noise
hAWGN = comm.AWGNChannel('EbNo',2);
rx = step(hAWGN, tx);

Now I need a way to plot the PSD of both tx and rx in the same graph.


Solution

  • Ok I think I've figure it out, you need to pass in more than one data to the same step call like so:

    Fs = 12e6;
    hss = dsp.SpectrumAnalyzer('SampleRate', Fs); 
    data = randi([0 1],2000,1);%I had to increase the # of points
    %% OQPSK Modulate data
    hMod = comm.OQPSKModulator('BitInput',true); 
    tx = step(hMod, data);
    %% Add noise
    hAWGN = comm.AWGNChannel('EbNo',2);
    rx = step(hAWGN, tx);
    
    %This is the line that makes it work, passing in a matrix of input data
    step(hss,[rx tx]);
    

    enter image description here