ptolemy.actor.lib.comm
Class HadamardCode

java.lang.Object
  extended byptolemy.kernel.util.NamedObj
      extended byptolemy.kernel.InstantiableNamedObj
          extended byptolemy.kernel.Entity
              extended byptolemy.kernel.ComponentEntity
                  extended byptolemy.actor.AtomicActor
                      extended byptolemy.actor.TypedAtomicActor
                          extended byptolemy.actor.lib.Source
                              extended byptolemy.actor.lib.comm.HadamardCode
All Implemented Interfaces:
ptolemy.actor.Actor, ptolemy.kernel.util.Changeable, java.lang.Cloneable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.actor.Executable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Nameable, java.io.Serializable, ptolemy.actor.TypedActor

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,v 1.20 2004/04/13 03:01:35 cxh Exp $
Author:
Edward A. Lee and Rachel Zhou
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 PortParameter index
          Index of the code to generate.
 ptolemy.data.expr.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
_stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
HadamardCode(ptolemy.kernel.CompositeEntity container, java.lang.String name)
          Construct an actor with the given container and name.
 
Method Summary
 void attributeChanged(ptolemy.kernel.util.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()
           
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort, typeConstraintList
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, clone, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, iterate, newReceiver, outputPortList, prefire, preinitialize, pruneDependencies, removeDependency, setContainer, stop, stopFire, terminate, wrapup
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName, validateSettables
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, getAttribute, getAttributes, getChangeListeners, getClassName, getDerivedLevel, getDerivedList, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setModelErrorHandler, setPersistent, setSource, toplevel, toString, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
getDirector, getExecutiveDirector, getFunctionDependency, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
iterate, prefire, preinitialize, stop, stopFire, terminate, wrapup
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getFullName, getName, getName
 

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 ptolemy.data.expr.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.

Constructor Detail

HadamardCode

public HadamardCode(ptolemy.kernel.CompositeEntity container,
                    java.lang.String name)
             throws ptolemy.kernel.util.NameDuplicationException,
                    ptolemy.kernel.util.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:
ptolemy.kernel.util.IllegalActionException - If the entity cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

attributeChanged

public void attributeChanged(ptolemy.kernel.util.Attribute attribute)
                      throws ptolemy.kernel.util.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.

Throws:
ptolemy.kernel.util.IllegalActionException - If index is negative or log2Length is not strictly positive.

fire

public void fire()
          throws ptolemy.kernel.util.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 ptolemy.actor.Executable
Overrides:
fire in class Source
Throws:
ptolemy.kernel.util.IllegalActionException - If index is out of range.

initialize

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

Throws:
ptolemy.kernel.util.IllegalActionException - If there is no director.

postfire

public boolean postfire()
                 throws ptolemy.kernel.util.IllegalActionException
Throws:
ptolemy.kernel.util.IllegalActionException