Class Waveform
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,Executable
,FiringsRecordable
,Initializable
,TimedActor
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class Waveform extends DiscreteClock
This actor produces a periodic continuous-time signal defined by a periodic sequence of samples and an interpolation method. The interpolation parameter specifies the interpolation method, which is either "linear", which indicates linear interpolation, or "hermite", which indicates third order interpolation based on the Hermite curves in chapter 11 of "Computer Graphic, Principles and Practice", by Foley, van Dam, Feiner and Hughes, 2nd ed. in C, 1996. Interpolation is calculated assuming that the waveform is periodic.At the beginning of each time interval of length given by period, starting from the time at which initialize() is invoked, this actor initiates a continuous output that passes through the values given by values at the time offsets into the period given by offsets. These parameters contain arrays, which are required to have the same length. The offsets array contains doubles, which must be nondecreasing and nonnegative, or an exception will be thrown when it is set.
You can provide a finite stopTime. Upon reaching that stop time, postfire() returns false, which requests that the director not fire this actor again. The output will be absent after that time. The clock can also be started and stopped repeatedly during an execution. A token at the start input will start the clock at the beginning of a period. A token at the stop input will stop the clock, if it is still running. If both start and stop are received simultaneously, then the clock will be stopped. When the clock is stopped, the output is absent.
The values parameter by default contains the array {1.0, -1.0}. The default offsets array is {0.0, 1.0}. The default period is 2.0. This results in a triangle wave (for linear interpolation) and a smooth sinusoid-like waveform (for hermite interpolation).
The type of the output is double.
If two offsets are equal, or if one is equal to the period, then two events will be produced at the same time, but with different microsteps. This will cause strange effects with hermite interpolation, and hence is not recommended. But it can sometimes be useful with linear interpolation to get discontinuous outputs.
If the period is changed at any time, either by provided by an input or by changing the parameter, then the new period will take effect immediately if the new period is provided at the same time (including the microstep) that the current cycle starts, or after the current cycle completes otherwise.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Sarah Packman, Yuhong Xiong, Edward A. Lee
- See Also:
Interpolation
- Pt.AcceptedRating:
- Yellow (yuhong)
- Pt.ProposedRating:
- Yellow (yuhong)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description StringParameter
interpolation
The interpolation method, which must be "linear" or "hermite".-
Fields inherited from class ptolemy.actor.lib.DiscreteClock
_cycleCount, _cycleStartTime, _enabled, _firstOutputProduced, _nextOutputIndex, _nextOutputTime, _offsets, _phase, offsets, period, start, stop, values
-
Fields inherited from class ptolemy.actor.lib.TimedSource
stopTime, stopTimeIsLocal
-
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 Waveform(CompositeEntity container, java.lang.String name)
Construct an actor with the specified container and name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected double
_hermite(double index, double startTime, double startValue, double tanStart, double endTime, double endValue, double tanEnd)
Return the Hermite curve interpolation.protected void
_produceIntermediateOutput()
Produce the output required at times between the specified times using the specified interpolation method.protected void
_skipToNextPhase()
Skip the current firing phase and request a refiring at the time of the next one.void
attributeChanged(Attribute attribute)
Check the validity of the parameter.void
initialize()
Override the base class to set the output microstep to zero.-
Methods inherited from class ptolemy.actor.lib.DiscreteClock
_getValue, clone, fire, postfire, prefire
-
Methods inherited from class ptolemy.actor.lib.TimedSource
getModelStopTime, getStopTime, wrapup
-
Methods inherited from class ptolemy.actor.lib.Source
_customTypeConstraints
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, 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
-
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
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
interpolation
public StringParameter interpolation
The interpolation method, which must be "linear" or "hermite".
-
-
Constructor Detail
-
Waveform
public Waveform(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Construct an actor with the specified container and name.- 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
Check the validity of the parameter.- Overrides:
attributeChanged
in classDiscreteClock
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the argument is the values parameter and it does not contain an one dimensional array; or the argument is the times parameter and it does not contain an one dimensional array or is not increasing and non-negative; or the argument is the period parameter and is negative; or the argument is the order parameter and the order is not supported by the Interpolation class.
-
initialize
public void initialize() throws IllegalActionException
Override the base class to set the output microstep to zero.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classDiscreteClock
- Throws:
IllegalActionException
- If the parent class throws it, or if the values parameter is not a row vector, or if the fireAt() method of the director throws it, or if the director does not agree to fire the actor at the specified time.
-
_hermite
protected double _hermite(double index, double startTime, double startValue, double tanStart, double endTime, double endValue, double tanEnd)
Return the Hermite curve interpolation.- Parameters:
index
- The interpolation point index.startTime
- The time of the starting reference point.startValue
- The value of the starting reference point.tanStart
- The tangent of the starting reference point.endTime
- The time of the ending reference point.endValue
- The value of the ending reference point.tanEnd
- The tangent of the ending reference point.- Returns:
- The Hermite curve interpolation.
-
_produceIntermediateOutput
protected void _produceIntermediateOutput() throws IllegalActionException
Produce the output required at times between the specified times using the specified interpolation method.- Overrides:
_produceIntermediateOutput
in classDiscreteClock
- Throws:
IllegalActionException
- If sending the output fails.
-
_skipToNextPhase
protected void _skipToNextPhase() throws IllegalActionException
Skip the current firing phase and request a refiring at the time of the next one.- Overrides:
_skipToNextPhase
in classDiscreteClock
- Throws:
IllegalActionException
- If the period cannot be evaluated.
-
-