Class HadamardCode

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class HadamardCode
    extends Source
    Produce a Hadamard codeword by selecting a row from a Hadamard matrix. The log base 2 of the matrix dimension is given by the log2Length parameter, which should be a non-negative integer smaller than 32. The row index is given by the index parameter or by the associated index port, which should be a non-negative integer smaller than the matrix dimension. If the index changes value when the actor is in the middle of producing a sequence of Hadamard codeword, the actor will take on the new index value, and start to produce the new codeword from the beginning.

    A Hadamard matrix is defined in the following way:

    H1 = [1, 1; 1, -1]

    Hn+1 = [Hn, Hn; Hn, -Hn]

    where n is a positive integer. Therefore, Hn is a 2n by 2n square matrix. The codeword length is 2n.

    The actor produces Hadamard codeword in booleans. Therefore, 1 is treated as "true" and -1 is treated as "false".

    Since:
    Ptolemy II 3.0
    Version:
    $Id$
    Author:
    Edward A. Lee and Ye Zhou
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Red (eal)
    • Field Detail

      • index

        public PortParameter index
        Index of the code to generate. Codes with different indexes are orthogonal. This is an int with default 0. It should not exceed length-1, where length = 2^log2Length.
      • log2Length

        public Parameter log2Length
        Log base 2 of the length of the code. This is an integer with default 5. It is required to be greater than 0.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        If the attribute being changed is log2Length, then calculate the new Hadamard sequence; if it is index, then verify that is non-negative and check if it is different from the previous value.
        Overrides:
        attributeChanged in class NamedObj
        Parameters:
        attribute - The attribute that changed.
        Throws:
        IllegalActionException - If index is negative or log2Length is not strictly positive.
      • fire

        public void fire()
                  throws IllegalActionException
        Read from the associated index port if there is any input. The actor compares the new index value with the old one. If the value changes, the actor will interrupt the current output sequence, compute the new Hadamard codeword, and send it to the output in sequence. If the index remains constant when it reaches the end of a Hadamard codeword sequence, the next iteration will restart from the beginning of that codeword.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class Source
        Throws:
        IllegalActionException - If index is out of range.
      • postfire

        public boolean postfire()
                         throws IllegalActionException
        Description copied from class: AtomicActor
        Return true, unless stop() has been called, in which case, return false. Derived classes override this method to define operations to be performed at the end of every iteration of its execution, after one invocation of the prefire() method and any number of invocations of the fire() method. This method typically wraps up an iteration, which may involve updating local state. In derived classes, this method returns false to indicate that this actor should not be fired again.
        Specified by:
        postfire in interface Executable
        Overrides:
        postfire in class AtomicActor<TypedIOPort>
        Returns:
        True if execution can continue into the next iteration.
        Throws:
        IllegalActionException - Not thrown in this base class.