Thanks Roger; that is a clever substitute. It runs 0.01 second faster than the original one.
Steve: The code above is an excerpt of BCJR algorithm. It is the forward recursion part which sweeps over the trellis structure from the beginning to the end in forward direction. It is difficult to explain in words what that excerpt is trying to do for the general audience since it requires a lot of backgroun math to set the scene.
I have another loop similar to the first one which is a backward recursion. It starts from the end working its way to the beginning:
% Backwards recursion b=zeros(16,length); b=b-inf; b(1,length)=0; for i= length-1:-1:1 for j= 1:32 A = b(transitions(j,1),i); B = b(transitions(j,2),i+1) + ug (j, i+1) + eg(j, i+1); if(A == -inf && B == -inf) b(transitions(j,1),i) = -inf; else b(transitions(j,1),i)= max(A,B) + log(1+exp(-abs(A-B))); end end end
If I apply Roger's idea I get 0.02 sec improvement in one calling. However, the main problem that costs time here is the big length of the signal (the variable i here). But thanks Roger, that was clever.