卷积码+交织+维特比译码+解交织.docx

上传人:b****3 文档编号:13284150 上传时间:2023-06-12 格式:DOCX 页数:15 大小:119.07KB
下载 相关 举报
卷积码+交织+维特比译码+解交织.docx_第1页
第1页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第2页
第2页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第3页
第3页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第4页
第4页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第5页
第5页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第6页
第6页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第7页
第7页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第8页
第8页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第9页
第9页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第10页
第10页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第11页
第11页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第12页
第12页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第13页
第13页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第14页
第14页 / 共15页
卷积码+交织+维特比译码+解交织.docx_第15页
第15页 / 共15页
亲,该文档总共15页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

卷积码+交织+维特比译码+解交织.docx

《卷积码+交织+维特比译码+解交织.docx》由会员分享,可在线阅读,更多相关《卷积码+交织+维特比译码+解交织.docx(15页珍藏版)》请在冰点文库上搜索。

卷积码+交织+维特比译码+解交织.docx

卷积码+交织+维特比译码+解交织

1.实验摘要

实验1卷积码编码

实验2交织编码

实验3解交织

实验4维特比译码

2.实验1

2.1实验1概要

在实验1中,首先给出了卷积码编码的流程,然后给出了实现卷积码编码的源程序。

2.2程序的具体过程

2.2.1程序流程

2.2.2MATLAB源程序

function[output]=cnv_encd(input)

%output=cnv_encd(g,k0,input)卷积码编码函数

%g生成矩阵

%k0输入码长

%input输入信源序列

%output输出卷积编码序列

g=[111;101];%编码矩阵

k0=1;

input=[1101];

ifrem(length(input),k0)>0

input=[input,zeros(size(1:

k0-rem(length(input),k0)))];

end

n=length(input)/k0;

ifrem(size(g,2),k0)>0

error('Error,gisnotoftherightsize.')

end

li=size(g,2)/k0;

n0=size(g,1);

u=[zeros(size(1:

(li-1)*k0)),input,zeros(size(1:

(li-1)*k0))];

u1=u(li*k0:

-1:

1);

fori=1:

n+li-2

u1=[u1,u((i+li)*k0:

-1:

i*k0+1)];

end

uu=reshape(u1,li*k0,n+li-1);

output=reshape(rem(g*uu,2),1,n0*(n+li-1));

3.实验2

3.1实验2概要

在实验2中,给出了两种交织编码的过程—卷积交织和循环等差交织,然后给出了实现这两种交织编码的源程序。

3.2程序的具体过程

3.2.1程序流程

3.2.2MATLAB源程序

(1)卷积交织

function[aa]=jiaozhi(bb,n)

%jiaozhi.m卷积交织函数

n=28;%分组长度

%bb卷积交织前原分组序列

%aa卷积交织后分组序列

%序号重排方式:

cc=[123171151721;82241812628;15932519137;2216104262014];%交织矩阵

bb=[12345678910111213141516171819202122232425262728];

fori=1:

n

aa(i)=bb(cc(i));

end

(2)循环等差交织

function[aa]=jiaozhi_nocnv(bb,n)

%jiaozhi_nocnv.m循环等差交织函数

n=28;%分组长度

%bb循环等差交织前原分组序列

%aa循环等差交织后还原分组序列

%序号重排方式:

bb=[12345678910111213141516171819202122232425262728];

j=1;

fori=1:

n

j=rem(j+5-1,n)+1;%序号重排方式迭代算法

aa(n+1-i)=bb(j);

end

3.2.3程序说明

交织码通常表示为(M,N),分组长度L=MN,交织方式用M行N列的交织矩阵表示。

一般,交织方式分为分组交织和卷积交织。

分组交织的交织矩阵按列写入,按行读出;去交织矩阵按行写入按列读出。

卷积交织的交织矩阵和去交织矩阵的写入与读出均按行进行。

注意本次仿真采用(7,4)卷积交织编码和循环等差交织编码。

