卷积码(3 1 2)编译码程序

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

电子信息与计算机工程系2011级信息工程

——卷积码(3 1 2)

1.卷积码编译码程序

1.1内嵌函数trel1.m

clear;clc

trel = poly2trellis(3,[06,05,07]);

msg = randint(1,10)

code = convenc(msg,trel)

code1 = encode312(msg)

code-code1

msg1=decode_312(code)

msg-msg1

1.2编码程序encode31

2.m

function code = encode312(msg)

code = zeros(1,length(msg)*3);

current = [0 0];

for i = 1:length(msg)

[out,next] = state_machine(msg(i),current);

current = next;

code(3*i-2) = out(1);

code(3*i-1) = out(2);

code(3*i) = out(3);

end

1.3 状态积state_machine.m

function[output,nextState]=stat_machine(input,current_state) output(1) =mod(input+current_state(1),2);

output(2) =mod(input+current_state(2),2);

output(3) =mod(input+current_state(1)+current_state(2),2);

nextState(1) =input;

nextState(2) =current_state(1);

1.4汉明距离hamming.m

function distance = hamming(a,b)

temp = a+b;

temp = mod(temp,2);

distance = sum(temp);

1.5译码程序decode_31

2.m

function msg=decode_312(code)

chip = 6;

for i = 1:2^chip

M(i,:) =de2bi(i-1,chip);

W(i,:) =encode312(M(i,:));

D(i)=hamming(W(i,:),code(1:chip*3));

end

[val,index] = sort(D);

ret_msg = zeros(1,length(code)/3);

for i = 1:4

ret_msg(i,1:chip) =M(index(i),:);

ret_dis(i) = D(index(i));

end

iter = (length(code)-chip*3)/3;

for i=1:iter

for j=1:4

msg_temp1 = [ret_msg(j,1:chip+i-1) 0];

msg_temp2 = [ret_msg(j,1:chip+i-1) 1];

code_temp1 = encode312(msg_temp1);

code_temp2 = encode312(msg_temp2);

dis_temp1 = hamming(code_temp1,code(1:chip*3+3*i));

dis_temp2 = hamming(code_temp2,code(1:chip*3+3*i));

if(dis_temp1

ret_msg(j,1:chip+i)=msg_temp1;

ret_dis(j)= dis_temp1;

else

ret_msg(j,1:chip+i)= msg_temp2;

ret_dis(j) = dis_temp2;

end

end

end

[val,index] = sort(ret_dis);

msg = ret_msg(index(1),:);

相关文档
最新文档