# How to plot in MATLAB the PSD of two signals with different bandwidths

I would like to plot the power spectral density (PSD) of this signal

$$y(t) = x(t) + i(t)$$

where both $$x(t)$$ and $$i(t)$$ are binary phase shift keying (BPSK) signals with baseband bandwidths $$W_x/2$$ and $$W_i/2$$, respectively.

Assuming rectangular pulse shaping, each signal will have a $$sinc$$ PSD, which is centered around $$f_x$$ for $$x(t)$$, and around $$f_i$$ for $$i(t)$$.

Assuming that $$f_i-\frac{W_i}{2} > f_x-\frac{W_x}{2}$$ and $$f_i+\frac{W_i}{2} < f_x+\frac{W_x}{2}$$, how can I generate the signals $$x(t)$$ and $$i(t)$$ in MATLAB, and compare the PSD of $$y(t)$$ with the PSD of each of $$x(t)$$ and $$i(t)$$?

Parameters

N=100;

%Bandwidth
W_x = 200*10^6;
W_i = 50*10^6;

%sampling time
T_x = 1/(2*W_x);
T_i = 1/(2*W_i);

%time axis (these are of different lengths!)
t_x = T_x.*(0:N-1);
t_i = T_i.*(0:N-1);

%carrier frequencies
fx = 100*10^6;
fi = 150*10^6;


I am stuck here. How can I continue from here?

• Do you know the closed form solution for a BPSK spectrum or are you planning to generate the time domain signals and then calculate the PSD from there ? Sep 12, 2022 at 11:48
• It's the latter. I want to calculate the PSD from the time domain signal. Sep 12, 2022 at 11:49
• How did you pick the sampling time (seems under sampled) and $N=100$ (feels way too small) ? Sep 12, 2022 at 11:51
• These are adjustable. I wasn't sure about them. You can consider $N=10^6$ and sampling frequency to be $8\times W$. Sep 12, 2022 at 11:53

The spectrum of a BPSK signal has a sinc function envelope. That's not bandlimited and falls off very slowly with frequency so you can't easily sample it without getting significant amount of aliasing unless you choose a VERY high sample rate.

If you just want to see qualitatively what's happening, the code below should work. If you want better than that, you need define exactly what level of precision is required and adjust signal length and sample rate accordingly.

%% PSD of a BPSK signal

N=100;

%Bandwidth
W_x = 200*10^6;
W_i = 50*10^6;

%sampling time
T_x = 1/(2*W_x);
T_i = 1/(2*W_i);

%time axis (these are of different lengths!)
t_x = T_x.*(0:N-1);
t_i = T_i.*(0:N-1);

%carrier frequencies
fx = 100*10^6;
fi = 150*10^6;

%% choose reeasonable parameters
n0 = 5e6; % signal length in samples
fs = 5e9; % sample rate in Hz
t = (0:n0-1)'/fs; % time axis

% create the modulation signals
Lx = fs/W_x; % divider
Li = fs/W_i;
nx = n0/Lx; % length of modulation signal X
ni = n0/Li;
% binary random sequence +1, -1
modx = sign(rand(nx,1) -0.5);
modi = sign(rand(ni,1)-0.5);
% upsample from modulation rate to analysis rate
y = ones(Lx,1)*(modx'); modxUp = y(:);
y = ones(Li,1)*(modi'); modiUp = y(:);
% build the time domain signals
x0 = cos(2*pi*fx*t).*modxUp;
i0 = cos(2*pi*fi*t).*modiUp;
xall = [x0 i0 x0+i0];
% spectral analysis
nfft = 2^14;
psd = pwelch(xall,hanning(nfft));
% plot it
clf;
freqAxis = (0:nfft/2)'*fs./nfft;
plot(freqAxis,10*log10(psd));
xlabel('Frequency in Hz');
grid('on');
ylabel('level in dB');
legend('X','I','X+I');
set(gca,'ylim',[-60 25]);
set(gca,'xlim',[0 fs/4]);

• Thanks. It looks right. I have a related question: signal $x(t)$ (the desired signal) comes from source $S_1$ and intended to receiver $R_1$, while signal $i(t)$ (the interference) comes from source $S_2$. What I am trying to do is to know when there is interference at $R_1$ from the PSD of the received signal. Obviously, I want to monitor the PSD of the received signal over time. Is this the right approach to detect the interference? Sep 13, 2022 at 6:52