卷积码译码器

 

 

1 clear all
2 codeinput=[ 1 1 1 0 1 0 0 1 0 1 1 0 ];
3 inputmetrics=zeros(8,3);
4  output=zeros(8,9);
5 current_state=0;
6 statemetric=zeros(8,1);
7 G=[1 0 0; 1 0 1; 1 1 1 ];
8  for a=0:1
9 current_state=0;
10 input=a;
11 [next_state1,memory_contents]=nxt_stat(current_state,input,3,1);
12 output1=mod(memory_contents*G',2);
13   current_state2=next_state1;
14 for b=0:1
15 input=b;
16 [next_state2,memory_contents]=nxt_stat(current_state2,input,3,1);
17 output2=mod(memory_contents*G',2);
18 current_state3=next_state2;
19 for c=0:1
20 input=c;
21 [next_state3,memory_contents]=nxt_stat(current_state3,input,3,1);
22 output3=mod(memory_contents*G',2);
23 d=[a b c];
24 e=bin2deci(d);
25 statemetric(e+1)=next_state3;
26 inputmetrics(e+1,:)=d;
27 output(e+1,:)=[output1 output2 output3];
28 end
29 end
30 end
31 outputcode=[];
32 inputcode=[];
33 K=zeros(8,1);
34 for n=1:8
35 k=0;
36 for i=1:length(output)
37 if codeinput(i)~=output(n,i)
38 k=k+1;
39 end
40 K(n,:)=k;
41 end
42 end
43 [k1,k2]=sort(K);
44 O_length=K(k2(1:4),:);
45 outputsecond=[output(k2(1:4),:)];
46 state=statemetric(k2(1:4),:);
47 inputsecond=inputmetrics(k2(1:4),:);
48 x=1;
49 for depth=0:(length(codeinput)/3)-4
50 next_state=zeros(8,1);
51 for n=1:4
52 for m=0:1
53 [next_state(x,:),memory_contents]=nxt_stat(state(n,:),m,3,1);
54 outputthird1=mod(memory_contents*G',2);
55 outputthird(x,:)=outputthird1;
56 inputthird(x,:)=m;
57 x=x+1;
58 end
59 end
60 K=zeros(8,1);
61 for n=1:8
62 k=0;
63 for i=1:3
64 if codeinput(9+depth*3+i)~=outputthird(n,i)
65 k=k+1;
66 end
67 K(n,:)=k;
68 end
69 end
70 K=K+[O_length(1); O_length(1); O_length(2) ;O_length(2); O_length(3); O_length(3) ;O_length(4); O_length(4)];
71 [k1,k2]=sort(K);
72 state=next_state(k2(1:4),:);
73 O_length=K(k2(1:4),:);
74 outputcode=[ outputcode outputthird(k2(1:4),:)];
75 inputcode=[inputcode inputthird(k2(1:4),:)];
76 end
77 outputcode=[outputsecond outputcode];
78 inputcode=[inputsecond inputcode];
79
80 [h,g]=min(O_length);
81 final=inputcode(g,:);
82 final
83
84

 

posted @ 2010-08-25 17:17  xxfighting  阅读(393)  评论(0编辑  收藏  举报