Compare two graphs on same plot
34 views (last 30 days)
Show older comments
Nathan Jaqua
on 21 Mar 2020
Answered: Sriram Tadavarty
on 21 Mar 2020
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?
code:
%% This file will simulate BPSK
clc
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
figure;
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
figure;
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);
0 Comments
Accepted Answer
Sriram Tadavarty
on 21 Mar 2020
Hi Nathan,
I assume both variables bhat and btilda have same length.
% Option 1
figure
plot(1:length(bhat),bhat,1:length(btilda),btilda)
% Option 2
figure
plot(bhat)
hold on
plot(btilda)
Hope this helps.
Regards,
Sriram
0 Comments
More Answers (0)
See Also
Categories
Find more on BPSK in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!