MATLAB Answers

Compare two graphs on same plot

5 views (last 30 days)
We are working with BPSK Demodulation. I want to plot the btilda and bhat variables in this code on the same graph so I can compare them. Does anyone know how to do that?
%% This file will simulate BPSK
clear all;
% generate logical data bits
nb = 25;
c = 2*(randn(nb,1) > 0)-1; % generate random 25 bits
% BPSK modulation
Fs = 5e3; % sampling frequency for signal representation
Ts = 1/Fs; % sampling period
T = 1e-2; % symbol period
fc = 1e2; % carrier frequency
phi = 0; % phase offset
% time vector
t = 0:Ts: nb*T - Ts;
% Modulate the data bits to BPSK signal
[x,xc,btilda] = BPSK_MOD(c, fc, phi, T, Ts);
% plot the data, carrier, and modulated signal
subplot 311; plot(t, btilda); title('Information bits');
ylabel('amplitude'); xlabel('time');
subplot 312; plot(t, xc); title('Carrier Signal');
ylabel('amplitude'); xlabel('time');
subplot 313; plot(t, x); title('BPSK modulated Signal');
ylabel('amplitude'); xlabel('time');
% AWGN channel noise
SNR = 10;
sigma = 10^(-SNR/20); % noise standard deviation
noise = sigma*randn(size(x));
x = x + noise;
% receiver processing.
bhat = BPSK_DMOD(x, fc, phi, Ts);
bRcvd = receivedSignalBitEst(bhat, T, Ts);
% plot the received signal, noise, and demodulate it
subplot 311; plot(x); title('Received data signal');grid on;
subplot 312; plot(noise); title('Noise level ');grid on;
subplot 313; plot(bhat);title('Received data signal'); grid on;
% calculate number of bits in error
bErr = length(find((c(1:end-1) - bRcvd)~= 0));
fprintf('Total bits are in Error: %d\n', bErr);


Sign in to comment.

Accepted Answer

Sriram Tadavarty
Sriram Tadavarty on 21 Mar 2020
Hi Nathan,
I assume both variables bhat and btilda have same length.
% Option 1
% Option 2
hold on
Hope this helps.


Sign in to comment.

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!