2

I'm trying to implement a BCH 18,6 decoder for QR Code version verification, and am having a hard time with syndrome calculation. My understanding is that the syndromes should be 0 when the codeword has no errors, but that's not what I'm getting.

The generator polynomial used to encode the version is, per the QR Code spec ISO/IEC 18004:2000(E) (Annex D) is:

$G(x) = x^{12} + x^{11} + x^{10} + x^9 + x^8 + x^5 + x^2 + 1$

The example used in that annex is:

  • Data (version): 000111
  • Error correction: 110010010100
  • Codeword: 000111110010010100

Which gives me

$R(x) = x^{14}+x^{13}+x^{12}+x^{11}+x^{10}+x^7+x^4+x^2$

The spec says to calculate syndrome $S_i$ (for i=1,3,5) by evaluating $R(\alpha^i)$. So i'm trying $S_1$, which gives me:

$S_1 = \alpha^{14}+\alpha^{13}+\alpha^{12}+\alpha^{11}+\alpha^{10}+\alpha^7+\alpha^4+\alpha^2$

I then simplify the terms $\alpha_i$ (for $i>4$) by replacing them with their $GF(2^5)$ equivalents. The spec didn't tell me which $P(x)$ to use, so I picked $P(x)=x^5+x^2+1$ from here. Later I tried all the irreducible degree 5 polynomials from this answer, with no better luck. I suspect that's supposed to be unsurprising, but I'm not sure why. Anyway, back to using $P(x)=x^5+x^2+1$.

To get the in-$GF(2^5)$ values, I started with $\alpha^4=10000$. To calculate $\alpha^5$, left shift 1, then because MSB is 1, XOR with $100101$, get $\alpha^5 = 00101$, and so on for $\alpha^i$ for every i through 14. Thus $\alpha^{14}=11101$, so $\alpha^{14}=\alpha^4+\alpha^3+\alpha^2+1$. Apply that to all terms, and we get:

$S_1 = (\alpha^4+\alpha^3+\alpha^2+1) + (\alpha^4+\alpha^3+\alpha^2) + (\alpha^3+\alpha^2+\alpha) + (\alpha^2+\alpha+1) + (\alpha^4+1) + (\alpha^4+\alpha^2) + \alpha^4 + \alpha^2$

which is:

$S_1 = \alpha^4+\alpha^3+1$

which isn't zero. What am I doing wrong? This same algorithm works for BCH(15,5), which makes me think there's some subtlety of BCH(18,6) or $GF(2^5)$ that I'm missing.

simmonmt
  • 23
  • 3
  • Because the bit level description of a shortened BCH-code is anything but unique, it is impossible to help you unless you give the details of this particular code. A) which primitive element of (presumably) $GF(2^5)$ is used? B) How is this code shortened? Using a generator polynomial (coming from part A) is a most natural way, but not the only possibility. – Jyrki Lahtonen Nov 27 '19 at 04:54
  • Hold on, I thought that $6$ is the minimum distance, but it looks like it is the rank, and there are 12 check bits. Sorry about a trivial booboo like that. Anyway, something does not add up, because neither $12$ nor $11$ is a multiple of $5$. Are you sure this is defined over $GF(2^5)$? Even with a $(15,5)$ code with ten check bits, your verification should involve evaluating the polynomials at two points. – Jyrki Lahtonen Nov 27 '19 at 04:59
  • @JyrkiLahtonen I added the primitive element and the generator polynomial. The spec specifically says find the syndrome by evaluating $R(\alpha^i)$ for i=1,3,5 where $\alpha$ is a primitive element of $GF(2^5)$. – simmonmt Nov 27 '19 at 15:44
  • Thanks for the edits. There is something wrong with the generator polynomial $G(x)$. It is the product of $(x+1)$ and an irreducible polynomial of degree $11$. If it were a generator of a BCH-code defined over $GF(2^5)$ it would have to be a product of $(x+1)$ and two or more irreducible quintics (=the minimal polynomials of $\alpha$, $\alpha^3$, etc). – Jyrki Lahtonen Nov 27 '19 at 17:03
  • In other words, with that generator polynomial the relevant field is $GF(2^{11})$, not $GF(2^5)$. – Jyrki Lahtonen Nov 28 '19 at 10:57
  • @JyrkiLahtonen tried it with $GF(2^{11})$ just for fun with $x^{11}+x^2+1$, but $S_1$ was non-zero. I found your https://math.stackexchange.com/a/2234211/729002 so I'm trying to see which generator would work. Everything in those answers (particularly the second one) seems to assume a 31-bit length. I don't know what if anything needs to change for my 18-bit length – simmonmt Nov 28 '19 at 16:43
  • Hmm $\alpha$ needs to be a zero of the generating polynomial of the code. And a factor of degree $11$ to some extent means that the code is designed to be used for lengths close to $2^{11}-1=2047$. Or at least for a length in that ball park. To me this suggests that there is an error in $G(x)$. You see, with a single irreducible factor you only get minimum distance three (= ability to correct a single error). With two factors (roots $\alpha$ and $\alpha^3$) you get minimum distance five. That's how you get a double error correcting $(15,5)$ code. – Jyrki Lahtonen Nov 28 '19 at 18:37
  • Actually, a double error correcting BCH-code of a maximal length is a $(31,21)$-code. By shortening that code heavily, you can get an $(18,8)$ code and a $(15,5)$ code. Both sharing the same generator polynomial! The former would make some sense. Not sure about the latter, for there is also a double error correcting $(15,7)$-code. Then again, there may be other reasons to prefer slightly worse codes such as $(15,5)$, if it means that the decoder only needs to support a single finite field. – Jyrki Lahtonen Nov 28 '19 at 18:44
  • Also, with $GF(2^4)$ you get a triple error correcting $(15,5)$ code as opposed to the double error correcting $(15,5)$-code you get with $GF(2^5)$. – Jyrki Lahtonen Nov 28 '19 at 18:46
  • I would need to study the specs to be able to help. Is that posted somewhere on-line? – Jyrki Lahtonen Nov 28 '19 at 18:48
  • @JyrkiLahtonen this may have been a complete waste of time. A separate source https://www.thonky.com/qr-code-tutorial/format-version-information says it's a Golay code. Which is incredibly annoying. Someone even wrote a section in the 2000 spec saying how to decode it as "BCH (18,6)" (which I guess doesn't exist?) and I guess didn't verify that it worked? I'm new at Stack Exchange; what's the best way to resolve question since the whole premise is wrong? – simmonmt Nov 28 '19 at 19:44
  • Hallelujah! I thought that generator polynomial looked familiar! Yes, it's a Golay code (shortened five times). Annex D2 is rubbish. Can you write your own verification procedure? Basically a string of bits is a valid codeword if and only if it is divisible by $G(x)$. Annex D1 has a list of the interpretations. IIRC not all 64 codewords are currently in use. – Jyrki Lahtonen Nov 28 '19 at 20:05
  • I don't know what's best. May be leave this here? Conceivably somebody else may run into the same source. I'm afraid you may not be able to sue anyone for lost time and productivity :-) – Jyrki Lahtonen Nov 28 '19 at 20:08
  • Thanks for all your help. I'll probably just implement the one zxing uses - walk the list of values in the table and use the closest one. Which is unfortunate - the bch decoding was fun to write. But at least I got to do that for the QRCode format. Thanks again. – simmonmt Nov 28 '19 at 20:12

