您好,欢迎来到九壹网。
搜索
您的当前位置:首页卷积码实验报告

卷积码实验报告

来源:九壹网
 篇一:卷积码实验报告(c++) 计算机科学与工程系 一、实验名称:卷积码 二、实验环境

软件环境:windows 2000,microsoft visual c++6.0 硬件环境:p4,2.4ghz,256内存,ibm-pc及兼容机 三、实验目的

了解卷积码的编码原理,给定基本监督矩阵,导出一致监督矩阵、基本生成矩阵、一致生成矩阵,能够通过监督矩阵或生成矩阵编出截断码或非截断码。 四、实验过程与实验结果 源程序:

#include<iostream> #include<string> using namespace std; class juanjicode{ private: int i,j,t;

int n0,k0,r0,m;

int **h,**h,**g,**g; //实现编码所需变量 int code;

string info_str,code_str; int total_num,extra_num; public:

void initializing(); void trans_h_to_h(); void trans_h_to_g(); void print_g();

void trans_g_to_g(); void print_g(); //编码

void before_encoding();//编码前的准备 int check(string); void encoding(); };

/**********************初始化模块**********************/ void juanjicode::initializing() {

cout<<请输入码字长n0=; cin>>n0;

cout<<请输入信息元个数k0=; cin>>k0;

cout<<请输入关联长度m=; cin>>m;

//监督元个数

r0=n0-k0;//动态分配存储单元 h=new int*[r0];

for(i=0;i<r0;i++) h[i]=new int[m*n0]; cout<<请输入(<<n0<<,<<k0<<,<<m<<)卷积码的基本监督矩阵h[<<r0<<][<<m*n0<<]:<<endl; for(i=0;i<r0;i++) for(j=0;j<m*n0;j++) cin>>h[i][j]; //检测,输出h

cout<<您输入的基本监督矩阵h[<<r0<<][<<m*n0<<]如下:\\n<<endl; for(i=0;i<r0;i++) {

for(j=0;j<m*n0;j++) {

cout<<h[i][j]; if((j+1)%n0==0) cout<< ; }

cout<<endl; }

cout<<endl; //动态分配存储单元 h=new int*[m*r0];

for(i=0;i<m*r0;i++) h[i]=new int[m*n0]; g=new int*[m*k0];

for(i=0;i<m*k0;i++) g[i]=new int[n0]; g=new int*[m*k0];

for(i=0;i<m*k0;i++) g[i]=new int[m*n0]; }

//由基本监督矩阵h导出一致监督矩阵h并打印输出 void juanjicode::trans_h_to_h() {

cout<<该卷积码对应的一致监督矩阵h[<<m*r0<<][<<m*n0<<]如下(未输出部分全为0):\\n<<endl; for(t=0;t<m;t++) {

for(i=0;i<r0;i++) {

for(j=0;j<(t+1)*n0;j++)

{h[t*r0+i][j]=h[i][(m-t-1)*n0+j]; cout<<h[t*r0+i][j]; if((j+1)%n0==0) cout<< ; }

cout<<endl; }

cout<<endl; } }

//由基本监督矩阵h导出基本生成矩阵g并打印输出 void juanjicode::trans_h_to_g() {

for(t=0;t<m;t++) {

for(i=0;i<k0;i++) {

for(j=0;j<n0;j++) {

if(j>=k0)

g[k0*t+i][j]=h[j-k0][t*n0+i]; else {

if(t==m-1&&i==j) g[k0*t+i][j]=1; else

g[k0*t+i][j]=0; } } } }

print_g(); }

void juanjicode::print_g() {

cout<<该卷积码对应的基本生g[<<m*k0<<][<<n0<<]如下:\\n<<endl; for(i=0;i<m*k0;i++) {

for(j=0;j<n0;j++) {

cout<<g[i][j];} if((i+1)%k0==0)

成矩阵

cout<<endl; cout<<endl; } }