所谓循环等差,是指将序号从大到小顺时针排成一圈,从1开始等间隔逆时针取28个数,间隔为4,这样依次取的28个数即序号重排方式。

4.实验3

4.1实验3概要

与实验2对应的,在实验3中,也给出了与实验2对应的两种解交织的的流程,然后给出了实现这两种解交织操作的源程序。

4.2程序的具体过程

4.2.1程序流程

4.2.2MATLAB源程序

(1)解卷积交织

function[bb]=jiejiaozhi(aa,n)

%jiejiaozhi.m解卷积交织函数

n=28;%分组长度

%aa解卷积交织前原分组序列

%bb解卷积交织后分组序列

%序号重排方式:

cc=[123171152721;82241812628;15932519137;2216104262014];

aa=[18152223291617243101118254512192627613202128714];

fori=1:

n

bb(cc(i))=aa(i);

end

(2)解循环等差交织

function[bb]=jiejiaozhi_nocnv(aa,n)

%jiaozhi_nocnv.m解循环等差交织函数

n=28;%分组长度

%aa解循环等差交织前原分组序列

%bb解循环等差交织后还原分组序列

%序号重排方式:

aa=[12419149427221712722520151052823181383262116116];

j=1;

fori=1:

n

j=rem(j+5-1,n)+1;%序号重排方式迭代算法

bb(j)=aa(n+1-i);

end

5.实验4

5.1实验4概要

由于维特比译码算法是卷积码译码的最常用算法,因此在实验5中,首先给出了维特比译码的流程,然后给出了实现维特比译码的源程序。

5.2程序的具体过程

5.2.1程序流程

5.2.2MATLAB源程序

1)

functiony=bin2deci(x)

l=length(x);

y=(l-1:

-1:

0);

y=2.^y;

y=x*y';

2)

functiony=deci2bin(x,l)

y=zeros(1,l);

i=1;

whilex>=0&i<=l

y(i)=rem(x,2);

x=(x-y(i))/2;

i=i+1;

end

y=y(l:

-1:

1);

3)

functiondistance=metric(x,y)

ifx==y

distance=0;

else

distance=1;

end

4)

function[next_state,memory_contents]=nxt_stat(current_state,input,L,k)

binary_state=deci2bin(current_state,k*(L-1));

binary_input=deci2bin(input,k);

next_state_binary=[binary_input,binary_state(1:

(L-2)*k)];

next_state=bin2deci(next_state_binary);

memory_contents=[binary_input,binary_state];

5)

function[decoder_output,survivor_state,cumulated_metric]=viterbi(channel,snr_db)

G=[111;101];%G卷积编码矩阵,如(2,1,3)卷积码生成矩阵[111;101],可以根据自己的需要输入编码矩阵

k=1;%k信息源输入端口数k=1

channel=[110101001011];%信源编码

snr_db=6;%信噪比,可以通过调节信噪比大小观察viterbi译码的性能

%bpsk调制

%channel_output=bpsk(channel,snr_db);%调用bpsk函数,得到信道编码

channel_output=channel;

n=size(G,1);%n编码输出端口数量,(2,1,3)中n=2

ifrem(size(G,2),k)~=0%当G列数不是k的整数倍时

error('SizeofGandkdonotagree')%发出出错信息

end

ifrem(size(channel_output,2),n)~=0%当输出量元素个数不是输出端口的整数倍时

error('channeloutputnotoftherightsize')

end

N=size(G,2)/k;%得出移位数,即寄存器的个数

M=2^k;

number_of_states=2^(k*(N-1));%状态数

forj=0:

number_of_states-1%j表示当前寄存器组的状态因为状态是从零

%开始的,所以循环从0到number_of_states-1

form=0:

M-1%m为从k个输入端的信号组成的状态,总的状

%态数为2^k,所以循环从0到2^k-1

%nxt_stat完成从当前的状态和输入的矢量得出下寄存器组的一个状态

[next_state,memory_contents]=nxt_stat(j,m,N,k);%调用nxt_stat函数

