Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

soft viterbi implementation

Status
Not open for further replies.

shameem

Member level 5
Member level 5
Joined
Oct 27, 2005
Messages
90
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,288
Activity points
2,031
function encoder_out=cnv_encd(g,k,encoder_in)

hi,
Can anybody please upload some good material on implementation of soft viterbi decoder?
I need it very much. Olease help.

thanks
 

These two functions are for conv. encoder and soft viterbi decoder
%---------------------------------------------------------------------------

function encoder_out=cnv_encd(G,k,encoder_in)
% cnv_encd(G,k,encoder_in)
% determines the output sequence of a binary convolutional encoder
% G is the generator matrix of the convolutional code
% with n0 rows and l*k columns. Its rows are g1,g2,...,gn.
% k is the number of bits entering the encoder at each clock cycle.
% encoder_in The binary input seq.

% check to see if extra zero padding is necessary
if rem(length(encoder_in),k) > 0
encoder_in=[encoder_in,zeros(size(1:k-rem(length(encoder_in),k)))];
end
n=length(encoder_in)/k;
% check the size of matrix G
if rem(size(G,2),k) > 0
error('Error, g is not of the right size.')
end
% determine l and n0
l=size(G,2)/k;
n0=size(G,1);
% add extra zeros
u=[zeros(size(1:(l-1)*k)),encoder_in,zeros(size(1:(l-1)*k))];
% generate uu, a matrix whose columns are the contents of
% conv. encoder at various clock cycles.
u1=u(l*k:-1:1);
for i=1:n+l-2
u1=[u1,u((i+l)*k:-1:i*k+1)];
end
uu=reshape(u1,l*k,n+l-1);
% determine the output
encoder_out=reshape(rem(G*uu,2),1,n0*(l+n-1));



%---------------------------------------------------------------------------------

function [decoder_out,survivor_state,cumulated_metric]=viterbi_soft(G,k,decoder_in)
% VITERBI The Viterbi decoder for convolutional codes
% [decoder_out,survivor_state,cumulated_metric]=viterbi(G,k,decoder_in)
% G is a n x Lk matrix each row of which
% determines the connections from the shift register to the
% n-th output of the code, k/n is the rate of the code.
% survivor_state is a matrix showing the optimal path through
% the trellis. The metric is given in a separate function metric(x,y)
% and can be specified to accomodate hard and soft decision.
% This algorithm minimizes the metric rather than maximizing
% the likelihood.

n=size(G,1);
% check the sizes
if rem(size(G,2),k) ~=0
error('Size of G and k do not agree')
end
if rem(size(decoder_in,2),n) ~=0
error('channel output not of the right size')
end
L=size(G,2)/k;
number_of_states=2^((L-1)*k);
% generate state transition matrix, output matrix, and input matrix
for j=0:number_of_states-1
for l=0:2^k-1
[next_state,memory_contents]=nxt_stat(j,l,L,k);
input(j+1,next_state+1)=l;
branch_output=rem(memory_contents*G',2);
nextstate(j+1,l+1)=next_state;
output(j+1,l+1)=bin2deci(branch_output);
end
end
state_metric=zeros(number_of_states,2);
depth_of_trellis=length(decoder_in)/n;
decoder_in_matrix=reshape(decoder_in,n,depth_of_trellis);
survivor_state=zeros(number_of_states,depth_of_trellis+1);
% start decoding of non-tail channel outputs
for i=1:depth_of_trellis-L+1
flag=zeros(1,number_of_states);
if i <= L
step=2^((L-i)*k);
else
step=1;
end
for j=0:step:number_of_states-1
for l=0:2^k-1
branch_metric=0;
%binary_output=(ones(1,n)-2*deci2bin(output(j+1,l+1),n));
binary_output=deci2bin(output(j+1,l+1),n);
for ll=1:n
branch_metric=branch_metric+abs(decoder_in_matrix(ll,i)-binary_output(ll));
end
if((state_metric(nextstate(j+1,l+1)+1,2) > state_metric(j+1,1)...
+branch_metric) | flag(nextstate(j+1,l+1)+1)==0)
state_metric(nextstate(j+1,l+1)+1,2) = state_metric(j+1,1)+branch_metric;
survivor_state(nextstate(j+1,l+1)+1,i+1)=j;
flag(nextstate(j+1,l+1)+1)=1;
end
end
end
state_metric=state_metric:),2:-1:1);
end
% start decoding of the tail channel-outputs
for i=depth_of_trellis-L+2:depth_of_trellis
flag=zeros(1,number_of_states);
last_stop=number_of_states/(2^((i-depth_of_trellis+L-2)*k));
for j=0:last_stop-1
branch_metric=0;
%binary_output=(ones(1,n)-2*deci2bin(output(j+1,1),n));
binary_output=deci2bin(output(j+1,1),n);
for ll=1:n
branch_metric=branch_metric+abs(decoder_in_matrix(ll,i)-binary_output(ll));
end
if((state_metric(nextstate(j+1,1)+1,2) > state_metric(j+1,1)...
+branch_metric) | flag(nextstate(j+1,1)+1)==0)
state_metric(nextstate(j+1,1)+1,2) = state_metric(j+1,1)+branch_metric;
survivor_state(nextstate(j+1,1)+1,i+1)=j;
flag(nextstate(j+1,1)+1)=1;
end
end
state_metric=state_metric:),2:-1:1);
end
% generate the decoder output from the optimal path
state_sequence=zeros(1,depth_of_trellis+1);
state_sequence(1,depth_of_trellis)=survivor_state(1,depth_of_trellis+1);
for i=1:depth_of_trellis
state_sequence(1,depth_of_trellis-i+1)=survivor_state((state_sequence(1,depth_of_trellis+2-i)...
+1),depth_of_trellis-i+2);
end
decodeder_output_matrix=zeros(k,depth_of_trellis-L+1);
for i=1:depth_of_trellis-L+1
dec_output_deci=input(state_sequence(1,i)+1,state_sequence(1,i+1)+1);
dec_output_bin=deci2bin(dec_output_deci,k);
decoder_out_matrix:),i)=dec_output_bin(k:-1:1)';
end
decoder_out=reshape(decoder_out_matrix,1,k*(depth_of_trellis-L+1));
cumulated_metric=state_metric(1,1);
 

hi ahmedseu,
thank u very much for giving me the code of soft viterbi decoder.

Can u please give me a document, so that i can understand it easily.

thanks
 

dear All,
could any one provide me by a master documentation in implementation of th eviterbi decoder in VHDL , or arch
 

Dear,
it is possible if we can contact via email if u want.I have written a code for a 4state K=2 with rate1/2 hard decision viterbi decoder for the example mentioned in the first paper of Viterbi.
I will now begin to try another one but for soft decision , so we can interchange our knowledge in this field.
Best Regards
 

plz i need viterbi decoder implementation in c language plz if any boby can provide any kind of help to implement it on dsp processor
 

    V

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top