Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Exp.No.

4 Spread Spectrum – DSSS Modulation & Demodulation

clc
clear all
close all

% Generating the bit pattern with each bit 20 samples long

b=round(rand(1,30));
pattern=[];

%%

for k=1:30
if b(1,k)==0
sig=-ones(1,20);
else
sig=ones(1,20);
end

pattern=[pattern sig];
end
subplot(2,2,1);
plot(pattern);
title('Input Bit Sequence');

% Generating the pseudo random bit pattern for spreading


d=round(rand(1,120));
pn_seq=[];
carrier=[];
t=[0:2*pi/4:2*pi]; % Creating 5 samples for one cosine
for k=1:120
if d(1,k)==0
sig=-ones(1,5);
else
sig=ones(1,5);
end
c=cos(t);
carrier=[carrier c];
pn_seq=[pn_seq sig];

end

subplot(2,2,2);
plot(pn_seq);
title('PN sequence');
% Spreading of sequence
spreaded_sig=pattern.*pn_seq;
subplot(2,2,3);
plot(spreaded_sig);
title('Spreaded signal');

% Modulation of the spreaded signal


bpsk_sig=spreaded_sig.*carrier;

subplot(2,2,4);
plot(bpsk_sig);
title('BPSK Modulated Signal');

%Demodulation and Despreading of Received Signal

figure
rxsig=bpsk_sig.*carrier;
demod_sig=[];
for i=1:600
if rxsig(i)>=0
rxs =1;
else
rxs =-1;
end
demod_sig=[demod_sig rxs];
end
subplot(2,1,1);
plot(demod_sig);
title('Demodulated Signal')

despread_sig=demod_sig.*pn_seq;
subplot(2,1,2);
plot(despread_sig);
title('Despreaded data');

You might also like