smyslov
smyslov

Reputation: 1275

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.

Upvotes: 1

Views: 695

Answers (2)

Reza Javan
Reza Javan

Reputation: 1

You can use the below code in Matlab.

assume you have two signal, signal1, and signal2.

rmc = lteRMCDL('R.0');
[signal1,~,info] = lteRMCDLTool(rmc,[1;0;0;1]); %

signal2 = 100*signal1;

scope = dsp.SpectrumAnalyzer;
scope.PlotAsTwoSidedSpectrum = true;
scope.SampleRate = info.SamplingRate; 

% You should replace your samplerate whit info.samplerate

scope([signal1 signal2])

Upvotes: 0

willpower2727
willpower2727

Reputation: 789

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

Upvotes: 1

Related Questions