gov.nasa.gsfc.drl.rtstps.core
Class ReedSolomonDecoder

java.lang.Object
  extended by gov.nasa.gsfc.drl.rtstps.core.RtStpsNode
      extended by gov.nasa.gsfc.drl.rtstps.core.FrameSenderNode
          extended by gov.nasa.gsfc.drl.rtstps.core.ReedSolomonDecoder
All Implemented Interfaces:
FrameReceiver, Receiver, Sender, java.lang.Cloneable

public class ReedSolomonDecoder
extends FrameSenderNode
implements FrameReceiver, Sender, java.lang.Cloneable

This class does Reed Solomon error detection and correction on frames. It sends frames to a target FrameReceiver. Corrected issues related to corrections in August 2007.


Nested Class Summary
static class ReedSolomonDecoder.Setup
          This class defines setup fields that are commonly associated with a Reed Solomon block decoder component.
 
Field Summary
private  int actualLength
           
private  int[] antilog
           
private static int[] ANTILOG
           
static java.lang.String CLASSNAME
          This is a class name for this STPS node type, which is also the element name.
private  int codewordDistance
           
private  int codewordLength
          number of symbols in field, 2 ** bitsPerSymbol - 1
private static int CORRECTED
           
private  int[] correctionPolynomial
           
private  int[] DUAL_ANTILOG
           
private  int[] errorLocations
           
private  int[] errorMagnitudes
           
private  int frameLength
           
private  int[] log
           
private  int[] magnitudePolynomial
           
private static int OK
           
private  int parityLength
           
private  ReedSolomonDecoder.Setup setup
           
private  int[] sigma
           
private  int[] sigmab
           
private  int skipBytes
           
private  int[] syndrome
          The syndrome polynomial
private static int UNCORRECTABLE
           
 
Fields inherited from class gov.nasa.gsfc.drl.rtstps.core.FrameSenderNode
output
 
Fields inherited from class gov.nasa.gsfc.drl.rtstps.core.RtStpsNode
linkName, statusItemList, typeName
 
Constructor Summary
ReedSolomonDecoder()
          Create a Reed Solomon decoder node.
 
Method Summary
private  int computeErrorLocations(int degreeOfSigma)
          Calculate the roots of the error location polynomial by using the Chien search.
private  int computeErrorLocatorPolynomial()
          This is the Berlekamp Algorithm.
private  int computeErrorMagnitudes(int errors)
          This function uses the Forney Algorithm to calculate the error magnitudes.
private  boolean computeSyndrome(byte[] data, int level)
          This function implements the FFT-like syndrome calculation.
private  void correctSymbols(byte[] data, int level, int errorCount)
          This function xor's the error magnitudes with the appropriate symbols in error, thus correcting all symbols in error.
private  int decode(byte[] data)
          Do Reed Solomon decoding on one frame.
 void finishSetup(Configuration configuration)
          Finish the setup.
 int getParityLength()
          Get the parity length in bytes, which is the full parity length for all interleaves.
 void load(org.w3c.dom.Element element, Configuration configuration)
          Set up this stps node with a configuration.
 void putFrame(Frame frame)
          Give a frame to this FrameReceiver.
 void putFrames(Frame[] frames)
          Give an array of frames to this FrameReceiver.
private  void setAnnotation(int state, Frame frame)
          Set a frame's Reed Solomon annotation and mark the frame for deletion if necessary.
 
Methods inherited from class gov.nasa.gsfc.drl.rtstps.core.FrameSenderNode
addReceiver, flush, setOutputIsRequired
 
Methods inherited from class gov.nasa.gsfc.drl.rtstps.core.RtStpsNode
clear, clone, getElementName, getLinkName, getStatusItems, setLinkName, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.nasa.gsfc.drl.rtstps.core.FrameReceiver
flush, getLinkName
 
Methods inherited from interface gov.nasa.gsfc.drl.rtstps.core.Sender
addReceiver
 

Field Detail

CLASSNAME

public static final java.lang.String CLASSNAME
This is a class name for this STPS node type, which is also the element name. It is not necessarily the link name, which is the name of one particular object.

See Also:
Constant Field Values

OK

private static final int OK
See Also:
Constant Field Values

CORRECTED

private static final int CORRECTED
See Also:
Constant Field Values

UNCORRECTABLE

private static final int UNCORRECTABLE
See Also:
Constant Field Values

ANTILOG

private static final int[] ANTILOG

DUAL_ANTILOG

private int[] DUAL_ANTILOG

codewordLength

private int codewordLength
number of symbols in field, 2 ** bitsPerSymbol - 1


actualLength

private int actualLength

syndrome

private int[] syndrome
The syndrome polynomial


frameLength

private int frameLength

skipBytes

private int skipBytes

codewordDistance

private int codewordDistance

parityLength

private int parityLength

sigma

private int[] sigma

sigmab

private int[] sigmab

correctionPolynomial

private int[] correctionPolynomial

errorMagnitudes

private int[] errorMagnitudes

errorLocations

private int[] errorLocations

log

private int[] log

antilog

private int[] antilog

magnitudePolynomial

private int[] magnitudePolynomial

setup

private ReedSolomonDecoder.Setup setup
Constructor Detail

ReedSolomonDecoder

public ReedSolomonDecoder()
Create a Reed Solomon decoder node.

Method Detail

load

public void load(org.w3c.dom.Element element,
                 Configuration configuration)
          throws RtStpsException
Set up this stps node with a configuration.

Specified by:
load in class FrameSenderNode
Throws:
RtStpsException

finishSetup

public void finishSetup(Configuration configuration)
                 throws RtStpsException
Finish the setup. When this method is called, you may assume all nodes have been created and exist by name in the map, and all standard links have been resolved. This is a last chance to prepare for data flow.

Overrides:
finishSetup in class FrameSenderNode
Throws:
RtStpsException

getParityLength

public final int getParityLength()
Get the parity length in bytes, which is the full parity length for all interleaves. Do not use this method until after this object has been loaded.


putFrames

public void putFrames(Frame[] frames)
               throws RtStpsException
Give an array of frames to this FrameReceiver.

Specified by:
putFrames in interface FrameReceiver
Throws:
RtStpsException

putFrame

public void putFrame(Frame frame)
              throws RtStpsException
Give a frame to this FrameReceiver.

Specified by:
putFrame in interface FrameReceiver
Throws:
RtStpsException

setAnnotation

private void setAnnotation(int state,
                           Frame frame)
Set a frame's Reed Solomon annotation and mark the frame for deletion if necessary.


decode

private int decode(byte[] data)
Do Reed Solomon decoding on one frame.
 1) Calculate the syndrome vector from the received RS codeword.
 2) Calculate the coefficients of the error locator polynomial.
 3) Calculate the roots of the error locator polynomial.
 4) Calculate the error magnitudes.
 5) Correct the symbols in error with the previously calculated
    information.
 <\pre>
 Polynomial coefficients are stored P[0] = a*X ... P[n] = z*X


computeSyndrome

private boolean computeSyndrome(byte[] data,
                                int level)
This function implements the FFT-like syndrome calculation. Reed Solomon Codes define the symbol ordering in the opposite direction that the data symbols are received.
 R_n-1 = r[0]
 R_n-2 = r[1]
 ...
 R1   = r[n-2]
 R0   = r[n-1]

 For CCSDS:
 R254 = r[0]
 R253 = r[1]
 ...
 R1   = r[253]
 R0   = r[254]

 Recursive syndrome formula.
                        (mo + i)                  (mo + i)
 Si = ((...(R[n-1] * gamma        + R[n-2]) * gamma          +
                 (mo + i)
     ...) * gamma         + R[0])

                   POA
 Where gamma = alpha    , therefore powerOfAlpha = (POA * (mo + i))
 and
 0 <= i <= (d - 2) = (2t - 1)
 and
 n = 2**bitsPerSymbol - 1, bitsPerSymbol = number of bits per symbol
 
This function is the most important one, since it is called for each frame. It is the first step in the decoding process, and it determines if there are errors in the data.

Parameters:
data - The frame data including the sync pattern and parity.
level - The current interleave level.
Returns:
true if it detects an error or false otherwise.

computeErrorLocatorPolynomial

private int computeErrorLocatorPolynomial()
This is the Berlekamp Algorithm. This algorithm always finds the shortest feedback shift register that generates the first 2t (32 for CCSDS) terms of S(z), the syndrome.

This algorithm finds the solution of the key equation: [sigma(z)*syndrome(z)] = 0 The syndrome is given, so this algorithm finds sigma(z) of minimum degree. This is the same problem as finding the minimum-length shift register, which generates the first 2t terms of syndrome(z), which will predict s[1] from s[0] and so on. For each new syndrome symbol, the algorithm tests to see whether the current correction polynomial will predict this symbol correctly. If so, the correction polynomial is left unchanged and the correction term is modified by multiplying by z. If the current correction polynomial fails, then it is modified by adding the correction term. One then checks to determine if the new register length has increased. If it has not, then the correction polynomial that is currently being maintained is at least as good a choice as any other. If the length of the new register increases, then the previous correction polynomial becomes the better choice since the oldest symbol associated with this register must have a higher index than the oldest symbol associated with the current correction term.

Returns:
The degree of the error location polynomial.

computeErrorLocations

private int computeErrorLocations(int degreeOfSigma)
Calculate the roots of the error location polynomial by using the Chien search.
 Solve:
                          i                 poa
 sigma(x): where x = gamma and gamma = alpha    , and
 vf_end <= i <= (n - 1), n = 2**bitsPerSymbol - 1,
 bitsPerSymbol = number of bits per symbol,
 
and vf_end = the first location in the received vector following the virtual fill symbols. I start the Chien Search at vf_end since there is no point trying to find errors in the virtual fill symbols where errors will never exist. i An error location is found for each value of gamma that makes sigma evaluate to 0.

Returns:
The number of errors detected or UNCORRECTABLE if the number of errors is greater than degreeOfSigma.

computeErrorMagnitudes

private int computeErrorMagnitudes(int errors)
This function uses the Forney Algorithm to calculate the error magnitudes. It first calculates magnitudePolynomial(X){magnitudePolynomial(X) is the error magnitude polynomial}:
                                                              2
 magnitudePolynomial(X) = 1 + (s[1]+sigma[1])*X +
      (s[2]+s[1]*sigma[1]+sigma[2])*X + ...
                                                                v
 + (s[v] + sigma[1]*s[v-1] + ... + sigma[v-1]*s[1] + sigma[v])*X
 Where v = number of errors detected

         n-l
 If gamma    is an error-location number, then the error value
 at location n-l is given by:

              -(1-mo)l         l
         gamma        * magnitudePolynomial(gamma )
 e    = ------------------------
  n-l         l               l
         gamma  * sigma'(gamma )

                    POA
 Where gamma = alpha    and
 sigma'(X) is the derivative of sigma(X) and is given by:

                                  2                     2i
 sigma'(X) = sigma[1] + sigma[3]*X + ... + sigma[2i+1]*X  + ...
 0 <= i <= floor((t-1)/2)
 


correctSymbols

private void correctSymbols(byte[] data,
                            int level,
                            int errorCount)
This function xor's the error magnitudes with the appropriate symbols in error, thus correcting all symbols in error.

Parameters:
data - The data vector.
level - Interleave level
errorCount - Number of correctable errors