资源简介
viterbi软判决和硬判决译码算法,
两个函数,有详细注释
代码片段和文件信息
%硬判决
function decoder_output=viterbi_hard(yL)
global G;
n=size(G1);
K=size(G2);
number_of_states=2^(K-1);
%------------------------------------------------
%-------------生成各分支的输出--------------------
%------------------------------------------------
for j=0:number_of_states-1
for t=0:1
[next_statememory_contents]=next_state_fun(jtK);
input(j+1next_state+1)=t;
branch_output=rem(memory_contents*G‘2);
nextstate(j+1t+1)=next_state;
output(j+1t+1)=bin2deci(branch_output);
end
end
%------------------------------------------------
metric_of_states=zeros(1number_of_states); %各状态的度量metric
metric_of_states_c=zeros(number_of_states2); %各状态两个输入的度量
length_seq=length(y)/n; %符号个数
decoder_output=zeros(1length_seq-K+1); %解码输出
channel_output_matrix=reshape(ynlength_seq); %将解调输出的比特按符号排列
survivor_state=zeros(number_of_stateslength_seq+1); %留存路径
input_of_state=zeros(number_of_stateslength_seq+12); %汇聚到各状态的分支对应的输入
state_sequence=zeros(1length_seq+1);
count=zeros(1number_of_states);
for i=1:length_seq-K+1
%------------------------------------------------
for j=0:number_of_states-1
for t=0:1
binary_output=deci2bin(output(j+1t+1)n); %将各分支的输出转换为2进制
branch_metric=Hamming_dis(channel_output_matrix(:i)‘binary_output); %计算分支度量
count(nextstate(j+1t+1)+1)=count(nextstate(j+1t+1)+1)+1;
metric_of_states_c(nextstate(j+1t+1)+1count(nextstate(j+1t+1)+1))=metric_of_states(j+1)+branch_metric; %计算累积度量(加)
input_of_state(nextstate(j+1t+1)+1:count(nextstate(j+1t+1)+1))=survivor_state(j+1:); %该分支所在路径的对应的输入
input_of_state(nextstate(j+1t+1)+1icount(nextstate(j+1t+1)+1))=t;
end;
end;
%----------------比较汇聚到同一状态的两条路径,选取距离较小的-----------------
for j=0:number_of_states-1
if metric_of_states_c(j+11)>=metric_of_states_c(j+12)
metric_of_states(j+1)=metric_of_states_c(j+12);
survivor_state(j+1:)=input_of_state(j+1:2);
else
metric_of_states(j+1)=metric_of_states_c(j+11);
survivor_state(j+1:)=input_of_state(j+1:1);
end;
end;
count=zeros(1number_of_states);
%--------------------------截短输出------------------------------------
if i>L
[min_metriclocation]=min(metric_of_states);
decoder_output(i-L)=survivor_state(locationi-L);
end;
end
%---------------------最后L个比特译码输出--------------------------------
[min_metriclocation]=min(metric_of_states);
decoder_output(length_seq-K+1-L+1:length_seq-K+1)=survivor_state(locationlength_seq-K+1-L+1:length_seq-K+1);
% =========================================================
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3130 2017-12-04 11:53 viterbi_hard.m
文件 2688 2018-01-02 15:59 viterbi_soft.m
- 上一篇:基于VHDL语言的循环码编译码系统的设计
- 下一篇:Linux 常用C函数中文版
评论
共有 条评论