//由基本生成矩阵g导出一致生成矩阵g并打印输出 void juanjicode::trans_g_to_g() {

for(t=0;t<m;t++) {

for(i=0;i<m*k0;i++) {

for(j=0;j<n0;j++) {

if(i<(t+1)*k0)

g[i][t*n0+j]=g[(m-(t+1))*k0+i][j]; else

g[i][t*n0+j]=0; } } }

print_g(); }

void juanjicode::print_g() {

cout<<该卷积码对应的一致生成矩阵g[<<m*k0<<][<<m*n0<<]如下(未输出部分全为0):\\n<<endl;

for(i=0;i<m*k0;i++) {

for(j=0;j<m*n0;j++) {

if(j<i/k0*n0)

cout<< ;//为0的块不输出 else

cout<<g[i][j]; if((j+1)%n0==0) cout<< ; }

if((i+1)%k0==0) cout<<endl; cout<<endl; }

}/**********************编码模块**********************/ //利用一致生成矩阵g及基本生成矩阵g编码

void juanjicode::before_encoding()//编码前的准备 {

c: int flag;

cout<<请输入待编码的0、1信息序列:<<endl; cin>>info_str; flag=check(info_str); if(!flag) {

cout<<您输入的信息序列含除0、1外的其他字符,请重新输入!<<endl;goto c; } else {

if(total_num<m*k0) {

cout<<您输入的信息元个数不足,无法进行编码,请重新输入!<<endl; goto c; }

else if(total_num%k0!=0) {

cout<<您输入的信息序列存在冗余,无法进行编码,请重新输入!<<endl; goto c; } } }

int juanjicode::check(string info_str) {

int flag=1; total_num=0;

for(i=0;info_str[i]!=\\0;i++) {

if(!(info_str[i]==0||info_str[i]==1)) {

flag=0; break; }

total_num++;//统计输入的0、1的数目 }

return flag;

}篇二:卷积码编译码实验报告 厦 门 理 工 学 院 实 验 报 告 书

课程名称: 信息论与编码实验 实验名称: 卷积码编译码 12

中输入移位寄存器最多只有m?k个有效的寄存器单元,而输出移位寄存器仅起一个并串转换作用。因此称参量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); 3current = 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<dis_temp2)

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;

%选择较小汉明距的状态储存并输出在ret_msg中,最小汉明距存于ret_dis end end 45

篇三:卷积码实验报告 一、实验目的

1.进一步熟悉matlab编程环境。 2.学习卷积码编码基本流程。 二、实验要求:

(1)实验前编写源程序、准备测试数据。

(2)在matlab下完成程序的编辑、编译、运行,获得程序结果。如果结果有误,应找出原因,并设法更正之。 三、实验内容 ①主函数 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

②状态积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;

③汉明距离hamming_distance.m

function distance = hamming_distance(a,b) temp = a+b;

temp = mod(temp,2); distance = sum(temp);

④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

⑤ 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<dis_temp2)

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;

%选择较小汉明距的状态储存并输出在ret_msg中,最小汉明距存于ret_dis end end end

[val,index] = sort(ret_dis); %把最终选择的6种最小汉明距按从小到大排列 msg =ret_msg(index(1),:); %选出维特比译码最小的距离所译出的信息 四、实验数据记录及分析 msg =

columns 1 through 20

1 1 0 1 0 0 1 1 1 word =

columns 1 through 40 1 1 0 1 1 1 0 word1 =

columns 1 through 40 1 1 0 1 1 1 0 msg_1 =

columns 1 through 20

1 1 0 1 0 0 1 1 1 ans=

columns 1 through 20

0 0 0 0 0 0 0 0 0

由matlab实验结果可见,编码译码程序正确。也说明了维特比译码的可靠性四、实验心得

体会

这次试验的代码也是老师给的,matlab是上学期学的课程,说实话已经忘了差不多了,所以其实是不怎么看的懂试验代码的。看来还是得好好复习下matlab的相关知识。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务