Jump to content

Talk:BCH code

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Photonique (talk | contribs) at 16:48, 16 September 2006 (Try & resolve dispute). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

Dispute on Graph

I dont know how this is going to be useful, but to the best of my knowledge this is the graph I obtained from running my simulation code. The main program is given here (ancillary functions omitted for want of space). You can get the full program from | here.

#!/usr/bin/octave -q

#A simple communications channel,

%BPSK uncoded.
System.BER=[];
System.Error=[];
System.Length=36*1000;
System.Mesg=zeros(1,System.Length);
System.Coded=[];

%BCH coded.
System.BCHError=[];
System.BCHBER=[];
System.BCHLength=System.Length*(63.0/36.0);
System.BCHCoded=zeros(1,System.BCHLength);
System.BCHDeCoded=[];


%BPSK parameters.
System.Modulated=[];
System.DeModulated=[];
System.DeCoded=[];
System.CarrierRate=10;
System.DataRate=2;
System.SNRdb=0:0.5:10;


gen_poly=BCH_poly();

Length=length(System.SNRdb);
System.BCHActualErrors=zeros(1,Length);
System.BCHCorrected=zeros(1,Length);

%Additive White Gaussian Noise, power.
System.N0=5;


for iter=1:Length

  disp('=>')
  System.SNRdb(iter)
  System.BCHBER

  disp('Simulating AWGN  channel with BCH & BPSK')

  %Value of SNR
  Eb=System.SNR=10^(System.SNRdb(iter)/10)*System.N0;
  
  %Signal strength, power.
  System.Eb=  System.SNR*System.N0;
  Ec=Eb*36.0/63.0;
  
  %Source Message
  System.Mesg=mod(floor(randn(1,System.Length)),2);

  Rxword=[];
  Chunks=length(System.Mesg)/36;
  for biter=1:Chunks
    bmesg=System.Mesg((biter-1)*36+1:biter*36);
    cwmesg=GF_product(gen_poly,GF_polarize(bmesg));

    %convert from the 0,-1 mode to the 1,0 mode.
    cwmesgTx=cwmesg+1;

    System.BCHCoded((biter-1)*63+1:(biter)*63)=cwmesg;

%Modulate BPSK
    bch1=bpskmod(cwmesgTx,20,10,sqrt(Ec));

%Add noise
    bch2=bch1+sqrt(System.N0)*boxmuller(length(bch1)); 

%Demodulate BPSK
    cwRx=bpskdemod(bch2,20,10,sqrt(Ec)); 

%   This is in the +1,+0 mode,
%   convert to a 0,-1 mode
    cwrecv=cwRx-1;

    Rxword=[Rxword cwrecv];

%error pos gives roots w.r.t index of 0.
   errpos=BCH_decode_berlekamp(cwrecv,63,36,5);%_berlekamp

%so add +1, to convert error position locations form 0 index, to +1 index.
    errpos=errpos+1;

    if isempty(errpos)
      %disp('Codeword is correct')
      correctw=cwrecv;
    else
      %printf('Correcting %d errors\n',length(errpos))
      %errpos
      correctw=cwrecv;
      for i=1:length(errpos)
        %flip the bits,
	correctw(errpos(i))=-(1+correctw(errpos(i)));
      end
    end

   %disp('Corrected CW')
   %correctw
   %fgets(stdin)

   
   CorrectError=length(errpos);
   System.BCHCorrected(iter)=System.BCHCorrected(iter)+CorrectError;

   System.BCHDeCoded((biter-1)*63+1:biter*63)=correctw;
  end
  
  System.BCHActualErrors(iter)=Difference(System.BCHCoded,Rxword);
  System.BCHError(iter)=Difference(System.BCHCoded,System.BCHDeCoded);
  System.BCHBER(iter)=System.BCHError(iter)/System.BCHLength;





  %BPSK part of simulation,
  System.Coded=System.Mesg;

  %Modulate 
  System.Modulated=bpskmod(System.Coded,System.CarrierRate,System.DataRate,sqrt(System.Eb));
  
  
  %Channel with AWGN
  System.Channel=System.Modulated + sqrt(System.N0)*randn(1,length(System.Modulated));


  %DeModulate
  System.DeModulated=bpskdemod(System.Channel,System.CarrierRate,System.DataRate,sqrt(System.Eb));

  %Channel Decode
  System.DeCoded=System.DeModulated;

  %Error Calculation
  System.Error(iter)=Difference(System.Coded,System.DeCoded);
  System.BER(iter)=System.Error(iter)/System.Length;

end

disp('System Error')
System.Error

disp('System BER')
System.BER

disp('System.BCHError')
System.BCHError

disp('System.BCHBER')
System.BCHBER

disp('System BCH Actual')
System.BCHActualErrors

disp('System BCH Corrected')
System.BCHCorrected

disp('System SNRdb')
System.SNRdb

semilogy(System.SNRdb,System.BER,";Simulated BPSK;",System.SNRdb,0.5*erfc(sqrt(10.^(System.SNRdb/10))),";Theoretical BPSK;",System.SNRdb,System.BCHBER,";Simulated BCH, [63,36];")
title "BPSK Uncoded, Vs BCH Coded systems"
save bchchannel_sim System
fgets(stdin)
fgets(stdin)

Let me know whats the problem, if there is any. --பராசக்தி 16:48, 16 September 2006 (UTC)