
实 验 报 告 书
课程名称: 信息论与编码实验
实验名称: 卷积码编译码
一、实验目的
1、使用MATLAB进行卷积码编/解码器的代码编写、运行、仿真等操作。
2、熟练掌握MATLAB软件、语句。
3、理解卷积码编 解码器的原理、知识。
二、实验环境
MATLAB环境
二、实验要求
(1)实验前编写源程序、准备测试数据。
(2)在 MATLAB环境下完成程序的编辑、编译、运行,获得程序结果。如果结果有误,应找出原因,并设法更正之。
四、实验原理
1 、编码原理
卷积码编码的当前输出v(l)不仅与当前输入消息u(l)相关,还与此去前输入的m个消息u(l-1),…,u(l-m)相关,即v(l)=f(u(l),u(l-1),…,u(l-m)), l=0,1,2…
卷积编码电路中移位寄存器初态可设定为全0,电路为按段工作方式,即对每段k比特输出入,产生一段n比特输出。任意一输入段u(l-h)与输出v(l)的关系都是一个特殊的(n,k)线性分组码的编码关系,即存在kn的二元矩阵G,使得
v(l)=u(l-h)G, h=0,1,2,…,m
因此对于消息段序列u=(u(0),u(1),…,u(m),u(m+1),…),相应的输出端序列为v=(v(0),v(1),…,v(m),v(m+1),…),并满足v(0)=u(0)G
v(1)=u(0)G+u(1)G
v(m)=u(0)G+u(1)G+…+u(m-1)G+u(m)G
v(m+1)=u(1)G+u(2)G…+u(m)G+u(m+1)
卷积编码电路在按段工作方式下只需存储或者记忆m段的消息输入,电路中输入移位寄存器最多只有个有效的寄存器单元,而输出移位寄存器仅起一个并串转换作用。因此称参量m为卷积吗的记忆长度(段)
2、维比特译码原理
它的基本思想是把接收到的矢量,和网格图上诸种可能的路径比较,删去距离大的路径,保留距离小的路径,以距离最小路径作为发码的估值
五、实验内容
在MATLAB环境下卷积码编/解码器的实现。
1、 主函数main.m
clear;clc;
msg = randint(1,20,[0,1])
word = encode_conv213(msg)
word(1) =~word(1); %信道中存在污染,人为的模拟传输过word(10) =~word(10); %程中的出错码字
word(15) =~word(15);
word1=word
msg_1 = decode_conv213(word1)
msg-msg_1
2 、状态积state_machine.m
function [output,nextState] = state_machine(input,current_state)
output(1) = mod(current_state(1)+current_state(3),2);
output(2) = mod(input+current_state(2)+current_state(1),2);
nextState(1) = current_state(2);
nextState(2) = current_state(3);
nextState(3) = input;
3、 汉明距离hamming_distance.m
function distance = hamming_distance(a,b)
temp = a+b;
temp = mod(temp,2);
distance = sum(temp);
4 、213编码程序encode_conv213.m
function word = encode_conv213(msg)
word = zeros(1,length(msg)*2);
current = [0 0 0];
for i = 1:length(msg)
[out,next] = state_machine(msg(i),current);
current = next;
word(2*i-1) = out(1);
word(2*i) = out(2);
End
5、 213维比特译码decode_conv213.m
function msg = decode_conv213(word)
chip = 10; %初始状态选十个信息
for i = 1:2^chip
M(i,:) = de2bi(i-1,chip); %把所有可能性按二进制输出
W(i,:) = encode_conv213(M(i,:));
%得到相应的二进制编译后的码字
D(i) = hamming_distance(W(i,:),word(1:chip*2));
%与出错码字对比得到汉明距
end
[val,index] = sort(D);
%val中存汉明距从小到大排列,index中存对应val数据所在位置
ret_msg = zeros(1,length(word)/2); %开辟译出码字的存放空间
for i = 1:6
%1024种选择6种最小距离,并输出在ret_msg中,最小汉明距存于ret_dis
ret_msg(i,1:chip) = M(index(i),:);
ret_dis(i) = D(index(i));
end
iter = (length(word)-chip*2)/2; %剩余要译出的码字个数
for i=1:iter %迭代过程
for j=1:6
msg_temp1 = [ret_msg(j,1:chip+i-1) 0]; %下一状态出“0”
msg_temp2 = [ret_msg(j,1:chip+i-1) 1]; %下一状态出“1”
word_temp1 = encode_conv213(msg_temp1);
%下一状态为“0”时的编码
word_temp2 = encode_conv213(msg_temp2);
%下一状态为“1”时的编码
dis_temp1 = hamming_distance(word_temp1,word(1:chip*2+2*i));
dis_temp2 = hamming_distance(word_temp2,word(1:chip*2+2*i)); %算两种汉明距
if (dis_temp1 ret_dis(j) = dis_temp1; else ret_msg(j,1:chip+i) = msg_temp2; ret_dis(j) = dis_temp2; %选择较小汉明距的状态储存并输出在ret_msg中,最小汉明距存于ret_dis end end end [val,index] = sort(ret_dis); %把最终选择的6种最小汉明距按从小到大排列 msg =ret_msg(index(1),:); %选出维特比译码最小的距离所译出的信息 六、实验数据记录及分析(包括源程序清单及运行结果): 由Matlab实验结果可见,编码译码程序正确。也说明了维特比译码的可靠性 六、实验心得体会 通过本次实验,巩固的MATLAB软件的使用方法,实验过程中,通过在分析程序代码时,不断的翻阅课本和查找相关资料,我更加深刻地了解了卷积编码和译码的原理以及掌握了编写卷积码编译码程序的方法。虽然在看程序的过程中,遇到了一些陌生的语句,但是经过百度,与同学相互交流学习,取长补短,终于把程序看得有点明白了。最后,在matlab软件中运行后,验证了结果与理论相符合。
