<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Reed%E2%80%93Solomon_error_correction</id>
	<title>Reed–Solomon error correction - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://en.zaoniao.it/index.php?action=history&amp;feed=atom&amp;title=Reed%E2%80%93Solomon_error_correction"/>
	<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Reed%E2%80%93Solomon_error_correction&amp;action=history"/>
	<updated>2026-05-15T09:37:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.32.0</generator>
	<entry>
		<id>http://en.zaoniao.it/index.php?title=Reed%E2%80%93Solomon_error_correction&amp;diff=6592&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;&lt;amp/&gt; '''Reed–So 4}} (t 3 ''x''&lt;sup&gt;2&lt;/sup&gt; + 2 ''x'' + 1}}, then the codeword is calculated as follows. :&lt;math&gt;s_r(x) = p(x) \, x^t \mod g(x) = 547 x^3 + 738 x^2 + 442 x +...&quot;</title>
		<link rel="alternate" type="text/html" href="http://en.zaoniao.it/index.php?title=Reed%E2%80%93Solomon_error_correction&amp;diff=6592&amp;oldid=prev"/>
		<updated>2019-07-04T06:25:46Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;amp/&amp;gt; &amp;#039;&amp;#039;&amp;#039;Reed–So 4}} (t 3 &amp;#039;&amp;#039;x&amp;#039;&amp;#039;&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 2 &amp;#039;&amp;#039;x&amp;#039;&amp;#039; + 1}}, then the codeword is calculated as follows. :&amp;lt;math&amp;gt;s_r(x) = p(x) \, x^t \mod g(x) = 547 x^3 + 738 x^2 + 442 x +...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;amp/&amp;gt;&lt;br /&gt;
'''Reed–So 4}} (t 3 ''x''&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 2 ''x'' + 1}}, then the codeword is calculated as follows.&lt;br /&gt;
:&amp;lt;math&amp;gt;s_r(x) = p(x) \, x^t \mod g(x) = 547 x^3 + 738 x^2 + 442 x + 455&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;s(x) = p(x) \, x^t - s_r(x) = 3 x^6 + 2 x^5 + 1 x^4 + 382 x^3 + 191 x^2 + 487 x + 474&amp;lt;/math&amp;gt;&lt;br /&gt;
Errors in transmission might cause this to be received instead.&lt;br /&gt;
:&amp;lt;math&amp;gt;r(x) = s(x) + e(x) = 3 x^6 + 2 x^5 + 123 x^4 + 456 x^3 + 191 x^2 + 487 x + 474&amp;lt;/math&amp;gt;&lt;br /&gt;
The syndromes are calculated by evaluating ''r'' at powers of ''&amp;amp;alpha;''.&lt;br /&gt;
:&amp;lt;math&amp;gt;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&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;S_2 = r(3^2) = 637,\;S_3 = r(3^3) = 762,\;S_4 = r(3^4) = 925&amp;lt;/math&amp;gt;&lt;br /&gt;
To correct the errors, first use the [[Berlekamp–Massey algorithm#Berlekamp–Massey algorithm for fields|Berlekamp–Massey algorithm]] to calculate the error locator polynomial.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ''n''&lt;br /&gt;
! ''S''&amp;lt;sub&amp;gt;''n''+1&amp;lt;/sub&amp;gt;&lt;br /&gt;
! ''d''&lt;br /&gt;
! ''C''&lt;br /&gt;
! ''B''&lt;br /&gt;
! ''b''&lt;br /&gt;
! ''m''&lt;br /&gt;
|-&lt;br /&gt;
| 0 || 732 || 732 || 197 ''x'' + 1 || 1 || 732 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 1 || 637 || 846 || 173 ''x'' + 1 || 1 || 732 || 2&lt;br /&gt;
|-&lt;br /&gt;
| 2 || 762 || 412 || 634 ''x''&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 173 ''x'' + 1 || 173 ''x'' + 1 || 412 || 1&lt;br /&gt;
|-&lt;br /&gt;
| 3 || 925 || 576 || 329 ''x''&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 821 ''x'' + 1 || 173 ''x'' + 1 || 412 || 2&lt;br /&gt;
|}&lt;br /&gt;
The final value of ''C'' is the error locator polynomial, &amp;amp;Lambda;(''x''). The zeros can be found by trial substitution. They are ''x''&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt; = 757 = 3&amp;lt;sup&amp;gt;&amp;amp;minus;3&amp;lt;/sup&amp;gt; and ''x''&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; = 562 = 3&amp;lt;sup&amp;gt;&amp;amp;minus;4&amp;lt;/sup&amp;gt;, corresponding to the error locations. To calculate the error values, apply the [[Forney algorithm]].&lt;br /&gt;
:&amp;lt;math&amp;gt;\Omega(x) = S(x) \Lambda(x) \mod x^4 = 546 x + 732\,&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;\Lambda'(x) = 658 x + 821\,&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;e_1 = -\Omega(x_1)/\Lambda'(x_1) = -649/54 = 280 \times 843 = 74\,&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;e_2 = -\Omega(x_2)/\Lambda'(x_2) = 122\,&amp;lt;/math&amp;gt;&lt;br /&gt;
Subtracting ''e''&amp;lt;sub&amp;gt;1&amp;lt;/sub&amp;gt;''x''&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; and ''e''&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;''x''&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; from the received polynomial ''r'' reproduces the original codeword ''s''.&lt;br /&gt;
&lt;br /&gt;
=== Euclidean decoder ===&lt;br /&gt;
&lt;br /&gt;
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]] .&lt;br /&gt;
&lt;br /&gt;
Define S(x), &amp;amp;Lambda;(x), and &amp;amp;Omega;(x) for ''t'' syndromes and ''e'' errors:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt; S(x) = S_{t} x^{t-1} + S_{t-1} x^{t-2} + \cdots + S_2 x + S_1 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt; \Lambda(x) = \Lambda_{e} x^{e} + \Lambda_{e-1} x^{e-1} + \cdots + \Lambda_{1} x + 1&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt; \Omega(x) = \Omega_{e} x^{e} + \Omega_{e-1} x^{e-1} + \cdots + \Omega_{1} x + \Omega_{0}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The key equation is:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt; \Lambda(x) S(x) = Q(x) x^{t} + \Omega(x) &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For ''t'' = 6 and ''e'' = 3:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\begin{bmatrix}&lt;br /&gt;
\Lambda_3 S_6 &amp;amp; x^8 \\&lt;br /&gt;
\Lambda_2 S_6 + \Lambda_3 S_5 &amp;amp; x^7 \\&lt;br /&gt;
\Lambda_1 S_6 + \Lambda_2 S_5 + \Lambda_3 S_4 &amp;amp; x^6 \\&lt;br /&gt;
 S_6 + \Lambda_1 S_5 + \Lambda_2 S_4 + \Lambda_3 S_3 &amp;amp; x^5 \\&lt;br /&gt;
 S_5 + \Lambda_1 S_4 + \Lambda_2 S_3 + \Lambda_3 S_2 &amp;amp; x^4 \\&lt;br /&gt;
 S_4 + \Lambda_1 S_3 + \Lambda_2 S_2 + \Lambda_3 S_1 &amp;amp; x^3 \\&lt;br /&gt;
 S_3 + \Lambda_1 S_2 + \Lambda_2 S_1 &amp;amp; x^2 \\&lt;br /&gt;
 S_2 + \Lambda_1 S_1 &amp;amp; x \\&lt;br /&gt;
 S_1 &amp;amp; \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
=&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
Q_2 x^8 \\&lt;br /&gt;
Q_1 x^7 \\&lt;br /&gt;
Q_0 x^6 \\&lt;br /&gt;
0 \\&lt;br /&gt;
0 \\&lt;br /&gt;
0 \\&lt;br /&gt;
\Omega_2 x^2 \\&lt;br /&gt;
\Omega_1 x \\&lt;br /&gt;
\Omega_0 \\&lt;br /&gt;
\end{bmatrix}&lt;br /&gt;
&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The middle terms are zero due to the relationship between &amp;amp;Lambda; and syndromes.&lt;br /&gt;
&lt;br /&gt;
The extended Euclidean algorithm can find a series of polynomials of the form&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x) S(x) + B&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x) x&amp;lt;sup&amp;gt;t&amp;lt;/sup&amp;gt; = R&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x)&lt;br /&gt;
&lt;br /&gt;
where the degree of R decreases as i increases. Once the degree of R&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x) &amp;lt; t/2, then&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x) = &amp;amp;Lambda;(x)&lt;br /&gt;
&lt;br /&gt;
B&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x) = -Q(x)&lt;br /&gt;
&lt;br /&gt;
R&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(x) = &amp;amp;Omega;(x).&lt;br /&gt;
&lt;br /&gt;
B(x) and Q(x) don't need to be saved, so the algorithm becomes:&lt;br /&gt;
&lt;br /&gt;
:R&amp;lt;sub&amp;gt;−1&amp;lt;/sub&amp;gt; = x&amp;lt;sup&amp;gt;t&amp;lt;/sup&amp;gt;&lt;br /&gt;
:R&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt; = S(x)&lt;br /&gt;
:A&amp;lt;sub&amp;gt;−1&amp;lt;/sub&amp;gt; = 0&lt;br /&gt;
:A&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt; = 1&lt;br /&gt;
:i = 0&lt;br /&gt;
:while degree of R&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; &amp;gt;= t/2&lt;br /&gt;
::i = i + 1&lt;br /&gt;
::Q = R&amp;lt;sub&amp;gt;i-2&amp;lt;/sub&amp;gt; / R&amp;lt;sub&amp;gt;i-1&amp;lt;/sub&amp;gt;&lt;br /&gt;
::R&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = R&amp;lt;sub&amp;gt;i-2&amp;lt;/sub&amp;gt; - Q R&amp;lt;sub&amp;gt;i-1&amp;lt;/sub&amp;gt;&lt;br /&gt;
::A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; = A&amp;lt;sub&amp;gt;i-2&amp;lt;/sub&amp;gt; - Q A&amp;lt;sub&amp;gt;i-1&amp;lt;/sub&amp;gt; &lt;br /&gt;
to set low order term of &amp;amp;Lambda;(x) to 1, divide &amp;amp;Lambda;(x) and &amp;amp;Omega;(x) by A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(0):&lt;br /&gt;
:&amp;amp;Lambda;(x) = A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; / A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(0)&lt;br /&gt;
:&amp;amp;Omega;(x) = R&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt; / A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(0)&lt;br /&gt;
&lt;br /&gt;
A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;(0) is the constant (low order) term of A&amp;lt;sub&amp;gt;i&amp;lt;/sub&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Example ====&lt;br /&gt;
&lt;br /&gt;
Using the same data as the Berlekamp Massey example above:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! ''i''&lt;br /&gt;
! R&amp;lt;sub&amp;gt;''i''&amp;lt;/sub&amp;gt;&lt;br /&gt;
! A&amp;lt;sub&amp;gt;''i''&amp;lt;/sub&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| -1&lt;br /&gt;
| 001 x&amp;lt;sup&amp;gt;4&amp;lt;/sup&amp;gt; + 000 x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; + 000 x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 000 x + 000&lt;br /&gt;
| 000&lt;br /&gt;
|-&lt;br /&gt;
| 0&lt;br /&gt;
| 925 x&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt; + 762 x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 637 x + 732&lt;br /&gt;
| 001&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
| 683 x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 676 x + 024&lt;br /&gt;
| 697 x + 396 &lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
| 673 x + 596&lt;br /&gt;
| 608 x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 704 x + 544 &lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
:&amp;amp;Lambda;(x) = A&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; / 544 = 329 x&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; + 821 x + 001 &lt;br /&gt;
:&amp;amp;Omega;(x) = R&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; / 544 = 546 x + 732&lt;br /&gt;
&lt;br /&gt;
=== Decoder using discrete Fourier transform ===&lt;br /&gt;
&lt;br /&gt;
A discrete Fourier transform can be used for decoding. 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).&lt;br /&gt;
&lt;br /&gt;
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:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;R_j = E_j = S_j = r(\alpha^j)&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;for \ 1 \le j \le t&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Use &amp;lt;math&amp;gt;R_1&amp;lt;/math&amp;gt; through &amp;lt;math&amp;gt;R_t&amp;lt;/math&amp;gt; as syndromes (they're the same) and generate the error locator polynomial using the methods from any of the above decoders.&lt;br /&gt;
&lt;br /&gt;
Let v = number of errors. Generate E(x) using the known coefficients &amp;lt;math&amp;gt;E_1&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;E_t&amp;lt;/math&amp;gt;, the error locator polynomial, and these formulas&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;E_0 = - \frac{1}{\sigma_v}(E_{v} + \sigma_1 E_{v-1} + \cdots + \sigma_{v-1} E_{1})&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;E_j = -(\sigma_1 E_{j-1} + \sigma_2 E_{j-2} + \cdots + \sigma_v E_{j-v})&amp;lt;/math&amp;gt;&lt;br /&gt;
:&amp;lt;math&amp;gt;for \ t &amp;lt; j &amp;lt; n&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then calculate C(x) = R(x) - E(x) and take the inverse transform of C(x) to produce c(x).&lt;br /&gt;
&lt;br /&gt;
===Decoding beyond the error-correction bound===&lt;br /&gt;
&lt;br /&gt;
The [[Singleton bound]] states that the minimum distance ''d'' of a linear block code of size (''n'',''k'') is upper-bounded by ''n''&amp;amp;nbsp;&amp;amp;minus;&amp;amp;nbsp;''k''&amp;amp;nbsp;+&amp;amp;nbsp;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''&amp;amp;nbsp;&amp;amp;minus;&amp;amp;nbsp;''k''&amp;amp;nbsp;+&amp;amp;nbsp;1)/2⌋ errors. However, this error-correction bound is not exact.&lt;br /&gt;
&lt;br /&gt;
In 1999, [[Madhu Sudan]] and [[Venkatesan Guruswami]] at MIT published &amp;quot;Improved Decoding of Reed–Solomon and Algebraic-Geometry Codes&amp;quot; introducing an algorithm that allowed for the correction of errors beyond half the minimum distance of the code. It applies to Reed–Solomon codes and more generally to [[algebraic geometric code]]s. This algorithm produces a list of codewords (it is a [[list-decoding]] algorithm) and is based on interpolation and factorization of polynomials over &amp;lt;math&amp;gt;GF(2^m)&amp;lt;/math&amp;gt; and its extensions.&lt;br /&gt;
&lt;br /&gt;
===Soft-decoding===&lt;br /&gt;
&lt;br /&gt;
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 [[low-density parity-check code|LDPC]] and [[turbo code]]s, which employ iterated [[soft-decision decoding|soft-decision]] belief propagation decoding methods to achieve error-correction performance close to the [[Shannon limit|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.&lt;br /&gt;
In 2016, Steven J. Franke and Joseph H. Taylor published a novel soft-decision decoder.&lt;br /&gt;
&lt;br /&gt;
=== Matlab Example ===&lt;br /&gt;
&lt;br /&gt;
==== Encoder ====&lt;br /&gt;
Here we present a simple Matlab implementation for an encoder.&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
function [ encoded ] = rsEncoder( msg, m, prim_poly, n, k )&lt;br /&gt;
 %RSENCODER Encode message with the Reed-Solomon algorithm&lt;br /&gt;
 % m is the number of bits per symbol&lt;br /&gt;
 % prim_poly: Primitive polynomial p(x). Ie for DM is 301&lt;br /&gt;
 % k is the size of the message&lt;br /&gt;
 % n is the total size (k+redundant)&lt;br /&gt;
 % Example: msg = uint8('Test')&lt;br /&gt;
 % enc_msg = rsEncoder(msg, 8, 301, 12, numel(msg));&lt;br /&gt;
 &lt;br /&gt;
 % Get the alpha&lt;br /&gt;
 alpha = gf(2, m, prim_poly);&lt;br /&gt;
 &lt;br /&gt;
 % Get the Reed-Solomon generating polynomial g(x)&lt;br /&gt;
 g_x = genpoly(k, n, alpha);&lt;br /&gt;
 &lt;br /&gt;
 % Multiply the information by X^(n-k), or just pad with zeros at the end to&lt;br /&gt;
 % get space to add the redundant information&lt;br /&gt;
 msg_padded = gf([msg zeros(1, n-k)], m, prim_poly);&lt;br /&gt;
 &lt;br /&gt;
 % Get the remainder of the division of the extended message by the &lt;br /&gt;
 % Reed-Solomon generating polynomial g(x)&lt;br /&gt;
 [~, reminder] = deconv(msg_padded, g_x);&lt;br /&gt;
&lt;br /&gt;
 % Now return the message with the redundant information&lt;br /&gt;
 encoded = msg_padded - reminder;&lt;br /&gt;
&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
% Find the Reed-Solomon generating polynomial g(x), by the way this is the&lt;br /&gt;
% same as the rsgenpoly function on matlab&lt;br /&gt;
function g = genpoly(k, n, alpha)&lt;br /&gt;
 g = 1;&lt;br /&gt;
 % A multiplication on the galois field is just a convolution&lt;br /&gt;
 for k = mod(1 : n-k, n)&lt;br /&gt;
 g = conv(g, [1 alpha .^ (k)]);&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Decoder ====&lt;br /&gt;
Now the decoding part:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;matlab&amp;quot;&amp;gt;&lt;br /&gt;
function [ decoded, error_pos, error_mag, g, S ] = rsDecoder( encoded, m, prim_poly, n, k )&lt;br /&gt;
 %RSDECODER Decode a Reed-Solomon encoded message&lt;br /&gt;
 % Example:&lt;br /&gt;
 % [dec, ~, ~, ~, ~] = rsDecoder(enc_msg, 8, 301, 12, numel(msg))&lt;br /&gt;
 max_errors = floor((n-k)/2);&lt;br /&gt;
 orig_vals = encoded.x;&lt;br /&gt;
 % Initialize the error vector&lt;br /&gt;
 errors = zeros(1, n);&lt;br /&gt;
 g = [];&lt;br /&gt;
 S = [];&lt;br /&gt;
 &lt;br /&gt;
 % Get the alpha&lt;br /&gt;
 alpha = gf(2, m, prim_poly);&lt;br /&gt;
 &lt;br /&gt;
 % Find the syndromes (Check if dividing the message by the generator&lt;br /&gt;
 % polynomial the result is zero)&lt;br /&gt;
 Synd = polyval(encoded, alpha .^ (1:n-k));&lt;br /&gt;
 Syndromes = trim(Synd);&lt;br /&gt;
 &lt;br /&gt;
 % If all syndromes are zeros (perfectly divisible) there are no errors&lt;br /&gt;
 if isempty(Syndromes.x)&lt;br /&gt;
 decoded = orig_vals(1:k);&lt;br /&gt;
 error_pos = [];&lt;br /&gt;
 error_mag = [];&lt;br /&gt;
 g = [];&lt;br /&gt;
 S = Synd;&lt;br /&gt;
 return;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 % Prepare for the euclidean algorithm (Used to find the error locating&lt;br /&gt;
 % polynomials)&lt;br /&gt;
 r0 = [1, zeros(1, 2*max_errors)]; r0 = gf(r0, m, prim_poly); r0 = trim(r0);&lt;br /&gt;
 size_r0 = length(r0);&lt;br /&gt;
 r1 = Syndromes;&lt;br /&gt;
 f0 = gf([zeros(1, size_r0-1) 1], m, prim_poly);&lt;br /&gt;
 f1 = gf(zeros(1, size_r0), m, prim_poly);&lt;br /&gt;
 g0 = f1; g1 = f0;&lt;br /&gt;
 &lt;br /&gt;
 % Do the euclidean algorithm on the polynomials r0(x) and Syndromes(x) in&lt;br /&gt;
 % order to find the error locating polynomial&lt;br /&gt;
 while true&lt;br /&gt;
 % Do a long division&lt;br /&gt;
 [quotient, remainder] = deconv(r0, r1); &lt;br /&gt;
 % Add some zeros&lt;br /&gt;
 quotient = pad(quotient, length(g1));&lt;br /&gt;
 &lt;br /&gt;
 % Find quotient*g1 and pad&lt;br /&gt;
 c = conv(quotient, g1);&lt;br /&gt;
 c = trim(c);&lt;br /&gt;
 c = pad(c, length(g0));&lt;br /&gt;
 &lt;br /&gt;
 % Update g as g0-quotient*g1&lt;br /&gt;
 g = g0 - c;&lt;br /&gt;
 &lt;br /&gt;
 % Check if the degree of remainder(x) is less than max_errors&lt;br /&gt;
 if all(remainder(1:end - max_errors) == 0)&lt;br /&gt;
 break;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 % Update r0, r1, g0, g1 and remove leading zeros&lt;br /&gt;
 r0 = trim(r1); r1 = trim(remainder);&lt;br /&gt;
 g0 = g1; g1 = g;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 % Remove leading zeros&lt;br /&gt;
 g = trim(g);&lt;br /&gt;
 &lt;br /&gt;
 % Find the zeros of the error polynomial on this galois field&lt;br /&gt;
 evalPoly = polyval(g, alpha .^ (n-1 : -1 : 0));&lt;br /&gt;
 error_pos = gf(find(evalPoly == 0), m);&lt;br /&gt;
 &lt;br /&gt;
 % If no error position is found we return the received work, because&lt;br /&gt;
 % basically is nothing that we could do and we return the received message&lt;br /&gt;
 if isempty(error_pos)&lt;br /&gt;
 decoded = orig_vals(1:k);&lt;br /&gt;
 error_mag = [];&lt;br /&gt;
 return;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 % Prepare a linear system to solve the error polynomial and find the error&lt;br /&gt;
 % magnitudes&lt;br /&gt;
 size_error = length(error_pos);&lt;br /&gt;
 Syndrome_Vals = Syndromes.x;&lt;br /&gt;
 b(:, 1) = Syndrome_Vals(1:size_error);&lt;br /&gt;
 for idx = 1 : size_error&lt;br /&gt;
 e = alpha .^ (idx*(n-error_pos.x));&lt;br /&gt;
 err = e.x;&lt;br /&gt;
 er(idx, :) = err;&lt;br /&gt;
 end&lt;br /&gt;
 &lt;br /&gt;
 % Solve the linear system&lt;br /&gt;
 error_mag = (gf(er, m, prim_poly) \ gf(b, m, prim_poly))';&lt;br /&gt;
 % Put the error magnitude on the error vector&lt;br /&gt;
 errors(error_pos.x) = error_mag.x;&lt;br /&gt;
 % Bring this vector to the galois field&lt;br /&gt;
 errors_gf = gf(errors, m, prim_poly);&lt;br /&gt;
 &lt;br /&gt;
 % Now to fix the errors just add with the encoded code&lt;br /&gt;
 decoded_gf = encoded(1:k) + errors_gf(1:k);&lt;br /&gt;
 decoded = decoded_gf.x;&lt;br /&gt;
 &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
% Remove leading zeros from galois array&lt;br /&gt;
function gt = trim(g)&lt;br /&gt;
 gx = g.x;&lt;br /&gt;
 gt = gf(gx(find(gx, 1) : end), g.m, g.prim_poly);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
% Add leading zeros&lt;br /&gt;
function xpad = pad(x,k)&lt;br /&gt;
 len = length(x);&lt;br /&gt;
 if (len&amp;lt;k)&lt;br /&gt;
 xpad = [zeros(1, k-len) x];&lt;br /&gt;
 end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
* [[BCH code]]&lt;br /&gt;
* [[Chien search]]&lt;br /&gt;
* [[Berlekamp&amp;amp;ndash;Massey algorithm]]&lt;br /&gt;
* [[Forward error correction]]&lt;br /&gt;
* [[Berlekamp–Welch algorithm]]&lt;br /&gt;
* [[Folded Reed–Solomon code]]&lt;br /&gt;
&lt;br /&gt;
==Source==&lt;br /&gt;
&lt;br /&gt;
[http://wikipedia.org/ http://wikipedia.org/]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>
		
	</entry>
</feed>