Sunteți pe pagina 1din 22

August 5, 2013

Lab-4
Prepared By-Nilay Vithani and Sameer Patel

Common Function for Periodic Correlation and Periodic Autocorrelation:-
function x = disi(s1,s2)
if s1 == s2
m1=s1';
m2=m1;
for j=1:25
m2=circshift(m2,1);
m=m1.*m2;
s=0;
for i=1:length(m)
s=s+m(i);
end
x(j)=s;
end

else
m1=s1';
m2=s2';

for j=1:25
m=m1.*m2;
m2=circshift(m2,1);
s=0;
for i=1:length(m)
s=s+m(i);
end
x(j)=s;
end
end
August 5, 2013
Q1) For Autocorrelation
Code:-
clear all;
clc;
s1=[+1 -1 +1 +1 +1 -1 -1 -1 +1 -1]%input('Enter Sequence 1: ');
s2=[+1 -1 +1 +1 +1 -1 -1 -1 +1 -1]%input('Enter Sequence 2: ');
plot(disi(s1,s2));
xlabel('f(x)');
ylabel('x');
title('Periodic cross or auto correlation function');
legend('Auto correlation');

Figure:-

Figure For Q1-Autocorrelation
For Cross Correlation
Code:-
clear all;
clc;
s1=[+1 -1 +1 +1 +1 -1 -1 -1 +1 -1]%input('Enter Sequence 1: ');
s2=[1 -1 -1 +1 -1 1 -1 1 -1 -1]%input('Enter Sequence 2: ');
August 5, 2013
plot(disi(s1,s2));
xlabel('f(x)');
ylabel('x');
title('Periodic cross or auto correlation function');
legend('Auto correlation');

Figure:-

Figure For Q1-Cross Correlation











August 5, 2013
Q2)
Code:-
clear all;
clc;
N=16;
k=2;
H = hadamard(16);
k1 = randperm(size(H,1));
k2 = randperm(size(H,1));
s1 = H(k1(1:1),:);
s2 = H(k2(1:1),:);
Rc=disi(s1,s2);
Ra=disi(s1,s1);
Rmax=max(max(Rc,Ra))
figure;
s_2=disi(s1,s1);
s_2=[-s_2 s_2];
subplot(211);
plot(s_2);
title('Hadamard Walsh code set of length 16 Auto corr periodic');
s_1=disi(s1,s2);
s_1=[-s_1 s_1];
subplot(212);
plot(s_1,'g');
title('Hadamard Walsh code set of length 16 Cross corr periodic');

figure;
Rc=[-Rc Rc];
subplot(211);
plot(Rc);
title('Hadamard Walsh code set of length 16 Cross corr periodic');
welch=N*sqrt((k-1)/(k*N-1))
August 5, 2013
Cxy=xcorr(s1,s2);
subplot(212);
plot(Cxy,'r');
title('Hadamard Walsh code set of length 16 Cross corr Aperiodic');

for n=1:N-1;
Rxy(n)= Cxy(n) + Cxy(N-n);
end
figure;
subplot(211);
plot(Rxy);
title('Even cross correlation function');
subplot(212);
plot(Cxy,'black');
title('Aperiodic cross correlation function');
Output:-
Rmax =
16
welch =
2.8737
Conclusion:-
This shows that

>
Note:- The value of Rmax will change on every run of the code because of the coding taking two random rows from the Hadamard
matrix for the purpose of auto and cross-correlation
Figure:-

August 5, 2013

Figures For Q2







August 5, 2013
Q3)
Code:-
clear all;
clc;;
N=31;
%uncoded_bits = round(rand(1,N));
%b = -2*(uncoded_bits-0.5)
% Primitive polynomial here taken: x^5 + x^2 + 1
%initial sequance is 00001
a=[1; 0; 0; 0; 0];
for i=1:31
b(i)=a(5);
c=xor(a(5),a(2));
a=circshift(a,1);
a(1)=c;
end
d=b';
for i=1:31
m1(i,:)=circshift(d,i);
end

% Reciprocal polynomial of above is: x^5 + x^3 + 1
a=[1; 0; 0; 0; 0];
for i=1:31
b(i)=a(5);
c=xor(a(5),a(3));
a=circshift(a,1);
a(1)=c;
end
e=b';
for i=1:31
m2(i,:)=circshift(e,i);
August 5, 2013
end

matrix1=m1
matrix2=m2

Output:-
matrix1 =

Columns 1 through 22

1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 1 1
0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1 1
0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1 1
1 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0 1
0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0 0
1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 0 0
1 1 0 1 0 0 1 0 0 0 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 1 0 1 0
0 1 1 0 1 1 1 0 1
0 0 1 1 0 1 1 1 0
0 0 0 1 1 0 1 1 1
1 0 0 0 1 1 0 1 1
1 1 0 0 0 1 1 0 1
1 1 1 0 0 0 1 1 0
1 1 1 1 0 0 0 1 1
1 1 1 1 1 0 0 0 1
0 1 1 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0
1 0 0 1 1 1 1 1 0
1 1 0 0 1 1 1 1 1
0 1 1 0 0 1 1 1 1
1 0 1 1 0 0 1 1 1
0 1 0 1 1 0 0 1 1
0 0 1 0 1 1 0 0 1
August 5, 2013
1 0 0 1 0 1 1 0 0
0 1 0 0 1 0 1 1 0
0 0 1 0 0 1 0 1 1
0 0 0 1 0 0 1 0 1
0 0 0 0 1 0 0 1 0
1 0 0 0 0 1 0 0 1
0 1 0 0 0 0 1 0 0
1 0 1 0 0 0 0 1 0
0 1 0 1 0 0 0 0 1
1 0 1 0 1 0 0 0 0
1 1 0 1 0 1 0 0 0
1 1 1 0 1 0 1 0 0
0 1 1 1 0 1 0 1 0
1 0 1 1 1 0 1 0 1

Theory:-
The primitive polynomial used is:
5
+
2
+1
Reciprocal polynomial is:
3
+
2
+1
What wed obtained was a single sequence of length 31.
The entire matrix of sequences (31x31) can be obtained by circularly shifting the single sequence 31 times.










August 5, 2013




Q4)
Code:-
x=[1;0;0;0;0;1;0;1;0;1;1;1;0;1;1;0;0;0;1;1;1;1;1;0;0;1;1;0;1;0;0];
y=[1;0;0;0;0;1;1;0;1;0;1;0;0;1;0;0;0;1;0;1;1;1;1;1;0;1;1;0;0;1;1];
Ty=y;
for j=1:31
Ty=circshift(Ty,1);
a(j,:)=Ty;
end
gold=[x,y,xor(x, y),xor(x, a(:,1)),xor(x, a(:,2)),xor(x, a(:,3)),xor(x, a(:,4)),xor(x, a(:,5)),xor(x, a(:,6)),xor(x, a(:,7)),xor(x, a(:,8)),xor(x,
a(:,9)),xor(x, a(:,10)),xor(x, a(:,11)),xor(x, a(:,12)),xor(x, a(:,13)),xor(x, a(:,14)),xor(x, a(:,15)),xor(x, a(:,16)),xor(x, a(:,17)),xor(x,
a(:,18)),xor(x, a(:,19)),xor(x, a(:,20)),xor(x, a(:,21)),xor(x, a(:,22)),xor(x, a(:,23)),xor(x, a(:,24)),xor(x, a(:,25)),xor(x, a(:,26)),xor(x,
a(:,27)),xor(x, a(:,28)),xor(x, a(:,29)),xor(x, a(:,30))]
gold=gold';

k1 = randperm(size(gold,1));
k2 = randperm(size(gold,1));
s1 = gold(k1(1:1),:);
s2 = gold(k2(1:1),:);
seq1=s1;
seq2=s2;
crosscorrel=disi(seq1,seq2);
Rc=max(crosscorrel);
seq1=s1;
seq2=s1;
autocorrel=disi(seq1,seq1);
Ra=max(autocorrel);
Rmax=max(Ra,Rc);
N=31;
August 5, 2013
k=N+2;
Welch_bound=N*sqrt((k-1)/(k*N-1));
Rmax
Welch_bound
subplot(211)
title('Cross Correlation')
plot(crosscorrel,'black')
subplot(212)
plot(autocorrel,'b');
title('Auto Correlation')

Output:-
gold =

Columns 1 through 22

