% created by MUSTAFA SAMI AHMED
% Email mustafa_sami87@yahoo.com
set(0,'defaultaxesfontsize',16);
clc;
clear all;
%M =100;
M=121;
L=sqrt(M);
bv = 0:L-1;
Matrix = bv'*bv ;
incPhi = (2*pi)/L; %incremental phase change
Matrix = mod(Matrix*incPhi,2*pi);
b=reshape(Matrix,1,[]); % matrix 1D size 1xM
for p = 1:M
  d(p) = exp(1j*b(p)) ;
end    
AutoCorrelation = conv(d,conj(d(end:-1:1)));
AutoCorrelationdB =20*log10(abs(AutoCorrelation)/121);
laxis=-120:120;
 figure(1);
 stem(laxis,AutoCorrelation,'Linewidth',2);
 axis([-120 120 -20 130])
 title('Autocorrelation: Frank Code (M=121)')
 xlabel('lag value')
  figure(2);
plot(laxis,AutoCorrelationdB,'Linewidth',3);
title('Autocorrelation:  Frank Code (M=121)  db Scale')
xlabel('lag value')
axis([-120 120 -60 0])
%
register=[1 0 0 0 0 0 0];
for ri=1:127,
m127(ri)=register(1,7);
register(1,2:7)=register(1,1:6);
register(1,1)=rem((register(1,1)+m127(1,ri)),2);
end
m127t=2*m127-1;
AutoMLSR = conv(m127t,conj(m127t(end:-1:1)));
%AutodB =20*log10(abs(AutoMLSR)/max(abs(AutoMLSR)));
AutodB =20*log10(abs(AutoMLSR+0.0000001*ones(size(AutoMLSR)))/127);
laxis=-126:126;
 figure(3);
 stem(laxis,AutoMLSR,'-r','Linewidth',2);
 axis([-126 126 -20 130])
 title('Autocorrelation: MLSR Code (M=127)')
 xlabel('lag value')
  figure(4);
plot(laxis,AutodB,'-r','Linewidth',3);
title('Autocorrelation: MLSR Code (M=127)  db Scale')
xlabel('lag value')
axis([-128 128 -60 0])
