%(7,4)线性分组码编码译码函数,分别调用编码子函数和译码子函数
function start
num=1;
while(num==1)%进行编码或者译码的功能选择
choose=input('If you want to encode,please enter 1.If you want to decode,please enter 2.\n');
if (choose==1)%选择编码功能,输入编码向量
A=input('please enter a vector,the length is 4:\n');
A=mod(A,2);
if(length(A)~=4)%当输入错误长度时,报错,然后选择继续或者结束此过程
disp('you enter a wrong vector!');
num=input('If you want to go on,please enter 1,If you want to end,please enter else.\n');
else %当输入正确向量时,调用编码函数,输出编码结果,然后选择继续或者结束此过程
V=encoder (A);
num=input('If you want to go on,please enter 1,If you want to end,please enter else.\n');
end
else if(choose==2)%选择译码功能,输入接收的7位向量
R=input('please enter your receive vector,the length is 7:\n');
R=mod(R,2);
if(length(R)~=7)%当输入错误长度时,报错,然后选择继续或者结束此过程
disp('you enter a wrong vector!');
num=input('If you want to go on,please enter 1,If you want to end,please enter else.\n');
else %当输入正确向量时,调用译码函数,输出译码结果,然后选择继续或者结束此过程
D=decoding (R);
num=input('If you want to go on,please enter 1,If you want to end,please enter else.\n');
end
else %当输入无效数字时,报错,然后选择继续或者结束此过程
disp('you enter a wrong number!');
num=input('If you want to go on,please enter 1,If you want to end,please enter else.\n');
end
end
end