?? viterbi_encoder.m
字號:
function [channel_input]=viterbi_encoder(G,k,coder_input)
%k為輸入位數
channel_input=[];
n=size(G,1);%n為輸出位數,生成矩陣G的行數
G_2=size(G,2);%G_2 生成矩陣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)];%給輸入序列補0
gg_out=G*input_matrix'; %由輸入序列和生成矩陣得到輸出
for l=1:n
channel_input(n*(i-1)+l)=rem(gg_out(l),2);%由模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 + -