-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdecode.m
70 lines (66 loc) · 1.83 KB
/
decode.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
function [ P2,m ] = decode( P,P2,m,p2 )
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
len=length(P);
cunt=0;
for j=m:len
[row_no,zeroes]=check_coeff(P(m:j),0);
if row_no~=-1
col_no=0;k=0;
temp=P(j+1:j+row_no);
for i=length(temp):-1:1
col_no=col_no+temp(i)*2^k;
k=k+1;
end
if(col_no<abs((2^row_no)-1)-abs((2^(row_no-1))-1))
P2(p2,cunt+1)=-((2^row_no)-1)+col_no;
cunt=cunt+1;
elseif(row_no==0 && col_no==0)
j=j+1;
P2(p2,cunt+1)=0;
cunt=cunt+1;
else
P2(p2,cunt+1)=((2^(row_no-1))-1)+col_no-(abs((2^row_no)-1)-abs((2^(row_no-1))-1))+1;
cunt=cunt+1;
end
break;
end
end
i=j+1+row_no;
for j=i:1:len
[row_no,zeroes]=check_coeff(P(i:j),1);
if row_no~=-1
if((j-i)==10 & P(i:j)==[1,1,1,1,1,1,1,1,0,0,1])
P2(p2,cunt+15)=0;
cunt=cunt+15;
i=j+1;
else
col_no=0;k=0;
temp=P(j+1:j+row_no);
for i=length(temp):-1:1
col_no=col_no+temp(i)*2^k;
k=k+1;
end
if(zeroes>0)
P2(p2,cunt+zeroes)=0;
end
cunt=cunt+zeroes;
if(col_no<abs((2^row_no)-1)-abs((2^(row_no-1))-1))
P2(p2,cunt+1)=-((2^row_no)-1)+col_no;
cunt=cunt+1;
else
P2(p2,cunt+1)=((2^(row_no-1))-1)+col_no-(abs((2^row_no)-1)-abs((2^(row_no-1))));
cunt=cunt+1;
end
i=j+1+row_no;
end
elseif ((j-i)==10 & P(i:j)==[1,1,1,1,1,1,1,1,0,0,1])
P2(p2,cunt+15)=0;
cunt=cunt+15;
i=j+1;
elseif ((j-i)==3 & P(i:j)==[1,0,1,0])
P2(p2,64)=0;
m=j+1;
end
end
end