📄 sova0.m
字号:
function L_all = sova(rec_s, g, L_a, ind_dec)
% This function implememts Soft Output Viterbi Algorithm in trace back mode
% Input:
% rec_s: scaled received bits. rec_s(k) = 0.5 * L_c(k) * y(k)
% L_c = 4 * a * Es/No, reliability value of the channel
% y: received bits
% g: encoder generator matrix in binary form, g(1,:) for feedback, g(2,:) for feedforward
% L_a: a priori information about the info. bits. Extrinsic info. from the previous
% component decoder
% ind_dec: index of the component decoder.
% =1: component decoder 1; The trellis is terminated to all zero state
% =2: component decoder 2; The trellis is not perfectly terminated.
% Output:
% L_all: log ( P(x=1|y) ) / ( P(x=-1|y) )
%
% Copyright: Yufei Wu, Nov. 1998
% MPRG lab, Virginia Tech
% for academic use only
% Frame size, info. + tail bits
L_total = length(L_a);
[n,K] = size(g);
m = K - 1;
nstates = 2^m;
Infty = 1e10;
% SOVA window size. Make decision after 'delta' delay. Decide bit k when received bits
% for bit (k+delta) are processed. Trace back from (k+delta) to k.
% why set delta=30,not 40,10,20? -yzh
delta = 30;
% Set up the trellis defined by g.
[next_out, next_state, last_out, last_state] = trellis(g);
% Initialize path metrics to -Infty
for t=1:L_total+1
for state=1:nstates
path_metric(state,t) = -Infty;
end
end
% Why not use "path_metric=zeros(nstates,L_total+1)"? -yzh
% Trace forward to compute all the path metrics
path_metric(1,1) = 0; % why path_metric(1,1) is set to 0? -yzh
for t=1:L_total
% received bits at time t -yzh
y = rec_s(2*t-1:2*t);
% state: current state of decoder register -yzh
for state=1:nstates % state: vector,states start from step t+1, trace back from last state(step t) --yzh
sym0 = last_out(state,1:2);
sym1 = last_out(state,3:4);
state0 = last_state(state,1);
state1 = last_state(state,2);
% Mk0/Mk1: metric of state at time t -yzh
% y*sym0'/y*smy1': reliability is related to the amplitude of received bits
% -yzh
Mk0 = y*sym0' - L_a(t)/2 + path_metric(state0,t); % not lne function? -yzh
Mk1 = y*sym1' + L_a(t)/2 + path_metric(state1,t); % why +L_a(t)/2? received bit is 1(+1) -yzh
if Mk0>Mk1
path_metric(state,t+1)=Mk0;
Mdiff(state,t+1) = Mk0 - Mk1;
prev_bit(state, t+1) = 0; % decide the input bit -yzh
else
path_metric(state,t+1)=Mk1;
Mdiff(state,t+1) = Mk1 - Mk0;
prev_bit(state,t+1) = 1; % decide the input bit -yzh
end
end
end
% For decoder 1, trace back from all zero state,
% for decoder two, trace back from the most likely state
% Why decoder 1 trace back from zero state and 2 trace back from the most likely state? see encoderm.m and rsc_encode.m for answer -yzh
% mlstate: Maximum likelihood state? -yzh
if ind_dec == 1
mlstate(L_total+1) = 1;
else
% find( path_metric(:,L_total+1)==max(path_metric(:,L_total+1)) ) :
% return the row number of the max value of L_total column -yzh
% the row number is the state, see the definition of path_metric -yzh
mlstate(L_total+1) = find( path_metric(:,L_total+1)==max(path_metric(:,L_total+1)) );
mlstate;
end
% Trace back to get the estimated bits, and the most likely path
for t=L_total:-1:1
est(t) = prev_bit(mlstate(t+1),t+1);
mlstate(t) = last_state(mlstate(t+1), est(t)+1);
end
% Find the minimum delta that corresponds to a competition path with different info. bit estimation.
% Give the soft output
% delta: what's the meaning? -yzh
for t=1:L_total
llr = Infty;
% i should from 1 to delta,i=0 is no meaning? -yzh
for i=0:delta
if t+i<L_total+1 % if t+i>L_total+1 will not track back?
bit = 1-est(t+i); % another competition path's output. -yzh
temp_state = last_state(mlstate(t+i+1), bit+1); % why is mlstate(t+i+1),not mlstate(t+i)? -yzh
for j=i-1:-1:0 % % find competition path from temp_state defined above
bit = prev_bit(temp_state,t+j+1); % trace back for the competition path -yzh
temp_state = last_state(temp_state, bit+1); % trace back for the competition path -yzh
end
if bit~=est(t)
llr = min( llr,Mdiff(mlstate(t+i+1), t+i+1) ); % Why is llr calculated in this way? -yzh
% see <A primer on turbo code concept> page 6, equation (50)
% -yzh
end
end
end
L_all(t) = (2*est(t) - 1) * llr; % Why is L_all(t) calculated in this way? -yzh
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -