clc
clear all
close all
% Generation of bit pattern
s=round(rand(1,25)); % Generating 25 bits
signal=[];
carrier=[];
t=[0:2*pi/119:2*pi]; % Creating 60 samples for one cosine
for k=1:25
if s(1,k)==0
sig=-ones(1,120); % 120 minus ones for bit 0
else
sig=ones(1,120); % 120 ones for bit 1
end
c=cos(t);
carrier=[carrier c];
signal=[signal sig];
end
figure(1)
subplot(6,1,1);
plot(signal);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Original Bit Sequence');
subplot(6,1,2);
plot(carrier);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Original Bit Sequence');
% BPSK Modulation of the signal
bpsk_sig=signal.*carrier; % Modulating the signal
subplot(6,1,3);
plot(bpsk_sig);
axis([-100 3100 -1.5 1.5]);
title('\bf\it BPSK Modulated Signal');
%Demodulation
debpsk_sig=bpsk_sig.*carrier; %Coherent Multiplication
subplot (6,1,4);
plot(debpsk_sig);
axis([-100 3100 -2.5 2.5]);
title('\bf\it After Coherent Multiplication');
y=intdump(debpsk_sig,120); %Integral with period reset
subplot(6,1,5);
plot(y);
title('\bf\it After Intergrated with Period Reset');
orig_sig=[];
%Comparator with threshold 0
for i=1:25
if y(i)<0
r_sig=-ones(1,120); % 120 minus ones for bit 0
else
r_sig=ones(1,120); % 120 ones for bit 1
end
orig_sig=[orig_sig r_sig];
end
subplot(6,1,6);
plot(orig_sig);
axis([-100 3100 -1.5 1.5]);
title('\bf\it Original Signal');