Code covered by the BSD License

# Random Properties

### Ashish Verma (view profile)

Check randomness of PN sequence by random properties

Random_sequence_property.m
```clc;
clear all;
close all;
%.............................PN sequence............................
%....................................................................
%Generation of PN sequence and verification of randomness properties
%Two polynomail required for genration of gold

len = input('Enter the length of the sequence......');
disp ('Generator Polynomial Example [1 0 0 1...1] ');
poly = input ('Enter the polynomial: ');
disp ('Initial state Example [1 0 0 1...0]');
ini = input ('Enter the initial state: ');
ff = log2(len+1);
%pn sequence generation
a = zeros(len,ff);
a(1,(1:ff)) = ini ;
for i = 1:(len-1)
x = 0;
for j = 2:(ff+1)
if (poly (1,j) == 1)
x = xor (x,a(i,(j-1)));
end
end
a ((i+1),1:ff) = circshift(a(i,1:ff),[0 1]);
a ((i+1),1) = x;
end
for i = 1:len
h(1,i) = a(i,ff);
end
fprintf ('The generated sequence is: \n');
disp (h);
%balance property
check = 0;
one = 0;
zero = 0;
for i = 1:len
if ( h(1,i) == 0)
zero= zero+1;
else
one = one+1;
end
end
disp ('BALANCE PROPERTY');
disp ('Number of ones: ');
disp (one);
disp ('Number of zeros: ');
disp (zero);
if ((one-zero) == 1)
fprintf ( 'Balance property is satisfied\n\n');
else
fprintf ( 'Balance property is not satisfied\n\n');
check = 2;
end
%autocorelation property
while (check == 0)
for i= 1:len

y(i,:) = xor (h,circshift(h,[0 i]));
end
y(i,:)
for i = 1:len
one = 0;
zero = 0;
for j = 1:len
if ( y(i,j) == 0 );
zero = zero+1;
else
one = one+1;
end
end
z(i,1) = zero - one;
end
for i = 1: (len-1);
g(i,1) = -1;
end
g(i,1);
g (len,1) = len;
disp ('AUTOCORRELATION PROPERTY');
disp (z)
p=z';
k=round(len/2);
p = circshift(p,[0 k]);
t=1:1:(len);
figure
plot(t,p)
if(z == g)
fprintf ( 'Auto correlation property is satisfied\n\n');
check = 3;
else
fprintf ( 'Auto correlation property is not satisfied\n\n');
check = 2;
end
end

% run property
while( check == 3);
runs = ((len+1)/2);
u = ff;
r = zeros (1,u);
count = 1;
for i = 1:len-1
if (h(1,i) == h(1,i+1))
count = count+1;
else
r(1,count) = r(1,count)+1;
count = 1;
end
end
r(1,count) = r(1,count)+1;
s = zeros(1,u);
for i = 1:(u-1)
s(1,i) = runs / (2.^i) ;
end
s(1,u) = 1;
disp ('RUN PROPERTY');
fprintf ('Runs\t\t\t Run Length \n');
for i = 1:u
fprintf ('%d\t\t\t\t %d\n',r(1,i),i);
end
if (r == s)
fprintf ('Run Property is satisfied\n\n');
check = 4;
else
fprintf ('Run Property is not satisfied\n\n');
check = 2;
end
end
if (check == 2)
disp ('The given sequence is not a PN sequence');
else
disp ('The given sequence is a PN sequence');
end
disp(h)

```