input(j+1,next_state+1)=m;

branch_output=rem(memory_contents*G',2);

nextstate(j+1,m+1)=next_state;

output(j+1,m+1)=bin2deci(branch_output);

end

end

%state_metric数组用于记录译码过程在每状态时的汉明距离

%state_metric大小为number_of_states2,(:

1)当前

%状态位置的汉明距离,为确定值,而(:

2)为当前状态加输入

%得到的下一个状态汉明距离,为临时值

state_metric=zeros(number_of_states,2);

depth_of_trellis=length(channel_output)/n;

channel_output_matrix=reshape(channel_output,n,depth_of_trellis);

survivor_state=zeros(number_of_states,depth_of_trellis+1);

fori=1:

depth_of_trellis-N+1

flag=zeros(1,number_of_states);

if(i<=N)

step=2^(k*(N-i));

else

step=1;

end

forj=0:

step:

number_of_states-1

form=0:

M-1

branch_metric=0;

binary_output=deci2bin(output(j+1,m+1),n);

forll=1:

n

branch_metric=branch_metric+metric(channel_output_matrix(ll,i),binary_output(ll));

end

%选择码间距离较小的那条路径

%选择方法:

%当下一个状态没有被访问时就直接赋值,否则,用比它小的将其覆盖

if((state_metric(nextstate(j+1,m+1)+1,2)>state_metric(j+1,1)+branch_metric)|flag(nextstate(j+1,m+1)+1)==0)

state_metric(nextstate(j+1,m+1)+1,2)=state_metric(j+1,1)+branch_metric;

survivor_state(nextstate(j+1,m+1)+1,i+1)=j;

flag(nextstate(j+1,m+1)+1)=1;

end

end

end

state_metric=state_metric(:

2:

-1:

1);

end

fori=depth_of_trellis-N+2:

depth_of_trellis

flag=zeros(1,number_of_states);

%状态数从number_of_states→number_of_states/2→...→2→1

%程序说明同上,只不过输入矢量只为0

last_stop=number_of_states/(2^(k*(i-depth_of_trellis+N-2)));

forj=0:

last_stop-1

branch_metric=0;

binary_output=deci2bin(output(j+1,1),n);

forll=1:

n

branch_metric=branch_metric+metric(channel_output_matrix(ll,i),binary_output(ll));

end

if((state_metric(nextstate(j+1,1)+1,2)>state_metric(j+1,1)+branch_metric)|flag(nextstate(j+1,1)+1)==0)

state_metric(nextstate(j+1,1)+1,2)=state_metric(j+1,1)+branch_metric;

survivor_state(nextstate(j+1,1)+1,i+1)=j;

flag(nextstate(j+1,1)+1)=1;

end

end

state_metric=state_metric(:

2:

-1:

1);

end

%从最佳路径中产生解码

%译码过程可从数组survivor_state的最后一个位置向前逐级译码

state_sequence=zeros(1,depth_of_trellis+1);

state_sequence(1,depth_of_trellis)=survivor_state(1,depth_of_trellis+1);

fori=1:

depth_of_trellis

state_sequence(1,depth_of_trellis-i+1)=survivor_state((state_sequence(1,depth_of_trellis+2-i)+1),depth_of_trellis-i+2);

end

decoder_output_matrix=zeros(k,depth_of_trellis-N+1);

fori=1:

depth_of_trellis-N+1

%根据数组input的定义来得出从当前状态到下一个状态的输入信号矢量

dec_output_deci=input(state_sequence(1,i)+1,state_sequence(1,i+1)+1);

dec_output_bin=deci2bin(dec_output_deci,k);

%将一次译码存入译码输出矩阵decoder_output_matrix相应的位置

decoder_output_matrix(:

i)=dec_output_bin(k:

-1:

1)';

end

decoder_output=reshape(decoder_output_matrix,1,k*(depth_of_trellis-N+1));

cumulated_metric=state_metric(1,1);

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2