Package ptolemy.actor.lib.comm
Class HadamardCode
- java.lang.Object
-
- 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)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description 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
_triggered, output, trigger
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _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
Constructors Constructor Description HadamardCode(CompositeEntity container, java.lang.String name)
Construct an actor with the given container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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
_customTypeConstraints, prefire
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, 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
_addPort, _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, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, 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, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, 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.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
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
-
-
-
-
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.
-
-
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 classNamedObj
- 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 interfaceExecutable
- Overrides:
fire
in classSource
- 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 interfaceInitializable
- Overrides:
initialize
in classAtomicActor<TypedIOPort>
- 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 interfaceExecutable
- Overrides:
postfire
in classAtomicActor<TypedIOPort>
- Returns:
- True if execution can continue into the next iteration.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
-