📄 decoder.m
字号:
function [output,Error] = decoder(input)
Linput = length(input); % length of the input
Error=zeros(1,4); % error metric for each state, updated each time instant
newError = zeros(1,4); % update of the error metric
temp_output1 = [] ; % temporary possible output computed for state1, updated each time instant
temp_output2 = [] ; % temporary possible output computed for state2, updated each time instant
temp_output3 = [] ; % temporary possible output computed for state3, updated each time instant
temp_output4 = [] ; % temporary possible output computed for state4, updated each time instant
%The first two step in the trellis are particular, since the first state is
%always 00.
%initialization for the first step
Error(1)=sum(input(1:2) ~= [0 0]);
Error(3)=sum(input(1:2) ~= [1 1]);
%for the second step
newError(1)=Error(1)+sum(input(3:4) ~= [0 0]);
temp_output1 = [0 0];
newError(2)=Error(3)+sum(input(3:4) ~= [1 0]);
temp_output2 = [1 0];
newError(3)=Error(1)+sum(input(3:4) ~= [1 1]);
temp_output3 = [0 1];
newError(4)=Error(3)+sum(input(3:4) ~= [0 1]);
temp_output4 = [1 1];
Error=newError;
for k = 5:2:Linput
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%for each step in the trellis we update the counter of errors of each state
%and temporary output (the beginning of the possible final output) of each
%state.
%There are two possibilities to reach the state 00 (1):
%_ state 00 (1), input 0 --> code 00
%_ state 01 (2), input 0 --> code 11
[newError(1),i1] = min([Error(1)+ sum(input(k:k+1)~= [0 0]),Error(2)+ sum(input(k:k+1)~= [1 1])]);
if i1 == 1
newtemp_output1 = [temp_output1 0];
else
newtemp_output1 = [temp_output2 0];
end
%There are two possibilities to reach the state 01 (2):
%_ state 10 (3), input 0 --> code 10
%_ state 01 (4), input 0 --> code 01
[newError(2),i2] = min([Error(3)+ sum(input(k:k+1)~= [1 0]),Error(4)+ sum(input(k:k+1)~= [0 1])]);
if i2 == 1
newtemp_output2 = [temp_output3 0];
else
newtemp_output2 = [temp_output4 0];
end
%There are two possibilities to reach the state 01 (3):
%_ state 00 (1), input 1 --> code 11
%_ state 01 (2), input 1 --> code 00
[newError(3) i3] = min([Error(1)+ sum(input(k:k+1)~= [1 1]),Error(2)+ sum(input(k:k+1)~= [0 0])]);
if i3 == 1
newtemp_output3 = [temp_output1 1];
else
newtemp_output3 = [temp_output2 1];
end
%There are two possibilities to reach the state 11 (4):
%_ state 10 (3), input 1 --> code 01
%_ state 11 (4), input 1 --> code 10
[newError(4) i4] = min([Error(3)+ sum(input(k:k+1)~= [0 1]),Error(4)+ sum(input(k:k+1)~= [1 0])]);
if i4 == 1
newtemp_output4 = [temp_output3 1];
else
newtemp_output4 = [temp_output4 1];
end
%we update the values for the next step
Error=newError;
temp_output1=newtemp_output1;
temp_output2=newtemp_output2;
temp_output3=newtemp_output3;
temp_output4=newtemp_output4;
end
%At the end, we compare the error metric for each state. We take the min
%value and take the corresponding output.
[Error_total i] = min([Error(1), Error(2), Error(3), Error(4)]);
switch i
case{1}
output=temp_output1;
case{2}
output=temp_output2;
case{3}
output=temp_output3;
case(4)
output=temp_output4;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -