📄 viterbi_encoder.m
字号:
function [channel_input]=viterbi_encoder(G,k,coder_input)
% 卷积码编码
% G为生成多项式系数矩阵
% k for input number k为输入位数
% coder_input为输入码序列
channel_input=[];
% n for output number n为输出位数
n=size(G,1); % 矩阵G的行数
G_2=size(G,2); % 矩阵G的列数
% 如果矩阵G和输入码序列的列数不是k的整数倍则报错
if rem(size(G,2),k)~=0
error('Size of G and k do not agree')
end
if rem(size(coder_input,2),k)~=0
error('Size of Input and k do not agree')
end
depth_of_input=length(coder_input)/k;
% header 将所有移位寄存器清零,输入序列开始进行编码
for i=1:size(G,2)/k-1
input_matrix=[coder_input(i*k:-1:1),zeros(1,size(G,2)-i*k)];
gg_out=G*input_matrix';
for l=1:n
channel_input(n*(i-1)+l)=rem(gg_out(l),2);
end
end
% body 输入序列中间段编码
for i=size(G,2)/k:depth_of_input
input_matrix=[coder_input(k*i:-1:k*i-G_2+1)];
gg_out=G*input_matrix';
for l=1:n
channel_input(n*(i-1)+l)=rem(gg_out(l),2);
end
end
% tailer 输入序列结束,所有移位寄存器清零
for i=(G_2/k-1):-1:1
input_matrix=[zeros(1,G_2-i*k),coder_input(depth_of_input*k:-1:(depth_of_input-i)*k+1)];
gg_out=G*input_matrix';
for l=1:n
channel_input(n*(G_2/k-i-1)+l+depth_of_input*n)=rem(gg_out(l),2);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -