# Reed–Solomon error correction

(Redirected from Reed-Solomon)
Reed–Solomon codes
Named after Irving S. Reed and Gustave Solomon
Classification
Hierarchy Linear block code
Polynomial code
Cyclic code
BCH code
Reed–Solomon code
Block length n
Message length k
Distance nk + 1
Alphabet size q = pmn  (p prime)
Often n = q − 1.
Notation [n, k, nk + 1]q-code
Algorithms
Decoding Berlekamp–Massey
Euclidean
et al.
Properties
Maximum-distance separable code

Reed–Solomon codes are a group of error-correcting codes that were introduced by Irving S. Reed and Gustave Solomon in 1960.[1] They have many applications, the most prominent of which include consumer technologies such as CDs, DVDs, Blu-ray Discs, QR Codes, data transmission technologies such as DSL and WiMAX, broadcast systems such as DVB and ATSC, and storage systems such as RAID 6. They are also used in satellite communication.

In coding theory, the Reed–Solomon code belongs to the class of non-binary cyclic error-correcting codes. The Reed–Solomon code is based on univariate polynomials over finite fields.

It is able to detect and correct multiple symbol errors. By adding t check symbols to the data, a Reed–Solomon code can detect any combination of up to t erroneous symbols, or correct up to t/2⌋ symbols. As an erasure code, it can correct up to t known erasures, or it can detect and correct combinations of errors and erasures. Furthermore, Reed–Solomon codes are suitable as multiple-burst bit-error correcting codes, since a sequence of b + 1 consecutive bit errors can affect at most two symbols of size b. The choice of t is up to the designer of the code, and may be selected within wide limits.

## History

Reed–Solomon codes were developed in 1960 by Irving S. Reed and Gustave Solomon, who were then staff members of MIT Lincoln Laboratory. Their seminal article was titled "Polynomial Codes over Certain Finite Fields." (Reed & Solomon 1960). The original encoding scheme described in the Reed Solomon article used a variable polynomial based on the message to be encoded, which made decoding impractical for all but the simplest of cases. This was resolved by changing the encoding scheme to use a fixed polynomial known to both encoder and decoder. A practical decoder developed by Daniel Gorenstein and Neal Zierler was described in an MIT Lincoln Laboratory report by Zierler in January 1960 and later in a paper in June 1961.[2] During the same period, work was also being done on BCH codes and Reed-Solomon codes were considered as a special class of BCH codes at the time. The Gorenstein-Zierler decoder and the related work on BCH codes are described in a book Error Correcting Codes by W. Wesley Peterson (1961).[3]

An improved decoder was developed in 1969 by Elwyn Berlekamp and James Massey, and is since known as the Berlekamp–Massey decoding algorithm. Another improved decoder was developed in 1975 by Yasuo Sugiyama, based on the extended Euclidean algorithm.[4]

In 1977, Reed–Solomon codes were implemented in the Voyager program in the form of concatenated error correction codes. The first commercial application in mass-produced consumer products appeared in 1982 with the compact disc, where two interleaved Reed–Solomon codes are used. Today, Reed–Solomon codes are widely implemented in digital storage devices and digital communication standards, though they are being slowly replaced by more modern low-density parity-check (LDPC) codes or turbo codes. For example, Reed–Solomon codes are used in the Digital Video Broadcasting (DVB) standard DVB-S, but LDPC codes are used in its successor, DVB-S2.

## Applications

### Data storage

Reed–Solomon coding is very widely used in mass storage systems to correct the burst errors associated with media defects.

Reed–Solomon coding is a key component of the compact disc. It was the first use of strong error correction coding in a mass-produced consumer product, and DAT and DVD use similar schemes. In the CD, two layers of Reed–Solomon coding separated by a 28-way convolutional interleaver yields a scheme called Cross-Interleaved Reed–Solomon Coding (CIRC). The first element of a CIRC decoder is a relatively weak inner (32,28) Reed–Solomon code, shortened from a (255,251) code with 8-bit symbols. This code can correct up to 2 byte errors per 32-byte block. More importantly, it flags as erasures any uncorrectable blocks, i.e., blocks with more than 2 byte errors. The decoded 28-byte blocks, with erasure indications, are then spread by the deinterleaver to different blocks of the (28,24) outer code. Thanks to the deinterleaving, an erased 28-byte block from the inner code becomes a single erased byte in each of 28 outer code blocks. The outer code easily corrects this, since it can handle up to 4 such erasures per block.

The result is a CIRC that can completely correct error bursts up to 4000 bits, or about 2.5 mm on the disc surface. This code is so strong that most CD playback errors are almost certainly caused by tracking errors that cause the laser to jump track, not by uncorrectable error bursts.[5]

DVDs use a similar scheme, but with much larger blocks, a (208,192) inner code, and a (182,172) outer code.

Reed–Solomon error correction is also used in parchive files which are commonly posted accompanying multimedia files on USENET. The Distributed online storage service Wuala (discontinued in 2015) also used to make use of Reed–Solomon when breaking up files.

### Bar code

Almost all two-dimensional bar codes such as PDF-417, MaxiCode, Datamatrix, QR Code, and Aztec Code use Reed–Solomon error correction to allow correct reading even if a portion of the bar code is damaged. When the bar code scanner cannot recognize a bar code symbol, it will treat it as an erasure.

Reed–Solomon coding is less common in one-dimensional bar codes, but is used by the PostBar symbology.

### Data transmission

Specialized forms of Reed–Solomon codes, specifically Cauchy-RS and Vandermonde-RS, can be used to overcome the unreliable nature of data transmission over erasure channels. The encoding process assumes a code of RS(NK) which results in N codewords of length N symbols each storing K symbols of data, being generated, that are then sent over an erasure channel.

Any combination of K codewords received at the other end is enough to reconstruct all of the N codewords. The code rate is generally set to 1/2 unless the channel's erasure likelihood can be adequately modelled and is seen to be less. In conclusion, N is usually 2K, meaning that at least half of all the codewords sent must be received in order to reconstruct all of the codewords sent.

Reed–Solomon codes are also used in xDSL systems and CCSDS's Space Communications Protocol Specifications as a form of forward error correction.

### Space transmission

One significant application of Reed–Solomon coding was to encode the digital pictures sent back by the Voyager space probe.

Voyager introduced Reed–Solomon coding concatenated with convolutional codes, a practice that has since become very widespread in deep space and satellite (e.g., direct digital broadcasting) communications.

Viterbi decoders tend to produce errors in short bursts. Correcting these burst errors is a job best done by short or simplified Reed–Solomon codes.

Modern versions of concatenated Reed–Solomon/Viterbi-decoded convolutional coding were and are used on the Mars Pathfinder, Galileo, Mars Exploration Rover and Cassini missions, where they perform within about 1–1.5 dB of the ultimate limit, being the Shannon capacity.

These concatenated codes are now being replaced by more powerful turbo codes.

## Constructions

The Reed–Solomon code is actually a family of codes: For every choice of the three parameters k < n ≤ q, there is a Reed–Solomon code that has an alphabet of size q, a block length n, and a message length k. Moreover, the alphabet is interpreted as the finite field of order q, and thus, q has to be a prime power. In the most useful parameterizations of the Reed–Solomon code, the block length is usually some constant multiple of the message length, that is, the rate R = k/n is some constant, and furthermore, the block length is equal to or one less than the alphabet size, that is, n = q or n = q − 1.

### Reed & Solomon's original view: The codeword as a sequence of values

There are different encoding procedures for the Reed–Solomon code, and thus, there are different ways to describe the set of all codewords. In the original view of Reed & Solomon (1960), every codeword of the Reed–Solomon code is a sequence of function values of a polynomial of degree less than k. One issue with this view is that decoding and checking for errors is not practical except for the simplest of cases. In order to obtain a codeword of the Reed–Solomon code, the message is interpreted as the description of a polynomial p of degree less than k over the finite field F with q elements. In turn, the polynomial p is evaluated at n distinct points ${\displaystyle a_{1},\dots ,a_{n}}$ of the field F, and the sequence of values is the corresponding codeword. Formally, the set ${\displaystyle \mathbf {C} }$ of codewords of the Reed–Solomon code is defined as follows:

