/
Serial_Test.m
147 lines (114 loc) · 2.92 KB
/
Serial_Test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
clc
close all
VOLTAGELEVVALS; %Contains the Imported CELL Containing LSBs of Binary Equivalent of Voltage Values
string=str2double(VOLTAGELEVVALS); %Converts CELL data to DOUBLE Data
n=length(string);%Counts Length of String
S=string;
m=10;
for i=1:1:m-1
S(n+i)=S(i);
end
% //////////////////////////////////M BIT//////////////////////////////////
binary10bit=decimalToBinaryVector(0:1023,10);
freq10=zeros(1024,1);
buffer10=zeros(1,10);
start=1;
stop=m;
k=1;
for i=1:1:n
if i<=stop
buffer10(k)=S(i);
k=k+1;
end
if i>=stop
%///////////////////////////////////////////
for i=1:1:1024
if binary10bit(i,1:10)==buffer10;
freq10(i)=freq10(i)+1;
end
end
%//////////////////////////////////////////
start=start+10;
stop=stop+10;
k=1;
end
end
% //////////////////////////////////M-1 BIT///////////////////////////////
binary9bit=decimalToBinaryVector(0:511,9);
freq9=zeros(512,1);
buffer9=zeros(1,9);
start=1;
stop=m-1;
k=1;
for i=1:1:n
if i<=stop
buffer9(k)=S(i);
k=k+1;
end
if i>=stop
%///////////////////////////////////////////
for i=1:1:512
if binary9bit(i,1:9)==buffer9;
freq9(i)=freq9(i)+1;
end
end
%//////////////////////////////////////////
start=start+9;
stop=stop+9;
k=1;
end
end
% //////////////////////////////////M-2 BIT///////////////////////////////
binary8bit=decimalToBinaryVector(0:255,8);
freq8=zeros(256,1);
buffer8=zeros(1,8);
start=1;
stop=m-2;
k=1;
for i=1:1:n
if i<=stop
buffer8(k)=S(i);
k=k+1;
end
if i>=stop
%///////////////////////////////////////////
for i=1:1:256
if binary8bit(i,1:8)==buffer8;
freq8(i)=freq8(i)+1;
end
end
%//////////////////////////////////////////
start=start+8;
stop=stop+8;
k=1;
end
end
% CHI m SQUARE CALCULATION////////////////////////////////////////////////
Chim2=0;
for i=1:1:1024
Chim2=Chim2+(power(freq10(i),2));
end
Chim2=(power(2,m)/n)*Chim2-n;
% CHI m-1 SQUARE CALCULATION////////////////////////////////////////////////
Chim_12=0;
for i=1:1:512
Chim_12=Chim_12+(power(2,m-1)/n)*(power(freq9(i),2));
end
Chim_12=Chim_12-n;
% CHI m-2 SQUARE CALCULATION////////////////////////////////////////////////
Chim_22=0;
for i=1:1:256
Chim_22=Chim_22+(power(2,m-2)/n)*(power(freq8(i),2));
end
Chim_22=Chim_22-n;
DelChim2=Chim2-Chim_12;
Del2Chim2=Chim2-2*Chim_12+Chim_22;
p_val1=gammainc(power(2,m-2),DelChim2);
p_val2=gammainc(power(2,m-3),Del2Chim2);
if p_val1>=0.01
if p_val2>=0.01
disp('THE SERIES IS RANDOM');
end
else
disp('THE SERIES IS NON-RANDOM');
end