📄 logmapo.m
字号:
function L_all =logmapo(rec_s,g,L_a)
% Copyright Jan. 2006 Li Qiang
% EEE. Hongkong University of Science & Technology
% for academic use only
% Log_MAP algorithm using straightforward method to compute branch metrics
% no approximation is used.
% Can be simplified to Max-Log-MAP by using approximation ln(e^x+e^y) =max(x,y).
% Input: rec_s: scaled received bits.
% rec_s = 0.5 * L_c * r = ( 2 * a * rate * Eb/N0 ) * r
% g: code generator for the component RSC code, in binary matrix form.
% L_a: a priori info. for the current decoder,
% scrambled version of extrinsic Inftyo. of the previous decoder.
%
% Output: L_all: log-likelihood ratio of the symbols. Complete information.
% Total number of bits: Inftyo. + tail
L_total = length(rec_s)/2;
[n,K] = size(g);
m = K - 1;
nstates = 2^m; % number of states in the trellis
% Set up the trellis
[next_out0, next_state0, last_out0, last_state0, last_out1, last_state1] = trellis(g);
Infty = 1e10;
% Initialization of Alpha
Alpha(1,1) = 0;
Alpha(1,2:nstates) = -Infty*ones(1,nstates-1);
% Initialization of Beta
Beta(L_total,1) = 0;
Beta(L_total,2:nstates) = -Infty*ones(1,nstates-1);
% Trace forward, compute Alpha
for k = 2:L_total+1
for state2 = 1:nstates
gamma = -Infty*ones(1,nstates);
gamma(last_state0(state2,1)) = (rec_s(2*k-3)+rec_s(2*k-2)*last_out0(state2,2))+L_a(k-1)/2;
gamma(last_state0(state2,2)) = (-rec_s(2*k-3)+rec_s(2*k-2)*last_out0(state2,4))-L_a(k-1)/2;
tmp = gamma+Alpha(k-1,:);
Alpha(k,state2) = tmp(1);
for state = 2:nstates
Alpha(k,state2) = max(tmp(state),Alpha(k,state2))+log(1+exp(-abs(tmp(state)-Alpha(k,state2))));
end
end
tempmax(k) = max(Alpha(k,:));
Alpha(k,:) = Alpha(k,:) - tempmax(k);
end
% Trace backward, compute Beta
for k = L_total-1:-1:1
for state1 = 1:nstates
gamma = -Infty*ones(1,nstates);
gamma(next_state0(state1,1)) = (rec_s(2*k+1)+rec_s(2*k+2)*next_out0(state1,2))+L_a(k+1)/2;
gamma(next_state0(state1,2)) = (-rec_s(2*k+1)+rec_s(2*k+2)*next_out0(state1,4))-L_a(k+1)/2;
tmp = gamma+Beta(k+1,:);
Beta(k,state1) = tmp(1);
for state = 2:nstates
Beta(k,state1) = max(tmp(state),Beta(k,state1))+log(1+exp(-abs(tmp(state)-Beta(k,state1))));
end
end
Beta(k,:) = Beta(k,:) - tempmax(k+1);
end
% Compute the soft output, log-likelihood ratio of symbols in the frame
for k = 1:L_total
for state2 = 1:nstates
gamma0 = (rec_s(2*k-1)+rec_s(2*k)*last_out0(state2,2))+L_a(k)/2;
gamma1 = (-rec_s(2*k-1)+rec_s(2*k)*last_out0(state2,4))-L_a(k)/2;
temp0(state2) = gamma0 + Alpha(k,last_state0(state2,1)) + Beta(k,state2);
temp1(state2) = gamma1 + Alpha(k,last_state0(state2,2)) + Beta(k,state2);
end
tmp0 = temp0(1);
tmp1 = temp1(1);
for state = 2:nstates
tmp0 = max(tmp0,temp0(state))+log(1+exp(-abs(tmp0-temp0(state))));
tmp1 = max(tmp1,temp1(state))+log(1+exp(-abs(tmp1-temp1(state))));
end
L_all(2*k-1) = tmp0 - tmp1;
for state2 = 1:nstates
gamma0 = (rec_s(2*k-1)*last_out1(state2,1)+rec_s(2*k))+last_out1(state2,1)*L_a(k)/2;
gamma1 = (rec_s(2*k-1)*last_out1(state2,3)-rec_s(2*k))+last_out1(state2,3)*L_a(k)/2;
temp0(state2) = gamma0 + Alpha(k,last_state1(state2,1)) + Beta(k,state2);
temp1(state2) = gamma1 + Alpha(k,last_state1(state2,2)) + Beta(k,state2);
end
tmp0 = temp0(1);
tmp1 = temp1(1);
for state = 2:nstates
tmp0 = max(tmp0,temp0(state))+log(1+exp(-abs(tmp0-temp0(state))));
tmp1 = max(tmp1,temp1(state))+log(1+exp(-abs(tmp1-temp1(state))));
end
L_all(2*k) = tmp0 - tmp1;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -