Compare two graphs on same plot

조회 수: 16 (최근 30일)
Nathan Jaqua
Nathan Jaqua 2020년 3월 21일
답변: Sriram Tadavarty 2020년 3월 21일
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);

채택된 답변

Sriram Tadavarty
Sriram Tadavarty 2020년 3월 21일
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개)

카테고리

Help CenterFile Exchange에서 BPSK에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by