Class Quantizer

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

    public class Quantizer
    extends Transformer

    Produce an output token on each firing with a value that is a quantized version of the input. The input and output types are both double.

    There are two ways to specify the quantization. If the levels parameter is given, then the output will be the element of the array specified by levels that is closest to the input. Otherwise, if levels is empty, then the output will be quantized according to the delta parameter, which specifies the spacing between quantization levels. Specifically, the output will be

    delta * Math.floor( input/delta) .

    With the default value of delta, which is 1.0, the output is simply the integer part of the input.

    The levels parameter contains an array of doubles specifying the quantization levels. The elements must be in an increasing order, or an exception will be thrown. The default value of levels is {-1.0, 1.0}.

    Suppose u is the input, and levels = {a, b, c}, where a < b < c, then the output of the actor will be:

    y = a, for u <= (b+a)/2;
    y = b, for (b+a)/2 <u <= (c+b)/2;

    y = c, for u > (c+b)/2;

    Thus, for the default levels, the output is (almost) the signum function of the input, or +1.0 if the input is positive, and -1.0 otherwise. This is almost the signum function because it outputs -1.0 if the input is zero.

    This actor does not require that the quantization intervals be equal, i.e. we allow that (c-b) != (b-a).

    Since:
    Ptolemy II 0.3
    Version:
    $Id$
    Author:
    Jie Liu
    Pt.AcceptedRating:
    Yellow (yuhong)
    Pt.ProposedRating:
    Yellow (liuj)