ptolemy.actor.lib.comm
Class HadamardCode

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.lib.Source
                              extended by ptolemy.actor.lib.comm.HadamardCode
All Implemented Interfaces:
java.io.Serializable, 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: HadamardCode.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee and Ye Zhou
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
 
Field Summary
private  int _index
           
private  int _latestIndex
           
private  int _previousIndex
           
private  boolean[] _row
           
private static boolean[] _row0
           
private static boolean[] _row1
           
private  boolean _rowValueInvalid
           
 PortParameter index
          Index of the code to generate.
 Parameter log2Length
          Log base 2 of the length of the code.
 
Fields inherited from class ptolemy.actor.lib.Source
output, trigger
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
HadamardCode(CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
private  boolean[] _calculateRow(int matrixDimension, int index)
          Calculate Hardmard row given by the Hadamard matrix dimension and the row index.
 void attributeChanged(Attribute attribute)
          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.
 void fire()
          Read from the associated index port if there is any input.
 void initialize()
          Initialize the actor by resetting the index counter to begin at the beginning of the Hadamard sequence.
 boolean postfire()
          Return true, unless stop() has been called, in which case, return false.
 
Methods inherited from class ptolemy.actor.lib.Source
prefire
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

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.


_index

private int _index

_previousIndex

private int _previousIndex

_latestIndex

private int _latestIndex

_row

private boolean[] _row

_row0

private static boolean[] _row0

_row1

private static boolean[] _row1

_rowValueInvalid

private transient boolean _rowValueInvalid
Constructor Detail

HadamardCode

public HadamardCode(CompositeEntity container,
                    java.lang.String name)
             throws NameDuplicationException,
                    IllegalActionException
Construct an actor with the given container and name. The output and trigger ports are also constructed.

Parameters:
container - The container.
name - The name of this actor.
Throws:
IllegalActionException - If the entity cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
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.

initialize

public void initialize()
                throws IllegalActionException
Initialize the actor by resetting the index counter to begin at the beginning of the Hadamard sequence.

Specified by:
initialize in interface Initializable
Overrides:
initialize in class AtomicActor
Throws:
IllegalActionException - If there is no director.

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
Returns:
True if execution can continue into the next iteration.
Throws:
IllegalActionException - Not thrown in this base class.

_calculateRow

private boolean[] _calculateRow(int matrixDimension,
                                int index)
Calculate Hardmard row given by the Hadamard matrix dimension and the row index. The method computes iteratively by degrading the matrix dimension into half, until it reaches H1.

Parameters:
matrixDimension - Hadamard matrix dimension.
index - Row index.
Returns:
Desired Hadamard row.