ptolemy.domains.sdf.lib
Class Autocorrelation

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.domains.sdf.lib.SDFTransformer
                              extended byptolemy.domains.sdf.lib.Autocorrelation
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, SequenceActor, java.io.Serializable, ptolemy.actor.TypedActor

public class Autocorrelation
extends SDFTransformer

This actor calculates the autocorrelation of a sequence of input tokens. It is polymorphic, supporting any input data type that supports multiplication, addition, and division by an integer. However, since integer division will lose the fractional portion of the result, type resolution will resolve the input type to double or double matrix if the input port is connected to an integer or integer matrix source, respectively.

Both biased and unbiased autocorrelation estimates are supported. If the parameter biased is true, then the autocorrelation estimate is

   N-1-k
   1  ---
   r(k) = -  \    x*(n)x(n+k)
   N  /
   ---
   n = 0
   
for k = 0, ... , p, where N is the number of inputs to average (numberOfInputs), p is the number of lags to estimate (numberOfLags), and x* is the conjugate of the input (if it is complex). This estimate is biased because the outermost lags have fewer than N terms in the summation, and yet the summation is still normalized by N.

If the parameter biased is false (the default), then the estimate is

   N-1-k
   1   ---
   r(k) = ---  \    x*(n)x(n+k)
   N-k  /
   ---
   n = 0
   
In this case, the estimate is unbiased. However, note that the unbiased estimate does not guarantee a positive definite sequence, so a power spectral estimate based on this autocorrelation estimate may have negative components.

The output will be an array of tokens whose type is at least that of the input. If the parameter symmetricOutput is true, then the output will be symmetric and have length equal to twice the number of lags requested plus one. Otherwise, the output will have length equal to twice the number of lags requested, which will be almost symmetric (insert the last sample into the first position to get the symmetric output that you would get with the symmetricOutput being true).

Since:
Ptolemy II 1.0
Version:
$Id: Autocorrelation.java,v 1.30 2004/04/13 05:12:26 cxh Exp $
Author:
Edward A. Lee and Yuhong Xiong
See Also:
Serialized Form
Accepted Rating:
Yellow (neuendor)
Proposed Rating:
Green (eal)

Nested Class Summary
 
Nested classes inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.data.expr.Parameter biased
          If true, the estimate will be biased.
 ptolemy.data.expr.Parameter numberOfInputs
          Number of input samples to average.
 ptolemy.data.expr.Parameter numberOfLags
          Number of autocorrelation lags to output.
 ptolemy.data.expr.Parameter symmetricOutput
          If true, then the output from each firing will have 2*numberOfLags + 1 samples (an odd number) whose values are symmetric about the midpoint.
 
Fields inherited from class ptolemy.domains.sdf.lib.SDFTransformer
input, input_tokenConsumptionRate, output, output_tokenInitProduction, output_tokenProductionRate
 
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
Autocorrelation(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 argument is the order parameter, then set up the consumption and production constants, and invalidate the schedule of the director.
 java.lang.Object clone(ptolemy.kernel.util.Workspace workspace)
          Clone the actor into the specified workspace.
 void fire()
          Consume tokens from the input and produce a token on the output that contains an array token that represents an autocorrelation estimate of the consumed tokens.
 boolean prefire()
          If there are not sufficient inputs, then return false.
 java.util.List typeConstraintList()
          Return the type constraint that the type of the elements of the output array is no less than the type of the input port.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, attributeTypeChanged, clone, newPort
 
Methods inherited from class ptolemy.actor.AtomicActor
_createReceivers, connectionsChanged, getDirector, getExecutiveDirector, getFunctionDependency, getManager, initialize, inputPortList, iterate, newReceiver, outputPortList, postfire, 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
initialize, iterate, postfire, 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

biased

public ptolemy.data.expr.Parameter biased
If true, the estimate will be biased. This is a boolean with default value false.


numberOfInputs

public ptolemy.data.expr.Parameter numberOfInputs
Number of input samples to average. This is an integer with default value 256.


numberOfLags

public ptolemy.data.expr.Parameter numberOfLags
Number of autocorrelation lags to output. This is an integer with default value 64.


symmetricOutput

public ptolemy.data.expr.Parameter symmetricOutput
If true, then the output from each firing will have 2*numberOfLags + 1 samples (an odd number) whose values are symmetric about the midpoint. If false, then the output from each firing will have 2*numberOfLags samples (an even number) by omitting one of the endpoints (the last one). This is a boolean with default value false.

Constructor Detail

Autocorrelation

public Autocorrelation(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.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the actor 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 argument is the order parameter, then set up the consumption and production constants, and invalidate the schedule of the director.

Parameters:
attribute - The attribute that has changed.
Throws:
ptolemy.kernel.util.IllegalActionException - If the parameters are out of range.

clone

public java.lang.Object clone(ptolemy.kernel.util.Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the actor into the specified workspace. This calls the base class and then sets the type constraints.

Parameters:
workspace - The workspace for the new object.
Returns:
A new actor.
Throws:
java.lang.CloneNotSupportedException - If a derived class has an attribute that cannot be cloned.

fire

public void fire()
          throws ptolemy.kernel.util.IllegalActionException
Consume tokens from the input and produce a token on the output that contains an array token that represents an autocorrelation estimate of the consumed tokens. The estimate is consistent with the parameters of the object, as described in the class comment.

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

prefire

public boolean prefire()
                throws ptolemy.kernel.util.IllegalActionException
If there are not sufficient inputs, then return false. Otherwise, return whatever the base class returns.

Specified by:
prefire in interface ptolemy.actor.Executable
Overrides:
prefire in class SDFTransformer
Returns:
True if it is ok to continue.
Throws:
ptolemy.kernel.util.IllegalActionException - If the base class throws it.

typeConstraintList

public java.util.List typeConstraintList()
Return the type constraint that the type of the elements of the output array is no less than the type of the input port.

Returns:
A list of inequalities.