Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

close all disp('no. of ones ~= no.

clear all of zeros + 1 ; balance


clc property not satisfied');
end
%PN SEQUENCE GENERATION
k=input('enter the no.of %AUTO-CORRELATION PROPERTY OF
flip-flops >=3 :\n'); PN SEQUENCE
n=2^k-1; temp=0;
z=2*a-1; %generating mapped
a=zeros(1,n); pn sequence
b=round(rand(1,k)); ar=z;
d=(-n):1:(n);
ctr0=0; %loop sequence for
ctr1=0; auto-correlation operation by
circular shift
for i=1:n for m=1:(2*n+1)
a(i)=xor(b(k),b(k-1)); if d(m)<0
c=b; for i=1:n
for j=1:k-1 if (i-d(m))<=n
b(j+1)=c(j);
end temp=temp+((1/n)*(z(i)*ar(i-d
b(1)=a(i); (m))));
end else
disp('the pn sequence
generated is:'); temp=temp+((1/n)*(z(i)*ar((i-
disp(a); d(m)-n))));
end
%BALANCE PROPERTY OF PN end
SEQUENCE r(m)=temp;
temp=0;
for i=1:n else
if a(i)==1 for i=1:n
ctr1=ctr1+1; if (i-d(m))>0
else
ctr0=ctr0+1; temp=temp+((1/n)*(z(i)*ar(i-d
end (m))));
end else
disp('no. of zeros=');
disp(ctr0); temp=temp+((1/n)*(z(i)*ar(n+(
disp('no. of ones='); i-d(m)))));
disp(ctr1); end
if ctr1==ctr0+1 end
disp('no. of ones = no. r(m)=temp;
of zeros + 1 ; balance temp=0;
property satisfied'); end
else end
%PLOTTING OF AUTO-CORRELATION
FUNCTION FOR PN SEQUENCE
stem(d,r);
title('AUTO-CORRELATION');
grid on

%END
COMMAND WINDOW OUTPUT FOR PN-SEQUENCE AND VERIFICATION OF ITS
PROPERTIES

enter the no.of flip-flops >=3 :

the pn sequence generated is:

1 0 1 1 1 0 0

no. of zeros=

no. of ones=

no. of ones = no. of zeros + 1 ; balance property satisfied

>>
close all c=1/n;
clear all var=sqrt(c/2);
clc
oise=var*(randn(1,length(b)));
%input sequence as pn y=b+noise;
sequence for j=1:length(b)
if y(j)>threshold
k=input('enter the no.of r(j)=1;
flip-flops >=3 :\n');
n=2^k-1; else
r(j)=0;
a=zeros(1,n); end
b=round(rand(1,k));
end
for i=1:n
a(i)=xor(b(k),b(k-1)); %practical bit error
c=b; rate calculation
for j=1:k-1
b(j+1)=c(j); erbit=sum(r~=a);
end pber(k)=erbit/length(a);
b(1)=a(i); end
end
pber_avg(i)=sum(pber)/nsim
%generation of mapped ;
sequence end

b=2*a-1;
snrdb=0:1:10; %theoritical bit error rate
threshold=0; calculation
nsim=10;
n1=10.^((1*snrdb)/10); tber=1/2.*erfc(sqrt(n1));
c=0;
%plotting of BER vs SNR
%adding of AWGN noise to graph
mapped PN sequence
semilogy(snrdb,tber,'k--','l
for i=1:length(snrdb) inewidth',3);
for k=1:nsim hold on;
n=10^((snrdb(i))/10); grid on;
semilogy(snrdb,pber_avg,'r-*
');
title('SNR v/s BER plot for
BPSK modulation');
legend('theoritical %END
ber','practical ber');
xlabel('SNR in db');
ylabel('bit error rate');

COMMAND WINDOW OUTPUT FOR FOR BPSK MODULATION WITH


INPUT AS PN-SEQUENCE

enter the no. of flip-flops >=3 :


22
>>

You might also like