function dec_bits = decoder_75(Lext)

Tc=[ 0 0 0 0 2 1 1;
     1 0 1 1 2 0 0;
     2 1 1 0 3 0 1;
     3 1 0 1 3 1 0];  %trellis for the (7,5) code (in my own special notation. Do not try to understand this, it makes no sense at all)
A1=[0 0 1 0;
    0 0 1 0;
    0 0 0 1;
    0 0 0 1];
A0=[1 0 0 0;
    1 0 0 0;
    0 1 0 0;
    0 1 0 0]; % some other strange initializations
 
blockl=length(Lext)/2;

P=zeros(size(Tc,1),size(Tc,1)*blockl);
B1=zeros(size(Tc,1),size(Tc,1)*blockl);
B0=zeros(size(Tc,1),size(Tc,1)*blockl);
for n=1:blockl,
  P(:,(n-1)*size(Tc,1)+1:n*size(Tc,1)) = decodinggamma(Tc,Lext(2*n-1),Lext(2*n));
end

for n=1:blockl,
  B1(:,(n-1)*size(Tc,1)+1:n*size(Tc,1))=P(:,(n-1)*size(Tc,1)+1:n*size(Tc,1)).*A1;
  B0(:,(n-1)*size(Tc,1)+1:n*size(Tc,1))=P(:,(n-1)*size(Tc,1)+1:n*size(Tc,1)).*A0;
end
f=zeros(size(P,1),1);
b=zeros(size(P,1),1);
f(1)=1;
b(1)=1;
f=[f zeros(size(P,1),blockl)];
b=[zeros(size(P,1),blockl) b];

for k=1:blockl,
  f(:,k+1)=P(:,(k-1)*size(Tc,1)+1:k*size(Tc,1))'*f(:,k);
  f(:,k+1)=f(:,k+1)/sum(f(:,k+1));
end
for k=blockl:-1:1,
  b(:,k)=P(:,(k-1)*size(Tc,1)+1:k*size(Tc,1))*b(:,k+1);
  b(:,k)=b(:,k)/sum(b(:,k));
end
L=zeros(1,blockl-2);


for n=1:blockl-2,
  % if-statements prevents NaNs,
  if f(:,n)'*B0(:,(n-1)*size(Tc,1)+1:n*size(Tc,1))*b(:,n+1)==0,
    L(n)=5;
  elseif f(:,n)'*B1(:,(n-1)*size(Tc,1)+1:n*size(Tc,1))*b(:,n+1)==0,
    L(n)=-5;
  else
    L(n)=log(f(:,n)'*B1(:,(n-1)*size(Tc,1)+1:n*size(Tc,1))*b(:,n+1)/(f(:,n)'*B0(:,(n-1)*size(Tc,1)+1:n*size(Tc,1))*b(:,n+1)));
  end
end

% L is soft outputs,
dec_bits=(sign(L)+1)/2;


end






function gamma = decodinggamma(T,L1,L2)
gamma=zeros(size(T,1),size(T,1));
for i =0:size(T,1)-1,
  for j =0:size(T,1)-1,
    if T(i+1,2)==j,
      gamma(i+1,j+1)=exp(T(i+1,3)*L1)/(1+exp(L1))*exp(T(i+1,4)*L2)/(1+exp(L2))/2;
    elseif T(i+1,5)==j,
      gamma(i+1,j+1)=exp(T(i+1,6)*L1)/(1+exp(L1))*exp(T(i+1,7)*L2)/(1+exp(L2))/2;
    end
  end
end
end