1 Answers1

0

The OP kindly forwarded me a copy of the specs.

In Annex D.1 they, indeed, describe a code with generator polynomial $$G(x) = x^{12} + x^{11} + x^{10} + x^9 + x^8 + x^5 + x^2 + 1.$$ Mathematica kindly factored this polynomial for us as

$$ G(x)=(x+1)(x^{11}+x^9+x^7+x^6+x^5+x+1). $$

However, in Annex D.2 a standard decoding procedure for a triple error correcting BCH code defined over $GF(2^5)$ is described, starting by calculating the values of a read word (interpreted as a polynomial with coefficients in $GF(2)$) at the expected elements $\alpha$, $\alpha^3$ and $\alpha^5$.

THIS IS TOTAL NON-SENSE AND HIGHLY INCOMPETENT.

  • A BCH code with such a description has a generator polynomial that is the product of three irreducible quintic factors, namely the minimal polynomials of $\alpha$, $\alpha^3$ and $\alpha^5$. It is impossible for $G(x)$ to be such a polynomial
  • They "forgot" to specify which primitive element of $GF(2^5)$ $\alpha$ is. There are $30$ different primitive elements in that field, split into six sets of conjugates. To specify the code they would need to tell the minimal polynomial of $\alpha$.
  • This code has fifteen check bits, not twelve as the one described in annex D.1.

MY INTERPRETATION

  • Whoever wrote Annex D.2 did not read Annex D.1. (or vice versa).
  • One of those two pieces was copy/pasted from somewhere else, by someone who is not qualified.
  • May be a version conflict, or work in progress, or not from an official source?
  • The meetings producing this document did a piss-poor job checking these parts.

I'm afraid this means you are screwed. You need another source. Contact the authors (or ask your boss for help in doing that). Undoubtedly there is an umbrella organization who was responsible for specifying this. The system works, so somebody somewhere has a documentation free of errors.

For what it's worth. I'm not a random dude in the internet. At one point I served as an associate editor of coding theory for IEEE Transactions on Information Theory, the top journal in this area. A random dude is not selected to such a position. Bringing this up in case you need to refer to (or copy/paste) this post in your request for a clarification.

Jyrki Lahtonen
  • 133,153
  • The factors of $G(x)$ looked familiar, and it is a generator for the famous perfect $(23,11,7)$ binary Golay code, shortened to a $(18,6)$-code. Should have spotted it much sooner :-( – Jyrki Lahtonen Nov 28 '19 at 20:13
  • A strange alignment error in the last list of bullets. Sorry about the bump. – Jyrki Lahtonen Nov 30 '19 at 06:59