Hi,
I have some problems with "bch code"; results I am obtaining are not coherent, and I would like to know why...
I will try eto explain my problem:
1.- I run next code in Matlab:
//**MATLAB**
x=[1 0 1 0];
x_gf=gf(x);
x_bch=bchenc(x_gf,7,4);
%The result I obtain fos x_bch is: 1 0 1 0 0 1 1, where 0 1 1 is bch code inside
//******
2.-Now, I try to do teh same using it++ library
//**it++**
BCH bch(7, 4, 1, "1 3",true);
//Note: "1 3" is the octal representation of the generator polynomial obtained with Matlab's
//'bchgenpoly(7,4)' function for n=7,k=4 bch narrow-sense code: x³+x+1
bvec input = "1 0 1 0";
bvec encoded = bch.encode(input);
bvec decoded = bch.decode(encoded);
cout << "input = " << input << endl ;
cout << "encoded = " << encoded << endl ;
cout << "decoded = " << decoded << endl ;
//In this case, the results are like:
//input = [1 0 1 0]
//encoded = [1 0 1 0 0 0 1], so bch code inside is 0 0 1 in this case
//decoded = [1 0 1 0]
//******
Why do I obtain different results from Matlab and from IT++?? the problem is that I searching for a bch(127,113,2) C/C++ implementation to use in a DVB-T modulator, It++ looks fine for my purpose, but results are not coherent with Matlab's results. Furthermore, Matlab's results are coherent with values read from real DVB-T signals. And I do not know where is the problem...
Thanks a lo for your patient and help. I hope any response from you.
Regards,
/Mikel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am back with a real answer. The difference is do to a different mapping of the bits to polynomial representation:
1) MATLAB maps highest order first: 1010 <-> i(x)=1x^3 + 0x^2 + 1x^1 + 0x^0 = x^3 + x, which I would intuitively prefer.
2) IT++ maps lowest order first: 1010 <-> i(x)= 1x^0 + 0x^1 + 1x^2 + 0x^3 = x^2 + 1
Both methods use the first method of encoding, mentioned in my previous post: i(x)x^(n-k) / g(x) = y(x), remainder(x), where the generator polynomial seem to be the same g(x) = x^3+x+1 and the codeword is i(x)x^(n-k) - remainder(x). In the IT++ method remainder(x) is again mapped lowest order first into bits, consistently.
Both mappings encode into valid code words of the same code (but of different mapping - recall code is the set of all codewords, the mapping is an encoder property) and the error correcting works on both codewords the same, i.e. it is independent from the mapping. For the de-mapping you have to use the corresponding (reverse) mapping, which both methods do. Thus, both methods (IT++ and MATLAB) obtain the full coding gain of this BCH-Code.
As I think that we should be consistent with MATLAB and DVB-T (and other) standard, we should switch to the highest order first mapping (method 1). As far as I know, this is just a reversing of the indizes of two for-loop when encoding, and again two times for decoding. I could provide a patch.
@ediap: Do you see any problems coming up with that? Since this is not really a bug (call it a feature), should I open a bug report or feature request?
Cheers,
Stephan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> @ediap: Do you see any problems coming up with that? Since this is not really a bug (call it a feature), should I open a bug report or feature request?
I also agree that we should unify this BCH code to match Matlab and DVB-T behaviour. Otherwise we will see endless discussions and questions why it does not work.
This is in fact not a bug, but a feature request, so it has to be applied to the development branch only (trunk). We can not break the current behaviour of stable releases. Please open a new Feature Request and attach the patch to it with a short ChangeLog compatible description.
Thanks!
/Adam
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
the observed difference is due to the encoding process: There exist (up to my knowledge) two ways of encoding systematically.
IT++ uses: copy over message bits m(x) to first part of code word c(x), calculate mod(x^(n-k)*m(x), g(x)) and append this to the message bit in the codeword. (Cp. p107 of Wicker: error control systems)
Both encoded vectors are element of the same code (i.e. set of codewords), but not of the same encoder.
I will have a closer look at the problem and come back later.
Regards,
Stephan
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I have some problems with "bch code"; results I am obtaining are not coherent, and I would like to know why...
I will try eto explain my problem:
1.- I run next code in Matlab:
//**MATLAB**
x=[1 0 1 0];
x_gf=gf(x);
x_bch=bchenc(x_gf,7,4);
%The result I obtain fos x_bch is: 1 0 1 0 0 1 1, where 0 1 1 is bch code inside
//******
2.-Now, I try to do teh same using it++ library
//**it++**
BCH bch(7, 4, 1, "1 3",true);
//Note: "1 3" is the octal representation of the generator polynomial obtained with Matlab's
//'bchgenpoly(7,4)' function for n=7,k=4 bch narrow-sense code: x³+x+1
bvec input = "1 0 1 0";
bvec encoded = bch.encode(input);
bvec decoded = bch.decode(encoded);
cout << "input = " << input << endl ;
cout << "encoded = " << encoded << endl ;
cout << "decoded = " << decoded << endl ;
//In this case, the results are like:
//input = [1 0 1 0]
//encoded = [1 0 1 0 0 0 1], so bch code inside is 0 0 1 in this case
//decoded = [1 0 1 0]
//******
Why do I obtain different results from Matlab and from IT++?? the problem is that I searching for a bch(127,113,2) C/C++ implementation to use in a DVB-T modulator, It++ looks fine for my purpose, but results are not coherent with Matlab's results. Furthermore, Matlab's results are coherent with values read from real DVB-T signals. And I do not know where is the problem...
Thanks a lo for your patient and help. I hope any response from you.
Regards,
/Mikel
Hi Mikel,
I am back with a real answer. The difference is do to a different mapping of the bits to polynomial representation:
1) MATLAB maps highest order first: 1010 <-> i(x)=1x^3 + 0x^2 + 1x^1 + 0x^0 = x^3 + x, which I would intuitively prefer.
2) IT++ maps lowest order first: 1010 <-> i(x)= 1x^0 + 0x^1 + 1x^2 + 0x^3 = x^2 + 1
Both methods use the first method of encoding, mentioned in my previous post: i(x)x^(n-k) / g(x) = y(x), remainder(x), where the generator polynomial seem to be the same g(x) = x^3+x+1 and the codeword is i(x)x^(n-k) - remainder(x). In the IT++ method remainder(x) is again mapped lowest order first into bits, consistently.
Both mappings encode into valid code words of the same code (but of different mapping - recall code is the set of all codewords, the mapping is an encoder property) and the error correcting works on both codewords the same, i.e. it is independent from the mapping. For the de-mapping you have to use the corresponding (reverse) mapping, which both methods do. Thus, both methods (IT++ and MATLAB) obtain the full coding gain of this BCH-Code.
As I think that we should be consistent with MATLAB and DVB-T (and other) standard, we should switch to the highest order first mapping (method 1). As far as I know, this is just a reversing of the indizes of two for-loop when encoding, and again two times for decoding. I could provide a patch.
@ediap: Do you see any problems coming up with that? Since this is not really a bug (call it a feature), should I open a bug report or feature request?
Cheers,
Stephan
Stephan,
> @ediap: Do you see any problems coming up with that? Since this is not really a bug (call it a feature), should I open a bug report or feature request?
I also agree that we should unify this BCH code to match Matlab and DVB-T behaviour. Otherwise we will see endless discussions and questions why it does not work.
This is in fact not a bug, but a feature request, so it has to be applied to the development branch only (trunk). We can not break the current behaviour of stable releases. Please open a new Feature Request and attach the patch to it with a short ChangeLog compatible description.
Thanks!
/Adam
Hi Mikel,
the observed difference is due to the encoding process: There exist (up to my knowledge) two ways of encoding systematically.
IT++ uses: copy over message bits m(x) to first part of code word c(x), calculate mod(x^(n-k)*m(x), g(x)) and append this to the message bit in the codeword. (Cp. p107 of Wicker: error control systems)
Both encoded vectors are element of the same code (i.e. set of codewords), but not of the same encoder.
I will have a closer look at the problem and come back later.
Regards,
Stephan