Class Waveform

  • 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)
    • Field Detail

      • interpolation

        public StringParameter interpolation
        The interpolation method, which must be "linear" or "hermite".
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        Check the validity of the parameter.
        Overrides:
        attributeChanged in class DiscreteClock
        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 interface Initializable
        Overrides:
        initialize in class DiscreteClock
        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.