www.pudn.com > mentos_fs.rar > viterbi_encoder.m


function [channel_input]=viterbi_encoder(G,k,coder_input) 
 
channel_input=[]; 
n=size(G,1); % G的行数对应n路输出 
G_2=size(G,2); % G的列数对应总的寄存器的个数 
 
if rem(size(G,2),k)~=0 % 总的寄存器的个数应为k的整数倍 
   error('Size of G and k do not agree') 
end 
if rem(size(coder_input,2),k)~=0 % 输入的符号数应为k的整数倍 
   error('Size of Input and k do not agree') 
end 
 
depth_of_input=length(coder_input)/k; % 每路输入中的寄存器的个数 
 
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 % n路输出的编码结果 
      channel_input(n*(i-1)+l)=rem(gg_out(l),2); % 模2运算得出信道输出 
   end 
end 
 
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 % n路输出的编码结果 
      channel_input(n*(i-1)+l)=rem(gg_out(l),2); % 模2运算得出信道输出 
   end 
end 
 
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 % n路输出的编码结果 
      channel_input(n*(G_2/k-i-1)+l+depth_of_input*n)=rem(gg_out(l),2); % 模2运算得出信道输出 
   end 
end