Class PeriodicSampler

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class PeriodicSampler
    extends Transformer
    This actor generates discrete events by periodically sampling the input signal. The sampling rate is given by parameter samplePeriod, which has default value 0.1. Specifically, if the actor is initialized at time t and the sample period is T, then the output will have the value of the input at times t + nT, for all natural numbers n. By default, this sampler will send to the output the initial value of the input (the input value at microstep 0), but will send it one microstep later (at microstep 1). This ensures that the output at microstep 0 is always absent, thus ensuring continuity from the left. That is, the input is absent prior to the sample time, so continuity requires that it be absent at microstep 0 at the sample time.

    To get this sampler to record values other than the initial value, set the microstep parameter to a value greater than 0. Setting it to 1, for example, will record the input value after a discontinuity rather than before the discontinuity. Note that Sampler normally records its inputs at microstep 1 (because it is triggered by a discrete signal, which has events at microstep 1), and therefore if you want this PeriodicSampler to behave the same as Sampler, you should set microstep to 1.

    This actor has multiport inputs and outputs. Signals in each input channel are sampled and produced to corresponding output channel.

    Note that this actor does not tolerate changing input or output connections during execution.

    Since:
    Ptolemy II 8.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • microstep

        public Parameter microstep
        The microstep at which to read the input. This is an whose default value is 0.
      • samplePeriod

        public Parameter samplePeriod
        The parameter for the sampling period. This is a double whose default value is 0.1.
    • Constructor Detail

      • PeriodicSampler

        public PeriodicSampler​(CompositeEntity container,
                               java.lang.String name)
                        throws IllegalActionException,
                               NameDuplicationException
        Construct an actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown. The actor can be either dynamic, or not. It must be set at the construction time and can't be changed thereafter. A dynamic actor will produce a token at its initialization phase.
        Parameters:
        container - The container of this actor.
        name - The actor's name
        Throws:
        IllegalActionException - If the entity cannot be contained by the proposed container.
        NameDuplicationException - If name coincides with an entity already in the container.
    • Method Detail

      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone this actor into the specified workspace. The new actor is not added to the directory of that workspace (you must do this yourself if you want it there). The result is a new actor with the same ports as the original, but no connections and no container. A container must be set before much can be done with this actor.
        Overrides:
        clone in class TypedAtomicActor
        Parameters:
        workspace - The workspace for the cloned object.
        Returns:
        A new ComponentEntity.
        Throws:
        java.lang.CloneNotSupportedException - If cloned ports cannot have as their container the cloned entity (this should not occur), or if one of the attributes cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • fire

        public void fire()
                  throws IllegalActionException
        Generate an output if the current time is one of the sampling times and the microstep matches. In addition, if the microstep parameter has value 0, produce the output only if the current microstep is 1. The value of the event is the value of the input signal at the current time at the microstep specified by the microstep parameter.
        Specified by:
        fire in interface Executable
        Overrides:
        fire in class AtomicActor<TypedIOPort>
        Throws:
        IllegalActionException - If the transfer of tokens failed.
      • isStrict

        public boolean isStrict()
        Return false if the microstep value is zero. In that case, this actor can produce some outputs even the inputs are unknown. This actor is usable for breaking feedback loops. It does not read inputs in the fire() method.
        Specified by:
        isStrict in interface Executable
        Overrides:
        isStrict in class AtomicActor<TypedIOPort>
        Returns:
        False.