1 1 0 0 0 1 1 1 1 0 0 1 0 1 0 1 1 0 1 1 1 0
0 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0 0
0 0 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0 0
0 0 0 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1 0
0 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 0 1
1 1 0 0 0 1 1 0 0 0 1 1 1 1 0 0 1 0 1 0 1 1
0 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0
1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0 1 0 1 0
0 1 1 1 1 0 1 1 0 0 1 1 1 0 0 0 0 1 1 0 1 0
1 0 1 0 0 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0 1 0
1 1 0 0 0 0 0 1 0 0 1 1 0 0 0 1 1 1 1 0 0 1
1 0 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0
0 1 0 0 0 1 0 1 1 1 1
1 1 0 1 1 1 0 1 0 0 0
1 0 0 1 0 0 0 1 0 1 1
1 0 1 1 0 1 1 1 0 1 0
0 1 0 1 1 0 1 1 1 0 1
1 0 1 0 1 1 0 1 1 1 0
1 0 1 0 1 0 0 1 0 0 0
0 0 1 0 1 0 1 1 0 1 1
1 0 0 1 0 1 0 1 1 0 1
0 0 1 1 0 1 0 1 0 0 1
August 5, 2013
0 0 0 1 1 0 1 0 1 0 0
0 0 0 0 1 1 0 1 0 1 0
0 1 1 1 1 0 0 1 0 1 0
0 0 1 1 1 1 0 0 1 0 1
0 0 0 1 1 1 1 0 0 1 0
1 0 0 0 1 1 1 1 0 0 1
1 1 0 0 0 1 1 1 1 0 0
1 0 0 1 1 1 0 0 0 0 1
1 1 0 0 1 1 1 0 0 0 0
1 0 0 1 1 0 0 0 1 1 1
0 1 0 0 1 1 0 0 0 1 1
1 1 0 1 1 0 0 1 1 1 0
0 0 0 1 0 0 1 1 0 0 0
1 1 1 1 0 1 1 0 0 1 1
1 1 1 1 1 0 1 1 0 0 1


Rmax =
10
Welch_bound =
5.4854
Conclusion:-
This shows that

>

Note:- The value of Rmax will change on every run of the code because of the coding taking two random rows from the Gold
sequence matrix for the purpose of auto and cross-correlation.







August 5, 2013
Figure:-

Figure For Q4


















August 5, 2013

Q5)
Code:-
clear all;
clc;
N=7;
M=6;
M1=7;
%CI
for k=1:N
s1(k)=exp(i.*((2*pi./N)) .*(k-1).*(M-1));
s2(k)=exp(i.*((2*pi./N)) .*(k-1).*(M1-1));
end
auto=abs(disi(s1,s1));
cross=abs(disi(s1,s2));
Rmax_CI=max(max(abs(auto),abs(cross)))
subplot(221);
plot(auto);
xlabel('f(x)');
ylabel('x');
title('CI Auto correlation function');
subplot(222);
plot(cross,'g');
xlabel('f(x)');
ylabel('x');
title('CI Cross correlation function');

%FZC
for k=1:N
s3(k)=(-1)^(M*k).*(exp(i*(pi.*M .*M.*k/N)));
s4(k)=(-1)^(M1*k).*(exp(i*(pi.*M1 .*M1.*k/N)));
end
August 5, 2013
auto1=abs(disi(s3,s3));
cross1=abs(disi(s3,s4));
Rmax_FZC=max(max(abs(auto1),abs(cross1)))
subplot(223);
plot(auto1,'r');
xlabel('f(x)');
ylabel('x');
title('FZC Auto correlation function');
subplot(224);
plot(cross1,'black');
xlabel('f(x)');
ylabel('x');
title('FZC Cross correlation function');

Output:-
Rmax_CI =

1.5906e-15


Rmax_FZC =

1.0150e-14










August 5, 2013
Figure:-

Figure For Q5


















August 5, 2013
Q6)
Code:-
clc;
clear all;
N=8;
k=8;
i=1/(k*(k-1)*N*N);
sumci=0;
sumhad=0;
h=hadamard(N);
for k=1:N
for j=1:N
ci(k,j)=exp((1i*2*pi*(k-1).*(j-1))./N);
end
end
for x=1:N
for y=1:N
for l=1:(2*N)-1
if(x~=y)
crossci=xcorr(ci(x,:),ci(y,:)); %CI cross-correlation
sumci=sumci+(abs(crossci(l)).^2);
crosshad=xcorr(h(x,:),h(y,:)); %Hadamard Walsh cross-correlation
sumhad=sumhad+(abs(crosshad(l)).^2);
end
end
end
end
Rccci=i.*sumci;
display(Rccci);
Rcchad=i.*sumhad;
display(Rcchad);

Output:-
August 5, 2013
Rccci =
0.3750
Rcchad =
0.6607

S-ar putea să vă placă și