${\displaystyle \mathbf {C} ={\Big \{}\;{\big (}p(a_{1}),p(a_{2}),\dots ,p(a_{n}){\big )}\;{\Big |}\;p{\text{ is a polynomial over }}F{\text{ of degree }}

Since any two distinct polynomials of degree less than ${\displaystyle k}$ agree in at most ${\displaystyle k-1}$ points, this means that any two codewords of the Reed–Solomon code disagree in at least ${\displaystyle n-(k-1)=n-k+1}$ positions. Furthermore, there are two polynomials that do agree in ${\displaystyle k-1}$ points but are not equal, and thus, the distance of the Reed–Solomon code is exactly ${\displaystyle d=n-k+1}$. Then the relative distance is ${\displaystyle \delta =d/n=1-k/n+1/n\sim 1-R}$, where ${\displaystyle R=k/n}$ is the rate. This trade-off between the relative distance and the rate is asymptotically optimal since, by the Singleton bound, every code satisfies ${\displaystyle \delta +R\leq 1}$. Being a code that achieves this optimal trade-off, the Reed–Solomon code belongs to the class of maximum distance separable codes.

While the number of different polynomials of degree less than k and the number of different messages are both equal to ${\displaystyle q^{k}}$, and thus every message can be uniquely mapped to such a polynomial, there are different ways of doing this encoding. The original construction of Reed & Solomon (1960) interprets the message x as the coefficients of the polynomial p, whereas subsequent constructions interpret the message as the values of the polynomial at the first k points ${\displaystyle a_{1},\dots ,a_{k}}$ and obtain the polynomial p by interpolating these values with a polynomial of degree less than k. The latter encoding procedure, while being slightly less efficient, has the advantage that it gives rise to a systematic code, that is, the original message is always contained as a subsequence of the codeword.

In many contexts it is convenient to choose the sequence ${\displaystyle a_{1},\dots ,a_{n}}$ of evaluation points so that they exhibit some additional structure. In particular, it is useful to choose the sequence of successive powers of a primitive root ${\displaystyle \alpha }$ of the field ${\displaystyle F}$, that is, ${\displaystyle \alpha }$ is generator of the finite field's multiplicative group and the sequence is defined as ${\displaystyle a_{i}=\alpha ^{i}}$ for all ${\displaystyle i=1,\dots ,q-1}$. This sequence contains all elements of ${\displaystyle F}$ except for ${\displaystyle 0}$, so in this setting, the block length is ${\displaystyle n=q-1}$. Then it follows that, whenever ${\displaystyle p(a)}$ is a polynomial over ${\displaystyle F}$, then the function ${\displaystyle p(\alpha a)}$ is also a polynomial of the same degree, which gives rise to a codeword that is a cyclic left-shift of the codeword derived from ${\displaystyle p(a)}$; thus, this construction of Reed–Solomon codes gives rise to a cyclic code.

#### Simple encoding procedure: The message as a sequence of coefficients

In the original construction of Reed & Solomon (1960), the message ${\displaystyle x=(x_{1},\dots ,x_{k})\in F^{k}}$ is mapped to the polynomial ${\displaystyle p_{x}}$ with

${\displaystyle p_{x}(a)=\sum _{i=1}^{k}x_{i}a^{i-1}\,.}$

As described above, the codeword is then obtained by evaluating ${\displaystyle p}$ at ${\displaystyle n}$ different points ${\displaystyle a_{1},\dots ,a_{n}}$ of the field ${\displaystyle F}$. Thus the classical encoding function ${\displaystyle C:F^{k}\to F^{n}}$ for the Reed–Solomon code is defined as follows:

${\displaystyle C(x)={\big (}p_{x}(a_{1}),\dots ,p_{x}(a_{n}){\big )}\,.}$

This function ${\displaystyle C}$ is a linear mapping, that is, it satisfies ${\displaystyle C(x)=x\cdot A}$ for the following ${\displaystyle (k\times n)}$-matrix ${\displaystyle A}$ with elements from ${\displaystyle F}$:

${\displaystyle A={\begin{bmatrix}1&\dots &1\\a_{1}&\dots &a_{n}\\a_{1}^{2}&\dots &a_{n}^{2}\\\vdots &\ddots &\vdots \\a_{1}^{k-1}&\dots &a_{n}^{k-1}\end{bmatrix}}}$

This matrix is the transpose of a Vandermonde matrix over ${\displaystyle F}$. In other words, the Reed–Solomon code is a linear code, and in the classical encoding procedure, its generator matrix is ${\displaystyle A}$.

#### Systematic encoding procedure: The message as an initial sequence of values

As mentioned above, there is an alternative way to map codewords ${\displaystyle x}$ to polynomials ${\displaystyle p_{x}}$. In this alternative encoding procedure, the polynomial ${\displaystyle p_{x}}$ is the unique polynomial of degree less than ${\displaystyle k}$ such that

${\displaystyle p_{x}(a_{i})=x_{i}}$ holds for all ${\displaystyle i=1,\dots ,k}$.

To compute this polynomial ${\displaystyle p_{x}}$ from ${\displaystyle x}$, one can use Lagrange interpolation. Once it has been found, it is evaluated at the other points ${\displaystyle a_{k+1},\dots ,a_{n}}$ of the field. The alternative encoding function ${\displaystyle C:F^{k}\to F^{n}}$ for the Reed–Solomon code is then again just the sequence of values:

${\displaystyle C(x)={\big (}p_{x}(a_{1}),\dots ,p_{x}(a_{n}){\big )}\,.}$

This time, however, the first ${\displaystyle k}$ entries of the codeword are exactly equal to ${\displaystyle x}$, so this encoding procedure gives rise to a systematic code. It can be checked that the alternative encoding function is a linear mapping as well.

#### Theoretical decoding procedure

Reed & Solomon (1960) described a theoretical decoder that corrected errors by finding the most popular message polynomial. The decoder only knows the set of values ${\displaystyle a_{1}}$ to ${\displaystyle a_{n}}$ and which encoding method was used to generate the codeword's sequence of values. The original message, the polynomial, and any errors are unknown. A decoding procedure could use a method like Lagrange interpolation on various subsets of n codeword values taken k at a time to repeatedly produce potential polynomials, until a sufficient number of matching polynomials are produced to reasonably eliminate any errors in the received codeword. Once a polynomial is determined, then any errors in the codeword can be corrected, by recalculating the corresponding codeword values. Unfortunately, in all but the simplest of cases, there are too many subsets, so the algorithm is impractical. The number of subsets is the binomial coefficient, ${\displaystyle \textstyle {\binom {n}{k}}={n! \over (n-k)!k!}}$, and the number of subsets is infeasible for even modest codes. For a ${\displaystyle (255,249)}$ code that can correct 3 errors, the naive theoretical decoder would examine 359 billion subsets. Practical decoding involved changing the view of codewords to be a sequence of coefficients as explained in the next section.

### The BCH view: The codeword as a sequence of coefficients

In this view, the sender again maps the message ${\displaystyle x}$ to a polynomial ${\displaystyle p_{x}}$, and for this, any of the two mappings above can be used (where the message is either interpreted as the coefficients of ${\displaystyle p_{x}}$ or as the initial sequence of values of ${\displaystyle p_{x}}$). Once the sender has constructed the polynomial ${\displaystyle p_{x}}$ in some way, however, instead of sending the values of ${\displaystyle p_{x}}$ at all points, the sender computes some related polynomial ${\displaystyle s}$ of degree at most ${\displaystyle n-1}$ for ${\displaystyle n=q-1}$ and sends the ${\displaystyle n}$ coefficients of that polynomial. The polynomial ${\displaystyle s(a)}$ is constructed by multiplying the message polynomial ${\displaystyle p_{x}(a)}$, which has degree at most ${\displaystyle k-1}$, with a generator polynomial ${\displaystyle g(a)}$ of degree ${\displaystyle n-k}$ that is known to both the sender and the receiver. The generator polynomial ${\displaystyle g(x)}$ is defined as the polynomial whose roots are exactly ${\displaystyle \alpha ,\alpha ^{2},\dots ,\alpha ^{n-k}}$, i.e.,

${\displaystyle g(x)=(x-\alpha )(x-\alpha ^{2})\cdots (x-\alpha ^{n-k})=g_{0}+g_{1}x+\cdots +g_{n-k-1}x^{n-k-1}+x^{n-k}\,.}$

The transmitter sends the ${\displaystyle n=q-1}$ coefficients of ${\displaystyle s(a)=p_{x}(a)\cdot g(a)}$. Thus, in the BCH view of Reed Solomon codes, the set ${\displaystyle \mathbf {C'} }$ of codewords is defined for ${\displaystyle n=q-1}$ as follows:[6]

${\displaystyle \mathbf {C'} =\left\{\left(s_{1},s_{2},\dots ,s_{n}\right)\left|s(a)=\sum _{i=1}^{n}s_{i}a^{i-1}\right.{\text{ is a polynomial that has at least the roots }}\alpha ^{1},\alpha ^{2},\dots ,\alpha ^{n-k}\right\}.}$

With this definition of the codewords, it can be immediately seen that a Reed–Solomon code is a polynomial code, and in particular a BCH code. The generator polynomial ${\displaystyle g(a)}$ is the minimal polynomial with roots ${\displaystyle \alpha ,\alpha ^{2},\ldots ,\alpha ^{n-k}}$ as defined above, and the codewords are exactly the polynomials that are divisible by ${\displaystyle g(a)}$.

Since Reed–Solomon codes are a special case of BCH codes, the practical decoders designed for BCH codes are applicable to Reed–Solomon codes: The receiver interprets the received word as the coefficients of a polynomial ${\displaystyle r(a)}$. If no error has occurred during the transmission, that is, if ${\displaystyle r(a)=s(a)}$, then the receiver can use polynomial division to determine the message polynomial ${\displaystyle p_{x}(a)=r(a)/g(a)}$. In general, the receiver can use polynomial division to construct the unique polynomials ${\displaystyle p(a)}$ and ${\displaystyle e(a)}$, such that ${\displaystyle e(a)}$ has degree less than the degree of ${\displaystyle g(a)}$ and

${\displaystyle r(a)=p(a)\cdot g(a)+e(a).}$

If the remainder polynomial ${\displaystyle e(a)}$ is not identically zero, then an error has occurred during the transmission. The receiver can evaluate ${\displaystyle r(a)}$ at the roots of ${\displaystyle g(a)}$ and build a system of equations that eliminates ${\displaystyle s(a)}$ and identifies which coefficients of ${\displaystyle r(a)}$ are in error, and the magnitude of each coefficient's error. If the system of equations can be solved, then the receiver knows how to modify the received word ${\displaystyle r(a)}$ to get the most likely codeword ${\displaystyle s(a)}$ that was sent.

#### Systematic encoding procedure

The above encoding procedure for the BCH view of Reed–Solomon codes is classical, but does not give rise to a systematic encoding procedure, i.e., the codewords do not necessarily contain the message as a subsequence.To remedy this fact, instead of sending ${\displaystyle s(x)=p(x)g(x)}$, the encoder constructs the transmitted polynomial ${\displaystyle s(x)}$ such that the coefficients of the ${\displaystyle k}$ largest monomials are equal to the corresponding coefficients of ${\displaystyle p(x)}$, and the lower-order coefficients of ${\displaystyle s(x)}$ are chosen exactly in such a way that ${\displaystyle s(x)}$ becomes divisible by ${\displaystyle g(x)}$. Then the coefficients of ${\displaystyle p(x)}$ are a subsequence of the coefficients of ${\displaystyle s(x)}$. To get a code that is overall systematic, we construct the message polynomial ${\displaystyle p(x)}$ by interpreting the message as the sequence of its coefficients.

Formally, the construction is done by multiplying ${\displaystyle p(x)}$ by ${\displaystyle x^{t}}$ to make room for the ${\displaystyle t=n-k}$ check symbols, dividing that product by ${\displaystyle g(x)}$ to find the remainder, and then compensating for that remainder by subtracting it. The ${\displaystyle t}$ check symbols are created by computing the remainder ${\displaystyle s_{r}(x)}$:

${\displaystyle s_{r}(x)=p(x)\cdot x^{t}\ {\bmod {\ }}g(x).}$

Note that the remainder has degree at most ${\displaystyle t-1}$, whereas the coefficients of ${\displaystyle x^{t-1},x^{t-2},\dots ,x^{1},x^{0}}$ in the polynomial ${\displaystyle p(x)\cdot x^{t}}$ are zero. Therefore, the following definition of the codeword ${\displaystyle s(x)}$ has the property that the first ${\displaystyle k}$ coefficients are identical to the coefficients of ${\displaystyle p(x)}$:

${\displaystyle s(x)=p(x)\cdot x^{t}-s_{r}(x)\,.}$

As a result, the codewords ${\displaystyle s(x)}$ are indeed elements of ${\displaystyle \mathbf {C'} }$, that is, they are divisible by the generator polynomial ${\displaystyle g(x)}$:[7]

${\displaystyle s(x)\equiv p(x)\cdot x^{t}-s_{r}(x)\equiv s_{r}(x)-s_{r}(x)\equiv 0\mod g(x)\,.}$

### Duality of the two views - discrete Fourier transform

At first sight, the two views of Reed–Solomon codes above seem very different. In the first definition, codewords in the set ${\displaystyle \mathbf {C} }$ are values of polynomials, whereas in the second set ${\displaystyle \mathbf {C'} }$, they are coefficients. Moreover, the generator polynomials in the first definition are of degree less than ${\displaystyle k}$, are variable, and unknown to the decoder, whereas those in the second definition are of degree ${\displaystyle n-k}$, are required to have specific roots, and are known to both encoder and decoder. Although the codewords as produced by the above encoder schemes are not the same, there is a duality between the coefficients of polynomials and their values that would allow the same codeword to be considered as a set of coefficients or a set of values.

The equivalence of the two definitions can be proved using the discrete Fourier transform. This transform, which exists in all finite fields as well as the complex numbers, establishes a duality between the coefficients of polynomials and their values. This duality can be approximately summarized as follows: Let ${\displaystyle p(x)}$ and ${\displaystyle q(x)}$ be two polynomials of degree less than ${\displaystyle n}$. If the values of ${\displaystyle p(x)}$ are the coefficients of ${\displaystyle q(x)}$, then (up to a scalar factor and reordering), the values of ${\displaystyle q(x)}$ are the coefficients of ${\displaystyle p(x)}$. For this to make sense, the values must be taken at locations ${\displaystyle x=\alpha ^{i}}$, for ${\displaystyle i=0,\dots ,n-1}$, where ${\displaystyle \alpha }$ is a primitive ${\displaystyle n}$th root of unity.

To be more precise, let

${\displaystyle p(x)=v_{0}+v_{1}x+v_{2}x^{2}+\cdots +v_{n-1}x^{n-1},}$
${\displaystyle q(x)=f_{0}+f_{1}x+f_{2}x^{2}+\cdots +f_{n-1}x^{n-1}}$

and assume ${\displaystyle p(x)}$ and ${\displaystyle q(x)}$ are related by the discrete Fourier transform. Then the coefficients and values of ${\displaystyle p(x)}$ and ${\displaystyle q(x)}$ are related as follows: for all ${\displaystyle i=0,\dots ,n-1}$, ${\displaystyle f_{i}=p(\alpha ^{i})}$ and ${\displaystyle \textstyle v_{i}={\frac {1}{n}}q(\alpha ^{n-i})}$ or in the case of a binary field where addition is effectively xor, ${\displaystyle v_{i}=q(\alpha ^{n-i})}$.

Using these facts, we have: ${\displaystyle (f_{0},\ldots ,f_{n-1})}$ is a code word of the Reed–Solomon code according to the first definition

• if and only if ${\displaystyle p(x)}$ is of degree less than ${\displaystyle k}$ (because ${\displaystyle f_{0},\ldots ,f_{n-1}}$ are the values of ${\displaystyle p(x)}$),
• if and only if ${\displaystyle v_{i}=0}$ for ${\displaystyle i=k,\ldots ,n-1}$,
• if and only if ${\displaystyle q(\alpha ^{i})=0}$ for ${\displaystyle i=1,\ldots ,n-k}$ (because ${\displaystyle q(\alpha ^{i})=nv_{n-i}}$ or for binary field ${\displaystyle q(\alpha ^{i})=v_{n-i}}$ ),
• if and only if ${\displaystyle (f_{0},\ldots ,f_{n-1})}$ is a code word of the Reed–Solomon code according to the second definition.

This shows that the two definitions are equivalent. However, the practical decoders described below require a generator polynomial known to the decoder, and view a codeword as a set of coefficients.

### Remarks

Designers are not required to use the "natural" sizes of Reed–Solomon code blocks. A technique known as "shortening" can produce a smaller code of any desired size from a larger code. For example, the widely used (255,223) code can be converted to a (160,128) code by padding the unused portion of the source block with 95 binary zeroes and not transmitting them. At the decoder, the same portion of the block is loaded locally with binary zeroes. The Delsarte-Goethals-Seidel[8] theorem illustrates an example of an application of shortened Reed–Solomon codes. In parallel to shortening, a technique known as puncturing allows omitting some of the encoded parity symbols.

## Properties

The Reed–Solomon code is a [n, k, nk + 1] code; in other words, it is a linear block code of length n (over F) with dimension k and minimum Hamming distance n − k + 1. The Reed–Solomon code is optimal in the sense that the minimum distance has the maximum value possible for a linear code of size (nk); this is known as the Singleton bound. Such a code is also called a maximum distance separable (MDS) code.

The error-correcting ability of a Reed–Solomon code is determined by its minimum distance, or equivalently, by ${\displaystyle n-k}$, the measure of redundancy in the block. If the locations of the error symbols are not known in advance, then a Reed–Solomon code can correct up to ${\displaystyle (n-k)/2}$ erroneous symbols, i.e., it can correct half as many errors as there are redundant symbols added to the block. Sometimes error locations are known in advance (e.g., "side information" in demodulator signal-to-noise ratios)—these are called erasures. A Reed–Solomon code (like any MDS code) is able to correct twice as many erasures as errors, and any combination of errors and erasures can be corrected as long as the relation 2E + Snk is satisfied, where ${\displaystyle E}$ is the number of errors and ${\displaystyle S}$ is the number of erasures in the block.

For practical uses of Reed–Solomon codes, it is common to use a finite field ${\displaystyle F}$ with ${\displaystyle 2^{m}}$ elements. In this case, each symbol can be represented as an ${\displaystyle m}$-bit value. The sender sends the data points as encoded blocks, and the number of symbols in the encoded block is ${\displaystyle n=2^{m}-1}$. Thus a Reed–Solomon code operating on 8-bit symbols has ${\displaystyle n=2^{8}-1=255}$ symbols per block. (This is a very popular value because of the prevalence of byte-oriented computer systems.) The number ${\displaystyle k}$, with ${\displaystyle k, of data symbols in the block is a design parameter. A commonly used code encodes ${\displaystyle k=223}$ eight-bit data symbols plus 32 eight-bit parity symbols in an ${\displaystyle n=255}$-symbol block; this is denoted as a ${\displaystyle (n,k)=(255,223)}$ code, and is capable of correcting up to 16 symbol errors per block.

The Reed–Solomon code properties discussed above make them especially well-suited to applications where errors occur in bursts. This is because it does not matter to the code how many bits in a symbol are in error — if multiple bits in a symbol are corrupted it only counts as a single error. Conversely, if a data stream is not characterized by error bursts or drop-outs but by random single bit errors, a Reed–Solomon code is usually a poor choice compared to a binary code.

The Reed–Solomon code, like the convolutional code, is a transparent code. This means that if the channel symbols have been inverted somewhere along the line, the decoders will still operate. The result will be the inversion of the original data. However, the Reed–Solomon code loses its transparency when the code is shortened. The "missing" bits in a shortened code need to be filled by either zeros or ones, depending on whether the data is complemented or not. (To put it another way, if the symbols are inverted, then the zero-fill needs to be inverted to a one-fill.) For this reason it is mandatory that the sense of the data (i.e., true or complemented) be resolved before Reed–Solomon decoding.

## Error correction algorithms

The decoders described below use the BCH view of the codeword as sequence of coefficients.

### Peterson–Gorenstein–Zierler decoder

Daniel Gorenstein and Neal Zierler developed a practical decoder that was described in a MIT Lincoln Laboratory report by Zierler in January 1960 and later in a paper in June 1961.[9] The Gorenstein-Zierler decoder and the related work on BCH codes are described in a book Error Correcting Codes by W. Wesley Peterson (1961).[10]

#### Syndrome decoding

The transmitted message is viewed as the coefficients of a polynomial s(x) that is divisible by a generator polynomial g(x).

${\displaystyle s(x)=\sum _{i=0}^{n-1}c_{i}x^{i}}$
${\displaystyle g(x)=\prod _{j=1}^{n-k}(x-\alpha ^{j}),}$

where α is a primitive root.

Since s(x) is divisible by generator g(x), it follows that

${\displaystyle s(\alpha ^{i})=0,\ i=1,2,\ldots ,n-k}$

The transmitted polynomial is corrupted in transit by an error polynomial e(x) to produce the received polynomial r(x).

${\displaystyle r(x)=s(x)+e(x)}$
${\displaystyle e(x)=\sum _{i=0}^{n-1}e_{i}x^{i}}$

where ei is the coefficient for the i-th power of x. Coefficient ei will be zero if there is no error at that power of x and nonzero if there is an error. If there are ν errors at distinct powers ik of x, then

${\displaystyle e(x)=\sum _{k=1}^{\nu }e_{i_{k}}x^{i_{k}}}$

The goal of the decoder is to find the number of errors (ν), the positions of the errors (ik), and the error values at those positions (eik). From those, e(x) can be calculated and subtracted from r(x) to get the original message s(x).

The syndromes Sj are defined as

{\displaystyle {\begin{aligned}S_{j}&=r(\alpha ^{j})=s(\alpha ^{j})+e(\alpha ^{j})=0+e(\alpha ^{j})=e(\alpha ^{j}),\ j=1,2,\ldots ,n-k\\&=\sum _{k=1}^{\nu }e_{i_{k}}\left(\alpha ^{j}\right)^{i_{k}}\end{aligned}}}

The advantage of looking at the syndromes is that the message polynomial drops out. Another possible way of calculating e(x) is using polynomial interpolation to find the only polynomial that passes through the points ${\displaystyle (\alpha ^{j},S_{j})}$ (Because ${\displaystyle S_{j}=e(\alpha ^{j})}$), however, this is not used widely because polynomial interpolation is not always feasible in the fields used in Reed–Solomon error correction. For example, it is feasible over the integers (of course), but it is infeasible over the integers modulo a prime[citation needed].

#### Error locators and error values

For convenience, define the error locators Xk and error values Yk as:

${\displaystyle X_{k}=\alpha ^{i_{k}},\ Y_{k}=e_{i_{k}}}$

Then the syndromes can be written in terms of the error locators and error values as

${\displaystyle S_{j}=\sum _{k=1}^{\nu }Y_{k}X_{k}^{j}}$

The syndromes give a system of n − k ≥ 2ν equations in 2ν unknowns, but that system of equations is nonlinear in the Xk and does not have an obvious solution. However, if the Xk were known (see below), then the syndrome equations provide a linear system of equations that can easily be solved for the Yk error values.

${\displaystyle {\begin{bmatrix}X_{1}^{1}&X_{2}^{1}&\cdots &X_{\nu }^{1}\\X_{1}^{2}&X_{2}^{2}&\cdots &X_{\nu }^{2}\\\vdots &\vdots &&\vdots \\X_{1}^{n-k}&X_{2}^{n-k}&\cdots &X_{\nu }^{n-k}\\\end{bmatrix}}{\begin{bmatrix}Y_{1}\\Y_{2}\\\vdots \\Y_{\nu }\end{bmatrix}}={\begin{bmatrix}S_{1}\\S_{2}\\\vdots \\S_{n-k}\end{bmatrix}}}$

Consequently, the problem is finding the Xk, because then the leftmost matrix would be known, and both sides of the equation could be multiplied by its inverse, yielding Yk

#### Error locator polynomial

There is a linear recurrence relation that gives rise to a system of linear equations. Solving those equations identifies the error locations.

Define the error locator polynomial Λ(x) as

${\displaystyle \Lambda (x)=\prod _{k=1}^{\nu }(1-xX_{k})=1+\Lambda _{1}x^{1}+\Lambda _{2}x^{2}+\cdots +\Lambda _{\nu }x^{\nu }}$

The zeros of Λ(x) are the reciprocals ${\displaystyle X_{k}^{-1}}$:

${\displaystyle \Lambda (X_{k}^{-1})=0}$
${\displaystyle \Lambda (X_{k}^{-1})=1+\Lambda _{1}X_{k}^{-1}+\Lambda _{2}X_{k}^{-2}+\cdots +\Lambda _{\nu }X_{k}^{-\nu }=0}$

Multiply both sides by ${\displaystyle Y_{k}X_{k}^{j+\nu }}$ and it will still be zero. j is any number such that 1≤j≤v.

{\displaystyle {\begin{aligned}&Y_{k}X_{k}^{j+\nu }\Lambda (X_{k}^{-1})=0.\\{\text{Hence }}&Y_{k}X_{k}^{j+\nu }+\Lambda _{1}Y_{k}X_{k}^{j+\nu }X_{k}^{-1}+\Lambda _{2}Y_{k}X_{k}^{j+\nu }X_{k}^{-2}+\cdots +\Lambda _{\nu }Y_{k}X_{k}^{j+\nu }X_{k}^{-\nu }=0,\\{\text{and so }}&Y_{k}X_{k}^{j+\nu }+\Lambda _{1}Y_{k}X_{k}^{j+\nu -1}+\Lambda _{2}Y_{k}X_{k}^{j+\nu -2}+\cdots +\Lambda _{\nu }Y_{k}X_{k}^{j}=0\\\end{aligned}}}

Sum for k = 1 to ν

{\displaystyle {\begin{aligned}&\sum _{k=1}^{\nu }(Y_{k}X_{k}^{j+\nu }+\Lambda _{1}Y_{k}X_{k}^{j+\nu -1}+\Lambda _{2}Y_{k}X_{k}^{j+\nu -2}+\cdots +\Lambda _{\nu }Y_{k}X_{k}^{j})=0\\&\sum _{k=1}^{\nu }(Y_{k}X_{k}^{j+\nu })+\Lambda _{1}\sum _{k=1}^{\nu }(Y_{k}X_{k}^{j+\nu -1})+\Lambda _{2}\sum _{k=1}^{\nu }(Y_{k}X_{k}^{j+\nu -2})+\cdots +\Lambda _{\nu }\sum _{k=1}^{\nu }(Y_{k}X_{k}^{j})=0\end{aligned}}}

This reduces to

${\displaystyle S_{j+\nu }+\Lambda _{1}S_{j+\nu -1}+\cdots +\Lambda _{\nu -1}S_{j+1}+\Lambda _{\nu }S_{j}=0\,}$
${\displaystyle S_{j}\Lambda _{\nu }+S_{j+1}\Lambda _{\nu -1}+\cdots +S_{j+\nu -1}\Lambda _{1}=-S_{j+\nu }\ }$

This yields a system of linear equations that can be solved for the coefficients Λi of the error location polynomial:

${\displaystyle {\begin{bmatrix}S_{1}&S_{2}&\cdots &S_{\nu }\\S_{2}&S_{3}&\cdots &S_{\nu +1}\\\vdots &\vdots &&\vdots \\S_{\nu }&S_{\nu +1}&\cdots &S_{2\nu -1}\end{bmatrix}}{\begin{bmatrix}\Lambda _{\nu }\\\Lambda _{\nu -1}\\\vdots \\\Lambda _{1}\end{bmatrix}}={\begin{bmatrix}-S_{\nu +1}\\-S_{\nu +2}\\\vdots \\-S_{\nu +\nu }\end{bmatrix}}}$

The above assumes the decoder knows the number of errors ν, but that number has not been determined yet. The PGZ decoder does not determine ν directly but rather searches for it by trying successive values. The decoder first assumes the largest value for a trial ν and sets up the linear system for that value. If the equations can be solved (i.e., the matrix determinant is nonzero), then that trial value is the number of errors. If the linear system cannot be solved, then the trial ν is reduced by one and the next smaller system is examined. (Gill n.d., p. 35)

#### Obtain the error locators from the error locator polynomial

Use the coefficients Λi found in the last step to build the error location polynomial. The roots of the error location polynomial can be found by exhaustive search. The error locators are the reciprocals of those roots. Chien search is an efficient implementation of this step.

#### Calculate the error locations

Calculate ik by taking the log base a of Xk. This is generally done using a precomputed lookup table.

#### Calculate the error values

Once the error locators are known, the error values can be determined. This can be done by direct solution for Yk in the error equations given above, or using the Forney algorithm.

#### Fix the errors

Finally, e(x) is generated from ik and eik and then is subtracted from r(x) to get the sent message s(x).

### Berlekamp–Massey decoder

The Berlekamp–Massey algorithm is an alternate iterative procedure for finding the error locator polynomial. During each iteration, it calculates a discrepancy based on a current instance of Λ(x) with an assumed number of errors e:

${\displaystyle \Delta =S_{i}+\Lambda _{1}\ S_{i-1}+\cdots +\Lambda _{e}\ S_{i-e}}$

and then adjusts Λ(x) and e so that a recalculated Δ would be zero. The article Berlekamp–Massey algorithm has a detailed description of the procedure. In the following example, C(x) is used to represent Λ(x).

#### Example

Consider the Reed–Solomon code defined in GF(929) with α = 3 and t = 4 (this is used in PDF417 barcodes). The generator polynomial is

${\displaystyle g(x)=(x-3)(x-3^{2})(x-3^{3})(x-3^{4})=x^{4}+809x^{3}+723x^{2}+568x+522}$

If the message polynomial is p(x) = 3 x2 + 2 x + 1, then the codeword is calculated as follows.

${\displaystyle s_{r}(x)=p(x)\,x^{t}\mod g(x)=547x^{3}+738x^{2}+442x+455}$
${\displaystyle s(x)=p(x)\,x^{t}-s_{r}(x)=3x^{6}+2x^{5}+1x^{4}+382x^{3}+191x^{2}+487x+474}$

${\displaystyle r(x)=s(x)+e(x)=3x^{6}+2x^{5}+123x^{4}+456x^{3}+191x^{2}+487x+474}$

The syndromes are calculated by evaluating r at powers of α.

${\displaystyle S_{1}=r(3^{1})=3\cdot 3^{6}+2\cdot 3^{5}+123\cdot 3^{4}+456\cdot 3^{3}+191\cdot 3^{2}+487\cdot 3+474=732}$
${\displaystyle S_{2}=r(3^{2})=637,\;S_{3}=r(3^{3})=762,\;S_{4}=r(3^{4})=925}$

To correct the errors, first use the Berlekamp–Massey algorithm to calculate the error locator polynomial.

n Sn+1 d C B b m
0 732 732 197 x + 1 1 732 1
1 637 846 173 x + 1 1 732 2
2 762 412 634 x2 + 173 x + 1 173 x + 1 412 1
3 925 576 329 x2 + 821 x + 1 173 x + 1 412 2

The final value of C is the error locator polynomial, Λ(x). The zeros can be found by trial substitution. They are x1 = 757 = 3−3 and x2 = 562 = 3−4, corresponding to the error locations. To calculate the error values, apply the Forney algorithm.

${\displaystyle \Omega (x)=S(x)\Lambda (x)\mod x^{4}=546x+732\,}$
${\displaystyle \Lambda '(x)=658x+821\,}$
${\displaystyle e_{1}=-\Omega (x_{1})/\Lambda '(x_{1})=-649/54=280\times 843=74\,}$
${\displaystyle e_{2}=-\Omega (x_{2})/\Lambda '(x_{2})=122\,}$

Subtracting e1x3 and e2x4 from the received polynomial r reproduces the original codeword s.

### Euclidean decoder

Another iterative method for calculating both the error locator polynomial and the error value polynomial is based on Sugiyama's adaptation of the Extended Euclidean algorithm .

Define S(x), Λ(x), and Ω(x) for t syndromes and e errors:

${\displaystyle S(x)=S_{t}x^{t-1}+S_{t-1}x^{t-2}+\cdots +S_{2}x+S_{1}}$
${\displaystyle \Lambda (x)=\Lambda _{e}x^{e}+\Lambda _{e-1}x^{e-1}+\cdots +\Lambda _{1}x+1}$
${\displaystyle \Omega (x)=\Omega _{e}x^{e}+\Omega _{e-1}x^{e-1}+\cdots +\Omega _{1}x+\Omega _{0}}$

The key equation is:

${\displaystyle \Lambda (x)S(x)=Q(x)x^{t}+\Omega (x)}$

For t = 6 and e = 3:

${\displaystyle {\begin{bmatrix}\Lambda _{3}S_{6}&x^{8}\\\Lambda _{2}S_{6}+\Lambda _{3}S_{5}&x^{7}\\\Lambda _{1}S_{6}+\Lambda _{2}S_{5}+\Lambda _{3}S_{4}&x^{6}\\S_{6}+\Lambda _{1}S_{5}+\Lambda _{2}S_{4}+\Lambda _{3}S_{3}&x^{5}\\S_{5}+\Lambda _{1}S_{4}+\Lambda _{2}S_{3}+\Lambda _{3}S_{2}&x^{4}\\S_{4}+\Lambda _{1}S_{3}+\Lambda _{2}S_{2}+\Lambda _{3}S_{1}&x^{3}\\S_{3}+\Lambda _{1}S_{2}+\Lambda _{2}S_{1}&x^{2}\\S_{2}+\Lambda _{1}S_{1}&x\\S_{1}&\\\end{bmatrix}}={\begin{bmatrix}Q_{2}x^{8}\\Q_{1}x^{7}\\Q_{0}x^{6}\\0\\0\\0\\\Omega _{2}x^{2}\\\Omega _{1}x\\\Omega _{0}\\\end{bmatrix}}}$

The middle terms are zero due to the relationship between Λ and syndromes.

The extended Euclidean algorithm can find a series of polynomials of the form

Ai(x) S(x) + Bi(x) xt = Ri(x)

where the degree of R decreases as i increases. Once the degree of Ri(x) < t/2, then

Ai(x) = Λ(x)

Bi(x) = -Q(x)

Ri(x) = Ω(x).

B(x) and Q(x) don't need to be saved, so the algorithm becomes:

R-1 = xt
R0 = S(x)
A-1 = 0
A0 = 1
i = 0
while degree of Ri >= t/2
i = i + 1
Q = Ri-2 / Ri-1
Ri = Ri-2 - Q Ri-1
Ai = Ai-2 - Q Ai-1

to set low order term of Λ(x) to 1, divide Λ(x) and Ω(x) by Ai(0):

Λ(x) = Ai / Ai(0)
Ω(x) = Ri / Ai(0)

Ai(0) is the constant (low order) term of Ai.

#### Example

Using the same data as the Berlekamp Massey example above:

i Ri Ai
-1 001 x4 + 000 x3 + 000 x2 + 000 x + 000 000
0 925 x3 + 762 x2 + 637 x + 732 001
1 683 x2 + 676 x + 024 697 x + 396
2 673 x + 596 608 x2 + 704 x + 544
Λ(x) = A2 / 544 = 329 x2 + 821 x + 001
Ω(x) = R2 / 544 = 546 x + 732

### Decoder using discrete Fourier transform

A discrete Fourier transform can be used for decoding.[11] To avoid conflict with syndrome names, let c(x) = s(x) the encoded codeword. r(x) and e(x) are the same as above. Define C(x), E(x), and R(x) as the discrete Fourier transforms of c(x), e(x), and r(x). Since r(x) = c(x) + e(x), and since a discrete Fourier transform is a linear operator, R(x) = C(x) + E(x).

Transform r(x) to R(x) using discrete Fourier transform. Since the calculation for a discrete Fourier transform is the same as the calculation for syndromes, t coefficients of R(x) and E(x) are the same as the syndromes:

${\displaystyle R_{j}=E_{j}=S_{j}=r(\alpha ^{j})}$
${\displaystyle for\ 1\leq j\leq t}$

Use ${\displaystyle R_{1}}$ through ${\displaystyle R_{t}}$ as syndromes (they're the same) and generate the error locator polynomial using the methods from any of the above decoders.

Let v = number of errors. Generate E(x) using the known coefficients ${\displaystyle E_{1}}$ to ${\displaystyle E_{t}}$, the error locator polynomial, and these formulas

${\displaystyle E_{0}=-{\frac {1}{\sigma _{v}}}(E_{v}+\sigma _{1}E_{v-1}+\cdots +\sigma _{v-1}E_{1})}$
${\displaystyle E_{j}=-(\sigma _{1}E_{j-1}+\sigma _{2}E_{j-2}+\cdots +\sigma _{v}E_{j-v})}$
${\displaystyle for\ t

Then calculate C(x) = R(x) - E(x) and take the inverse transform of C(x) to produce c(x).

### Decoding beyond the error-correction bound

The Singleton bound states that the minimum distance d of a linear block code of size (n,k) is upper-bounded by n − k + 1. The distance d was usually understood to limit the error-correction capability to ⌊d/2⌋. The Reed–Solomon code achieves this bound with equality, and can thus correct up to ⌊(n − k + 1)/2⌋ errors. However, this error-correction bound is not exact.

In 1999, Madhu Sudan and Venkatesan Guruswami at MIT published "Improved Decoding of Reed–Solomon and Algebraic-Geometry Codes" introducing an algorithm that allowed for the correction of errors beyond half the minimum distance of the code.[12] It applies to Reed–Solomon codes and more generally to algebraic geometric codes. This algorithm produces a list of codewords (it is a list-decoding algorithm) and is based on interpolation and factorization of polynomials over ${\displaystyle GF(2^{m})}$ and its extensions.

### Soft-decoding

The algebraic decoding methods described above are hard-decision methods, which means that for every symbol a hard decision is made about its value. For example, a decoder could associate with each symbol an additional value corresponding to the channel demodulator's confidence in the correctness of the symbol. The advent of LDPC and turbo codes, which employ iterated soft-decision belief propagation decoding methods to achieve error-correction performance close to the theoretical limit, has spurred interest in applying soft-decision decoding to conventional algebraic codes. In 2003, Ralf Koetter and Alexander Vardy presented a polynomial-time soft-decision algebraic list-decoding algorithm for Reed–Solomon codes, which was based upon the work by Sudan and Guruswami.[13]

### Matlab Example

#### Encoder

Here we present a simple Matlab implementation for an encoder.

function [ encoded ] = rsEncoder( msg, m, prim_poly, n, k )
%RSENCODER Encode message with the Reed-Solomon algorithm
% m is the number of bits per symbol
% prim_poly: Primitive polynomial p(x). Ie for DM is 301
% k is the size of the message
% n is the total size (k+redundant)
% Example: msg = uint8('Test')
% enc_msg = rsEncoder(msg, 8, 301, 12, numel(msg));

% Get the alpha
alpha = gf(2, m, prim_poly);

% Get the reed-solomon generating polynomial g(x)
g_x = genpoly(k, n, alpha);

% Multiply the information by X^(n-k), or just pad with zeros at the end to
% get space to add the redundant information
msg_padded = gf([msg zeros(1, n-k)], m, prim_poly);

% Get the remainder of the division of the extended message by the
% reed-solomon generating polynomial g(x)

% Now return the message with the redundant information

end

% Find the reed-solomon generating polynomial g(x), by the way this is the
% same as the rsgenpoly function on matlab
function g = genpoly(k, n, alpha)
g = 1;
% A multiplication on the galois field is just a convolution
for k = mod(1 : n-k, n)
g = conv(g, [1 alpha .^ (k)]);
end
end


#### Decoder

Now the decoding part:

function [ decoded, error_pos, error_mag, g, S ] = rsDecoder( encoded, m, prim_poly, n, k )
%RSDECODER Decode a reed-solomon encoded message
%   Example:
% [dec, ~, ~, ~, ~] = rsDecoder(enc_msg, 8, 301, 12, numel(msg))
max_errors = floor((n-k)/2);
orig_vals = encoded.x;
% Initialize the error vector
errors = zeros(1, n);
g = [];
S = [];

% Get the alpha
alpha = gf(2, m, prim_poly);

% Find the syndromes (Check if dividing the message by the generator
% polynomial the result is zero)
Synd = polyval(encoded, alpha .^ (1:n-k));
Syndromes = trim(Synd);

% If all syndromes are zeros (perfectly divisible) there are no errors
if isempty(Syndromes.x)
decoded = orig_vals(1:k);
error_pos = [];
error_mag = [];
g = [];
S = Synd;
return;
end

% Prepare for the euclidean algorithm (Used to find the error locating
% polynomials)
r0 = [1, zeros(1, 2*max_errors)]; r0 = gf(r0, m, prim_poly); r0 = trim(r0);
size_r0 = length(r0);
r1 = Syndromes;
f0 = gf([zeros(1, size_r0-1) 1], m, prim_poly);
f1 = gf(zeros(1, size_r0), m, prim_poly);
g0 = f1; g1 = f0;

% Do the euclidian algorithm on the polynomials r0(x) and Syndromes(x) in
% order to find the error locating polynomial
while true
% Do a long division
[quotient, remainder] = deconv(r0, r1);

c = conv(quotient, g1);
c = trim(c);

% Update g as g0-quotient*g1
g = g0 - c;

% Check if the degree of remainder(x) is less than max_errors
if all(remainder(1:end - max_errors) == 0)
break;
end

% Update r0, r1, g0, g1 and remove leading zeros
r0 = trim(r1); r1 = trim(remainder);
g0 = g1; g1 = g;
end

g = trim(g);

% Find the zeros of the error polynomial on this galois field
evalPoly = polyval(g, alpha .^ (n-1 : -1 : 0));
error_pos = gf(find(evalPoly == 0), m);

% If no error position is found we return the received work, because
% basically is nothing that we could do and we return the received message
if isempty(error_pos)
decoded = orig_vals(1:k);
error_mag = [];
return;
end

% Prepare a linear system to solve the error polynomial and find the error
% magnitudes
size_error = length(error_pos);
Syndrome_Vals = Syndromes.x;
b(:, 1) = Syndrome_Vals(1:size_error);
for idx = 1 : size_error
e = alpha .^ (idx*(n-error_pos.x));
err = e.x;
er(idx, :) = err;
end

% Solve the linear system
error_mag = (gf(er, m, prim_poly) \ gf(b, m, prim_poly))';
% Put the error magnitude on the error vector
errors(error_pos.x) = error_mag.x;
% Bring this vector to the galois field
errors_gf = gf(errors, m, prim_poly);

% Now to fix the errors just add with the encoded code
decoded_gf = encoded(1:k) + errors_gf(1:k);
decoded = decoded_gf.x;

end

% Remove leading zeros from galois array
function gt = trim(g)
gx = g.x;
gt = gf(gx(find(gx, 1) : end), g.m, g.prim_poly);
end

len = length(x);
if (len<k)
end
end


## Notes

1. ^ Reed & Solomon (1960)
2. ^ D. Gorenstein and N. Zierler, "A class of cyclic linear error-correcting codes in p^m symbols," J. SIAM, vol. 9, pp. 207-214, June 1961
3. ^ Error Correcting Codes by W_Wesley_Peterson, 1961
4. ^ Yasuo Sugiyama, Masao Kasahara, Shigeichi Hirasawa, and Toshihiko Namekawa. A method for solving key equation for decoding Goppa codes. Information and Control, 27:87–99, 1975.
5. ^ Immink, K. A. S. (1994), "Reed–Solomon Codes and the Compact Disc", in Wicker, Stephen B.; Bhargava, Vijay K., Reed–Solomon Codes and Their Applications, IEEE Press, ISBN 978-0-7803-1025-4
6. ^ Lidl, Rudolf; Pilz, Günter (1999). Applied Abstract Algebra (2nd ed.). Wiley. p. 226.
7. ^ See Lin & Costello (1983, p. 171), for example.
8. ^ Pfender, Florian; Ziegler, Günter M. (September 2004), "Kissing Numbers, Sphere Packings, and Some Unexpected Proofs" (PDF), Notices of the American Mathematical Society, 51 (8): 873–883. Explains the Delsarte-Goethals-Seidel theorem as used in the context of the error correcting code for compact disc.
9. ^ D. Gorenstein and N. Zierler, ”A class of cyclic linear error-correcting codes in p^m symbols,” J. SIAM, vol. 9, pp. 207-214, June 1961
10. ^ Error Correcting Codes by W_Wesley_Peterson, 1961
11. ^ Shu Lin and Daniel J. Costello Jr, ”Error Control Coding” second edition, pp. 255-262, 1982, 2004
12. ^ Guruswami, V.; Sudan, M. (September 1999), "Improved decoding of Reed–Solomon codes and algebraic geometry codes", IEEE Transactions on Information Theory, 45 (6): 1757–1767, doi:10.1109/18.782097
13. ^ Koetter, Ralf; Vardy, Alexander (2003). "Algebraic soft-decision decoding of Reed–Solomon codes". IEEE Transactions on Information Theory. 49 (11): 2809–2825. doi:10.1109/TIT.2003.819332.