0% found this document useful (0 votes)
7 views3 pages

BPSK

The document outlines a MATLAB script for BPSK (Binary Phase Shift Keying) modulation and demodulation, including the generation of a carrier signal and the addition of AWGN (Additive White Gaussian Noise) to simulate transmission. It calculates the Bit Error Rate (BER) across various SNR (Signal-to-Noise Ratio) levels and visualizes the results through plots. The script also demonstrates the demodulation process and the effect of noise on the transmitted signal.

Uploaded by

touuot0712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

BPSK

The document outlines a MATLAB script for BPSK (Binary Phase Shift Keying) modulation and demodulation, including the generation of a carrier signal and the addition of AWGN (Additive White Gaussian Noise) to simulate transmission. It calculates the Bit Error Rate (BER) across various SNR (Signal-to-Noise Ratio) levels and visualizes the results through plots. The script also demonstrates the demodulation process and the effect of noise on the transmitted signal.

Uploaded by

touuot0712
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

%DECODING

clc; clear all ;close all ; de=[];


b=[1 1 0 1 0 0 1 1 0 1]; for i =1:length(b)
b1=[b,b(length(b))]; k=sum(demod(1+(i-1)*length(t):i*length(t)));
nc=3; if k>0
Tb=1; de=[de,ones(1,length(t))];
fc=nc/Tb; else
fs=100; de=[de,zeros(1,length(t))];
t=linspace(0,1,fs); end
length(t) end
%carrier signal figure;
c_t=sin(2*pi*fc*t); plot(de,'LineWidth',2)
figure ; title('Demodulated signal');
plot(t,c_t) xlabel('Time (s)');
title('Carrier signal'); ylabel('Amplitude');
xlabel('Time (s)'); grid on;
ylabel('Amplitude'); %% BIT ERROR RATE
grid on; N = 1e6;
SNR_dB = 0:1:15;
BER = zeros(1, length(SNR_dB));
%BPSK data = randi([0 1], 1, N);
s_t=[]; bpsk_signal = 2*data - 1
for i =1:length(b) for snr_idx = 1:length(SNR_dB)
if b(i)==1 % Add AWGN to the BPSK signal for the given SNR
s_t=[s_t,c_t]; snr = SNR_dB(snr_idx);
else noisy_signal = awgn(bpsk_signal, snr, 'measured');
s_t=[s_t,-c_t]; % BPSK Demodulation (Detect positive as 1 and negative
end as 0)
end received_bits = noisy_signal > 0;
length(s_t) % Calculate Bit Error Rate (BER)
figure; num_errors = sum(data ~= received_bits); % Count bit
subplot(2,1,2) errors
t1=linspace(0,10,1000); BER(snr_idx) = num_errors/N; % BER for this SNR
plot(t1,s_t) end
title('BPSK signal');
xlabel('Time (s)'); % Plot BER vs SNR
ylabel('Amplitude'); figure;
grid on; semilogy(SNR_dB, BER, 'b-o', 'LineWidth', 2);
subplot(2,1,1) xlabel('SNR (dB)');
stairs(0:1:10,b1,'LineWidth',2) ylabel('Bit Error Rate (BER)');
title('BINARY DATA'); title('BER vs SNR for BPSK in AWGN Channel');
xlabel('Time (s)'); grid on;
ylabel('Amplitude');
grid on;
%Channel transmission
snr=15;
ch_t=awgn(s_t,snr,"measured");
figure;
plot(t1,ch_t)
title('Transmitted signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
%demodulation
c2_t=sin(2*pi*fc*t1);
demod=ch_t.*c2_t;
figure;
plot(t1,demod)
title('demod')
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

You might also like