Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

commBCHEncoder/commBCHDecoder

857 views
Skip to first unread message

Spiros

unread,
Dec 18, 2010, 10:37:04 AM12/18/10
to
Hi to all,
This question is considered with the use of Communications
Toolbox/Blockset.

I am trying to write a m-file that uses the comm.BCHEncoder/comm.Decoder in MATLAB R2010b for the DVB-T2 (DVB-S2 are the same) standard?.

In the DVB-S.2 model in Simulink the compiler doesn't complaint for any LDPC rate and everything seems OK.
In my code,if I try to use comm.BCHEncoder with any code rate other than 1/2 again everything is OK.
When I try Kbch=32208 and Nbch=32400,
I get an error:The values for N and K do not produce a valid narrow-sense BCH code.

%-----------------BCH encoding.... --------------------------------------
%
% Constrution of BCH_Encoder and BCH_Decoder
N_BCH=32400;
K_BCH=32208;
BBFrame=round(rand(32208,1));
BCH_Encoder=comm.BCHEncoder('CodewordLength',N_BCH,'MessageLength',K_BCH,'GeneratorPolynomial',g);
BCH_Decoder=comm.BCHDecoder('CodewordLength',N_BCH,'MessageLength',K_BCH,'GeneratorPolynomial',g);

BCHFrame=step(BCH_Encoder
Where BBframe is a random 32400 binary vector, and g the generator polynomial exactly the same as in the Simulink model DVB.S2 (can be found under "dvb stuct".
P.S. I also tried to use the PrimitivePolynomial with no success.

Hope for help
kindly regards Spiros

Ethem

unread,
Dec 20, 2010, 11:07:20 AM12/20/10
to
Hi Spiros,
You also need to set the appropriate primitive polynomial. Please have a look at the function called "getParamsDVBS2Demo" that comes with the DVBS2 demo. The demo uses the G^16 minimum weight primitive polynomial (e.g. primpoly(16,'min')).
Hth,
Ethem

"Spiros " <spze...@gmail.com> wrote in message <ieikf0$s16$1...@fred.mathworks.com>...

Spiros

unread,
Dec 20, 2010, 2:03:07 PM12/20/10
to
Hi Ethem
A found a solution, but the one you propose is more elegant.
Thanks a lot.
Regards Spiros

Adam

unread,
Mar 2, 2011, 7:27:07 AM3/2/11
to
"Spiros" wrote in message <ieo99b$lep$1...@fred.mathworks.com>...


Hello, Im working on DVB-T2 system and I got stuck on the same problem with BCH code as you did. Could you please tell me how you solved it ? Thanks a lot!

Spiros

unread,
Mar 4, 2011, 5:56:24 AM3/4/11
to
I've mailed you my BCH code.
HTH
regards Spiros

Bahman

unread,
Apr 12, 2011, 3:15:08 AM4/12/11
to
"Adam " <a.str...@centrum.cz> wrote in message <ikld2r$cg2$1...@fred.mathworks.com>...
Hi Spiros
I am working on DVB-S2 in matlab
i faced same problem with BCH en/decoder
would you plz tell me how i can use bch decoder for dvb-s2 normal fecframes(64800)
with different rates e.g. 1/2
regards

Bahman

unread,
Apr 12, 2011, 3:33:08 AM4/12/11
to
"Spiros" wrote in message <ikqggo$cnm$1...@fred.mathworks.com>...

> I've mailed you my BCH code.
> HTH
> regards Spiros
Dear Spiros
I faced same problem using bch enc/dec in dvb-s2 model in matlab
i wonder if you can help me ,i need to know how you solved your problem for n,k in bch enc/dec
Thanks in advance

Spiros

unread,
Apr 15, 2011, 3:35:20 PM4/15/11
to
"Bahman " <bahman...@yahoo.com> wrote in message <io0v7j$l0n$1...@fred.mathworks.com>...
See your mail.
HTH
Spiros

Akilan

unread,
May 14, 2011, 2:29:04 AM5/14/11
to
hello Spiros
could u please help me to find the solution for bch coding...
thank u
"Spiros" wrote in message <ieikf0$s16$1...@fred.mathworks.com>...

Ratty

unread,
May 22, 2011, 3:31:04 PM5/22/11
to
"Spiros" wrote in message <ikqggo$cnm$1...@fred.mathworks.com>...
> I've mailed you my BCH code.
> HTH
> regards Spiros

Good time of day!

Can you provide to me also this information?

Thanks a lot

V.B.

allice

unread,
Jun 2, 2011, 4:29:06 AM6/2/11
to
Dear Spiros
i also work on dvbs2 bch encoding and decoding. i am confused about constrution of bch enc and dec in matlab in normal length ie , N_BCH=32400 and K_BCH=32208. could you please mail you code to me?
thank you and with my best regards
Allice

Leonardo O. Iheme

unread,
Jun 28, 2011, 9:21:04 AM6/28/11
to
"Spiros" wrote in message <ieikf0$s16$1...@fred.mathworks.com>...

Hello Spiros,

I am faced with the same problem could you please help me out.
Your help will be appreciated.
Thanks a lot

Leonardo O. Iheme

unread,
Jul 4, 2011, 1:50:12 AM7/4/11
to
"Leonardo O. Iheme" <obina...@yahoo.com> wrote in message <iuckg0$7o3$1...@newscl01ah.mathworks.com>...

Figured it out myself and solved it. Thanks

Brian

unread,
Dec 7, 2011, 4:05:09 PM12/7/11
to
I hope you are still using this Forum. Is there anyway you can send me the code as well. I am having the same problem

Thanks!
Brian

Brian

unread,
Dec 7, 2011, 4:39:08 PM12/7/11
to
I am getting an error:

Error in ==> testing at 1
hEnc = comm.BCHEncoder;

??? Undefined function or variable 'comm'.

any idea how to fix this?

Thanks!

Fulus

unread,
Jun 23, 2012, 5:49:09 PM6/23/12
to
"Spiros" wrote in message <ieo99b$lep$1...@fred.mathworks.com>...
hello please i'm facing same problems here. could u help me out. fulu...@yahoo.com

Fulus

unread,
Jun 23, 2012, 7:42:07 PM6/23/12
to
hi,

plus i keep getting this error telling me my codeword length cant exceed 255...

??? Error using ==> fec.bchbase.setN at 20
N must equal 2^m-1 for some integer m between 3 and 8.

How can I achieve larger block lengths up to dvbs2 standards

"Fulus " <cas...@gmail.com> wrote in message <js5dkl$kim$1...@newscl01ah.mathworks.com>...

Bahman

unread,
Jun 24, 2012, 5:27:07 AM6/24/12
to
"Fulus " <cas...@gmail.com> wrote in message <js5k8f$gem$1...@newscl01ah.mathworks.com>...
Dear Fulus

You need to make such intialization

You need to define parameters for each modcod according to etsi standard

%-----DVB-S2---INITIALIZATION.......an example

EncoderBCH = comm.BCHEncoder;
EncoderBCH.CodewordLength=N_BCH;
EncoderBCH.MessageLength=K_BCH;
EncoderBCH.PrimitivePolynomialSource='Property';
EncoderBCH.PrimitivePolynomial=de2bi(65581,'left-msb');
EncoderBCH.GeneratorPolynomialSource='Property';
EncoderBCH.GeneratorPolynomial=genBCH;
EncoderBCH.CheckGeneratorPolynomial= false;
henc = fec.ldpcenc(H);
hdec = fec.ldpcdec(H);
hdec.DecisionType = 'Hard decision';
hdec.OutputFormat = 'Information part';
hdec.NumIterations = 50;

hdec.DoParityChecks = 'Yes';

DecoderBCH = comm.BCHDecoder;
DecoderBCH.CodewordLength=N_BCH;
DecoderBCH.MessageLength=K_BCH;
DecoderBCH.PrimitivePolynomialSource='Property';
DecoderBCH.PrimitivePolynomial=de2bi(65581,'left-msb');
DecoderBCH.GeneratorPolynomialSource='Property';
DecoderBCH.GeneratorPolynomial=genBCH;
DecoderBCH.CheckGeneratorPolynomial= false;
Bahman

Fulus

unread,
Jun 25, 2012, 8:09:07 PM6/25/12
to
Hello,

Thank you so much Bahman for your kind assistance. I am still getting an error message telling me my codeword length cant exceed 255. I think I am still doing something wrongly. Any help please. Thanks

Fulus

unread,
Jul 2, 2012, 8:41:07 PM7/2/12
to
"Spiros" wrote in message <ieo99b$lep$1...@fred.mathworks.com>...
Hello,

I really need immediate assistance on BCH encoding and decoding for dvbs2. I have encountered similar problems as you did. could you kindly assist me here. thanks

Fulus

Bahman

unread,
Jul 3, 2012, 2:24:07 AM7/3/12
to
"Fulus " <cas...@gmail.com> wrote in message <jstf33$fjh$1...@newscl01ah.mathworks.com>...
%Dear fulus this is an example for QPSK 8/9 try it

genBCH_t8 =[1 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 ...
0 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 0 1 0 0 1 0 0 ...
1 1 1 1 0 0 1 0 1 1 1 1 0 1 1 1 1 0 1 0 0 0 1 ...
1 0 0 1 1 1 1 1 1 1 0 0 0 1 1 0 1 1 0 1 0 1 1 ...
1 0 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 1 0 0 1 0 1 ...
1 0 0 1 1 0 0 0 1 0 1 0 1 1];



H = dvbs2ldpc(8/9);
K_BCH=57472;
N_BCH=57600;

genBCH=genBCH_t8;
EncoderBCH = comm.BCHEncoder;
EncoderBCH.CodewordLength=N_BCH;
EncoderBCH.MessageLength=K_BCH;
EncoderBCH.PrimitivePolynomialSource='Property';
EncoderBCH.PrimitivePolynomial=de2bi(65581,'left-msb');
EncoderBCH.GeneratorPolynomialSource='Property';
EncoderBCH.GeneratorPolynomial=genBCH;
EncoderBCH.CheckGeneratorPolynomial= false;
henc = fec.ldpcenc(H);
hdec = fec.ldpcdec(H);
hdec.DecisionType = 'Hard decision';
hdec.OutputFormat = 'Information part';
hdec.NumIterations = 50;

hdec.DoParityChecks = 'Yes';

DecoderBCH = comm.BCHDecoder;
DecoderBCH.CodewordLength=N_BCH;
DecoderBCH.MessageLength=K_BCH;
DecoderBCH.PrimitivePolynomialSource='Property';
DecoderBCH.PrimitivePolynomial=de2bi(65581,'left-msb');
DecoderBCH.GeneratorPolynomialSource='Property';
DecoderBCH.GeneratorPolynomial=genBCH;
DecoderBCH.CheckGeneratorPolynomial= false;
bahman

Fulus

unread,
Jul 15, 2012, 9:26:27 PM7/15/12
to
Hello,

Thank you so much for the initialization you sent me, I have a better understanding now, the BCH is encoding well now. However, the LDPC is a bit of a problem. after the bchecoding the ldpc encoder returns that; ''Input must be a column vector of length K''. I then reshapes the output bchfec - xsym=reshape( bchfec,length( bchfec)/k,k);

making it frame based column vectors of lenght N_BCH as input to the ldpc encoder. this now returns a diff error which I do not understand

Error using LDPCEncoder/step
Multichannel operation is not supported.

Error in DVBS2_a (line 54)
FECFrame=step(hEnc,xsym);

I am looking into any method to "Split Multichannel Frame-Based Signals into Individual Signals". I have had little or no success on it. I kindly would love ur input on how to go about this.

Thank you

Bahman

unread,
Jul 16, 2012, 2:04:07 AM7/16/12
to
"Fulus " <cas...@gmail.com> wrote in message <jtvqk3$pdo$1...@newscl01ah.mathworks.com>...
Hi dear Fulus

There is no need to reshape only invert the out put of bch encoder
Suppose that the output of bch is this:
encodedData = step(EncoderBCH, data);
then you invert it
encodedData=encodedData';
then
codeword = encode(henc, encodedData);
codeword will be your LDPC FECFRAME

Bahman

Fulus

unread,
Jul 16, 2012, 4:54:08 PM7/16/12
to
Hello

I have inverted the bch output just as you suggested but still the same "multichannel operation is not supported" error. here is a bit of my code so you might take a look
thank you.

hStr=RandStream('mt19937ar','seed',654321);
BBFrame=randi(hStr,[0,1],32208*k,1);
BCHFEC=step(EncoderBCH,BBFrame);
BCHFEC=BCHFEC';
FECFrame=step(hEnc,BCHFEC);
hInt = comm.BlockInterleaver(permVec);
IntData = step(hInt, FECFrame);
hMod = comm.PSKModulator(M, 'PhaseOffset',pi/16);
Msg_tx = step(hMod, IntData);
Msg_tx = rectpulse(Msg_tx,NSAMP);
EbNo=5;
snr=EbNo+10*log10(H)-10*log10(Nsamp);
hAWGN = comm.AWGNChannel('NoiseMethod', ...
'Signal to noise ratio (SNR)','SNR',snr);
noisy_msg = step(hAWGN, Msg_tx);
noisy_msg = intdump(noisy_msg, Nsamp);
hDemod = comm.PSKDemodulator(M, 'PhaseOffset',pi/16);
Msg_rx = step(hDemod, noisy_msg);
hDeInt = comm.BlockDeinterleaver(permVec);
FECFrame_rx = step(hDeInt, Msg_rx);
BCH_rx = step(hdec, FECFrame_rx);
BCH_rx =BCH_rx ';
BBFrame_rx = step(DecoderBCH, BCH_rx);

Bahman

unread,
Jul 17, 2012, 6:12:14 AM7/17/12
to
"Fulus " <cas...@gmail.com> wrote in message <ju1v1g$e24$1...@newscl01ah.mathworks.com>...
Hi dear

First of all you need to send BBFrame of 64800 bits at once like this

data = randi([0 1], K_BCH, 1);
BCHFEC=step(EncoderBCH,data);

second: there is no interleaving for QPSK at all
third:I prefer to do interleaving by making the element vector myself like this:

%----ELEMENTS FOR 8PSK (excluding rate 3/5 which is different)
l=1;
for i=1:21600


Interleave_8psk_b(l,1)=i;

Interleave_8psk_b(l+1,1)=i+21600;

Interleave_8psk_b(l+2,1)=i+43200;
l=l+3;
forth:I prefer to use AWGN instead of comm.awgn
fifth: as long as you may send single BBFrames I'm afraid there is no need for sampeling.(intdump and rectpulse)

Bahman

Fulus

unread,
Aug 14, 2012, 1:39:07 PM8/14/12
to
Hello Bahman

I observed that its when i use "hEnc = comm.LDPCEncoder(H); and
hDec = comm.LDPCDecoder(H);" that the decoder introduces errors. I used this because I got an error message which I could not understand while using the following you recommended:

henc = fec.ldpcenc(H);
hdec = fec.ldpcdec(H);
hdec.DecisionType = 'Hard decision';
hdec.OutputFormat = 'Information part';
hdec.NumIterations = 50;

here is the error message I got, which I have since been unable to resolve:

Error using tf (line 293)
The values of the "num" and "den" properties must be row vectors or cell arrays of row
vectors, where each vector is nonempty and containing numeric data. Type "help tf.num" or
"help tf.den" for more information.

Error in step (line 97)
sys = tf(a,b);

Error in wild (line 42)
BCHFEC=step(henc,BBframe);

Bahman

unread,
Aug 14, 2012, 10:49:08 PM8/14/12
to
"Fulus " <cas...@gmail.com> wrote in message <k0e2fr$p69$1...@newscl01ah.mathworks.com>...
Hi dear

is your bbframe a row vector?
because error indicates that it is a column vector,try it inverted (BBframe')

Fulus

unread,
Aug 15, 2012, 7:53:08 AM8/15/12
to
> Hi dear
>
> is your bbframe a row vector?
> because error indicates that it is a column vector,try it inverted (BBframe')

Hello,

yeah you right, I nverted it and it runs without errors now however, it still isnt function as it suppose to because as I go higher in Eb/No my BER isnt going lower but is actually increasing by a tiny amount. That is the Decoder is still introducing errors.

Bahman

unread,
Aug 16, 2012, 12:19:10 AM8/16/12
to
"Fulus " <cas...@gmail.com> wrote in message <k0g2j4$ar5$1...@newscl01ah.mathworks.com>...
Hi dear
you need to be careful about the noise you are introducing to awgn as well as noise variance you need to set in demodulator

Ed MrTz

unread,
Aug 22, 2012, 6:24:08 AM8/22/12
to
"Bahman " <bahman...@yahoo.com> wrote in message <k0hsbu$1kd$1...@newscl01ah.mathworks.com>...
Hi Everyone!

I hope that someone could help me, even.

I had the sames problems with BCH and LDPC Enc/Dec to make it run......but at the end I can solved.

Now, my problem is that when I use (without add a AWGN channel and modulation) encoder and decoder of BCH (in raw)......its returns 0 errors between the original msg and received/decoded msg. But its not so when I use LDPC (in raw) because I get to many errors (original msg - decoded msg).

Do you know why? I attach the code that I use:
H=dvbs2ldpc(1/4);
enc = fec.ldpcenc(H);

dec = fec.ldpcdec(H);
dec.DecisionType = 'Hard decision';
dec.OutputFormat = 'Information part';
dec.NumIterations = 50;

msg = randi([0 1],1,enc.NumInfoBits);
codeword = encode(enc,msg);

decodedmsg = decode(dec, codeword);

% Compare with original message
disp(['Number of bits incorrectly decoded = ' ...
num2str(nnz(decodedmsg-msg))]);

THANXXXX

Bahman

unread,
Aug 22, 2012, 8:06:09 AM8/22/12
to
"Ed MrTz" wrote in message <k12c08$sbt$1...@newscl01ah.mathworks.com>...
DEAR WHERE IS YOUR TRANSMISSION CHANNEL??????
BAHMAN

Ethem Sozer

unread,
Aug 22, 2012, 9:27:45 AM8/22/12
to
The input of decode method should be a bipolar soft signal where a 0 is
represented by a real number greater than zero, and a 1 is represented by a
real number less than 0. If you try:

>> decodedmsg = decode(dec, 1-2*codeword);

You should see zero errors. A more realistic simulation would be

rcvd = awgn(1-2*codeword, SNR); % chose an SNR value
decodedmsg = decode(dec, rcvd);

Hth,
Ethem


"Bahman " <bahman...@yahoo.com> wrote in message
news:k12hvh$ihk$1...@newscl01ah.mathworks.com...

Ed MrTz

unread,
Aug 25, 2012, 5:18:07 AM8/25/12
to
Thanks so much, Ethem Sozer!!!!

It has been really useful!!!! Now, I can continue with the other blocks!

Thanks also to Bahman for the interest. I told that I was trying without channel block (awgn) and modulation.

Regards


Ethem Sozer" <eso...@mathworks.com> wrote in message <k12mok$784$1...@newscl01ah.mathworks.com>...

Ed MrTz

unread,
Dec 29, 2012, 11:18:11 AM12/29/12
to
Hi again!

After a while, I came back programming this code and with the "patch" told me before "decodedmsg = decode(dec, 1-2*codeword);" ran OKS but when I try to get BER curve of LDPC on AWGN channel and QPSK mod, comparing with QPSK no coded reference curve...... the LDPC curve appears over the theorical QPSK curve, instead of plot below.

Anybody knows why?

Extra: I use dvds2ldpc to generate the H matrix and fec.ldpcenc/dec to code.

Thanks for all,

Edgar

"Ethem Sozer" <eso...@mathworks.com> wrote in message <k12mok$784$1...@newscl01ah.mathworks.com>...

ibrahem...@gmail.com

unread,
Apr 19, 2014, 3:48:00 PM4/19/14
to
Hello spiros,
May u gvie me ur email bcuz i wanna chat u for important thing.
best ragard

sofiasa...@gmail.com

unread,
Oct 13, 2014, 2:17:29 AM10/13/14
to
On Saturday, December 18, 2010 7:37:04 AM UTC-8, Spiros wrote:
> Hi to all,
> This question is considered with the use of Communications
> Toolbox/Blockset.
>
> I am trying to write a m-file that uses the comm.BCHEncoder/comm.Decoder in MATLAB R2010b for the DVB-T2 (DVB-S2 are the same) standard?.
>
> In the DVB-S.2 model in Simulink the compiler doesn't complaint for any LDPC rate and everything seems OK.
> In my code,if I try to use comm.BCHEncoder with any code rate other than 1/2 again everything is OK.
> When I try Kbch=32208 and Nbch=32400,
> I get an error:The values for N and K do not produce a valid narrow-sense BCH code.
>
> %-----------------BCH encoding.... --------------------------------------
> %
> % Constrution of BCH_Encoder and BCH_Decoder
> N_BCH=32400;
> K_BCH=32208;
> BBFrame=round(rand(32208,1));
> BCH_Encoder=comm.BCHEncoder('CodewordLength',N_BCH,'MessageLength',K_BCH,'GeneratorPolynomial',g);
> BCH_Decoder=comm.BCHDecoder('CodewordLength',N_BCH,'MessageLength',K_BCH,'GeneratorPolynomial',g);
>
> BCHFrame=step(BCH_Encoder
> Where BBframe is a random 32400 binary vector, and g the generator polynomial exactly the same as in the Simulink model DVB.S2 (can be found under "dvb stuct".
> P.S. I also tried to use the PrimitivePolynomial with no success.
>
> Hope for help
> kindly regards Spiros

hi ,
can anyone reply me with matlab coding for BCh decoder!!!!!!!!!!!!!!!in emergency

Yoga Julio

unread,
Mar 24, 2015, 4:08:48 AM3/24/15
to
"Adam " <a.str...@centrum.cz> wrote in message <ikld2r$cg2$1...@fred.mathworks.com>...
> "Spiros" wrote in message <ieo99b$lep$1...@fred.mathworks.com>...
> > Hi Ethem
> > A found a solution, but the one you propose is more elegant.
> > Thanks a lot.
> > Regards Spiros
>
>
> Hello, Im working on DVB-T2 system and I got stuck on the same problem with BCH code as you did. Could you please tell me how you solved it ? Thanks a lot!

same with me , Im working on DVB-T2 system and Igot stuck on the same problem with BCH as you did . Could you tell me how to solve it? Thanks a lot !

burak unal

unread,
Oct 28, 2016, 5:11:08 PM10/28/16
to
Hi to all,
I am trying to write a BCHEncoder for DVB-S2 standard but i am gettin this error,can somebody help me please how to fix it,thanks

Error in BCHEncoder (line 9)
[BCH_Poly,NumParityBits,~]=BCHGenerator(code_Rate);

Output argument "enc_data" (and maybe others) not assigned during call to
"C:\Users\GIGABYTE\Documents\MATLAB\Greek\Greek\BCHEncoder.m>BCHEncoder".
********************************************************************************************
function [ BCH_Poly, NumBCHParityBits, TErr ] = BCHGenerator( code_Rate )
%BCHGenerator. This function generates the BCH polynomials for for the
%NON-PRIMITIVE BCH codes used in DVB-S2
% According to the chosen code_Rate the function determines the
% correction ability of the code thus the polynomial. It also returns the
% number of parity bits.
%INPUT: 1. code_Rate
%OUTPUT: 1. BCH_Poly n-k+1 coefficients
% 2. NumBCHPatiryBits = n-k
switch code_Rate
case {1/4,1/3, 2/5, 1/2, 3/5, 3/4, 4/5}
TErr = 12;
case {2/3, 5/6}
TErr = 10;
case{8/9,9/10}
TErr = 8;
end
NumBCHParityBits = 16 * TErr;

% Define BCH polynomials (Table 6a & 6b)
% Non-zero powers (besides 0 and 16)
nzp = {[2 3 5] ... g1
[1 4 5 6 8] ... g2
[2 3 4 5 7 8 9 10 11] ... g3
[2 4 6 9 11 12 14] ... g4
[1 2 3 5 8 9 10 11 12] ... g5
[2 4 5 7 8 9 10 12 13 14 15] ... g6
[2 5 6 8 9 10 11 13 15] ... g7
[1 2 5 6 8 9 12 13 14] ... g8
[5 7 9 10 11] ... g9
[1 2 5 7 8 10 12 13 14] ... g10
[2 3 5 9 11 12 13] ... g11
[1 5 6 7 9 11 12]}; ... g12
g = zeros([12 16+1]);
for n = 1:12
g(n,[1 nzp{n}+1 end]) = 1;
end
% Compute the generator polynomial by multiplying the first TErr BCH
%polynomials
% Polynomial multiplication is a convolution
Poly = gf(g(1,:),1);
for n = 2:TErr
Poly = conv(Poly, gf(g(n,:),1));
end
BCH_Poly = fliplr(logical(Poly.x));
% Check if the degree of the generator polynomial is equal with the
%number of parity bits
%assert(length(BCH_GEN)-1 == NumBCHParityBits);
end

burak unal

unread,
Oct 28, 2016, 5:24:07 PM10/28/16
to
this is bch encoder


*************************************************************************************************
function [ enc_data ] = BCHEncoder( data, code_Rate )
%BCH Encoder for DVB-S2
% This Function Inmplements BCH encoding of data according to the
% selected code_Rate. Needs BCHGenerator function.
% INPUTS: 1. Binary data in vector form. Attention: data =num_blks*k_bch
% 2. the code_Rate
% OUTPUT: 1. encoded data. Each column is a different blk.
% see BCHGenerator function for more details
[BCH_Poly,NumParityBits,~]=BCHGenerator(code_Rate);
K_BCH=(64800*code_Rate)-NumParityBits;%BCH uncoded data blk
Num_blks=length(data)/K_BCH;%number of blks
data = reshape (data, [K_BCH Num_blks]);
%Encoder in MATLAB
ParityBits=zeros(Num_blks, NumParityBits)';
for i=1:Num_blks%for each BCH block(each column is a different blk
reg = zeros(1,NumParityBits)';
for j=1:K_BCH%for each BCH data bit
d= xor( data(j, i), reg(NumParityBits));
%update shift register
for k=NumParityBits:-1:2
a = and( d , BCH_Poly(NumParityBits-k+2));
reg(k)= xor( reg(k-1), a );
end
reg(1)=d;
end
%the remainder is the reverse of the bit register
for z = 1 : NumParityBits
ParityBits(z,i)=reg(NumParityBits-z+1);
end
end
0 new messages