Step 4. Tentative Decoding

set rn =1 if  q1n >0.5

and rn=0 otherwise.

If  r.HT = 0  stop
Else go to step 2.

In the software implementation the algorithm iterates 1000  times.
The function decode_ldpc(rx_waveform,No,amp,h,scale) does the decoding.
The function takes 4 parameters
                                          (i) rx_waveform : The soft output of the gaussian channel
                                          (ii) No: Twice the magnitude of PSD of the AWGN (No/2)
                                          (iii)amp: the amplitude of the bpsk waveform (amp representing the voltage for 1and -amp
                                                                                                                representing the voltage for 0)
                                          (iv)h: the parity check matrix to be used for decoding.
                                          (v)scale: this array contains the factor by which each bit was scaled before reception.
                                                       This helps you simulate different types of fading. If you apply  a certain type of fading to the
                                                       bits before adding the AWGN, then the fade coefficients for each bit in the codeword is
                                                       contained in 'scale'. The length of the array equals the length of the codeword.
                                                       If you don't want any fading, just initialize scale to an  all ones array.
                                                       The elements of the scale array are used in Step 1( Initialization) to compute  the
                                                       likelyhoods.

The function returns the decoded codeword and not the message bits.
The function can be used along with the modulation and channel transmission functions as shown below:

Function Usage Example:
  % assume the codeword c, the parity check matrix H and No are already loaded into the MATLAB memory
  tx_waveform=bpsk(c,1);  %amp= 1
  rx_waveform=awgn(tx_waveform,No);
  scale(1:length(c))=1;  %No fading.
  vhat=decode_ldpc(rx_waveform,No,1,h,scale) %since amp=1;

If you want to simulate a Rayleigh Fading channel and do the decoding, here is how your code should look like

 % assume the codeword c, the parity check matrix H and No are already loaded into the MATLAB memory
  tx_waveform=bpsk(c,1);  %amp= 1
  scale(1:length(c))=sqrt(exprnd(1,1,length(c)));
                                    %sqrt of an exponential Random Variable (RV) is Rayleigh
                                    %exprnd is a function available in the Statistics Toolbox and generates exponential RV's
  tx_waveform=tx_waveform.*scale;
  rx_waveform=awgn(tx_waveform,No);
  vhat=decode_ldpc(rx_waveform,No,1,h,scale) %since amp=1;

Once the decoding is done ( the termination condition is satisfied or the maximum number of iterations are performed), the message bits need to be extracted.  At the last step of encoding the message blocks, the reordering done to get a non-singular A was undone. If this reordering was done again, the message bits would be located at the end of the decoded codeword and can be extracted easily. The rearranged_cols array (output by the rearrange_cols( ) function) that holds the reordering information is used to do the reordering. The extract_mesg(vhat,rearranged_cols) works in this manner.

Function Usage Example:
 % assume we have the rearranged_cols array output by the rearrange_cols( ) function already loaded into MATLAB memory
 uhat = extract_mesg(vhat,rearranged_cols);
 



LDPC Software Index