Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.Counter System object

Package: dsp

Count up or down through specified range of numbers

Description

The Counter object counts up or down through a specified range of numbers.

To count up or down through a specified range of numbers:

  1. Define and set up your counter. See Construction.

  2. Call step to count up or down according to the properties of dsp.Counter. The behavior of step is specific to each object in the toolbox.

    Note:   Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Construction

count = dsp.Counter returns a counter System object, count, that counts up when the input is nonzero.

count = dsp.Counter('PropertyName',PropertyValue,...) returns a counter System object, count, with each specified property set to the specified value.

Properties

Direction

Count up or down

Specify the counter direction as Up or Down. The default is Up. This property is tunable.

CountEventInputPort

Add input to specify a count event

Set this property to true to enable a count event input for the internal counter. The internal counter increments or decrements whenever the count event input satisfies the condition you specify in the CountEventCondition property. When you set this property to false, the internal counter is free running, that is, the counter increments or decrements on every call to the step method. The default is true.

CountEventCondition

Condition that increments, decrements, or resets internal counter

Specify the event at the count event input that increments or decrements the counter as Rising edge, Falling edge, Either edge or Non-zero.

If you set the ResetInputPort and CountEventInputPort properties to true, the counter is reset when the event you specify for the CountEventCondition occurs. This property applies only when you set the CountEventInputPort property to true.

CounterSizeSource

Source of counter size data type

Specify the source of the counter size data type as Property or Input port. The default is Property.

CounterSize

Range of integer values to count through

Specify the range of integer values to count through before recycling to zero as 8 bits, 16 bits, 32 bits or Maximum. The default is Maximum.

MaximumCount

Counter's maximum value

Specify the counter's maximum value as a numeric scalar value. This property applies only when you set the CounterSizeSource property to Property and the CounterSize property to Maximum. The default is 255. This property is tunable.

InitialCount

Counter initial value

Specify the initial value for the counter. The default is 0. This property is tunable.

CountOutputPort

Output count

Set this property to true to enable output of the internal count. The default is true. You cannot set both CountOutputPort and HitOutputPort to false at the same time.

HitOutputPort

Output hit events

Set this property to true to enable output of the hit events. You cannot set both CountOutputPort and HitOutputPort to false at the same time. The default is true.

HitValues

Values whose occurrence in count produce a true hit output

Specify an integer scalar or a vector of integers, whose occurrences in the count you want flagged as a hit. This property applies only when you set the HitOutputPort property to true.

ResetInputPort

Add input to enable internal counter reset

When you set this property to true, specify a reset input to the step method. When the reset input receives the event you specify for the CountEventCondition property, the counter resets. If you set the CountEventInputPort property to false, the counter resets whenever the reset input is not zero.

SamplesPerFrame

Number of samples in each output frame

Specify the number of samples in each output frame. This property applies only when you set the CountEventInputPort property to false, indicating a free-running counter. The default is 1.

CountOutputDataType

Data type of count output

Specify the data type of the count output, CNT, as double, single, int8, uint8, int16, uint16, int32 or uint32. This property applies when you set the CountOutputPort property to true. The default is double.

Methods

resetReset internal states of Counter object
stepIncrement or decrement the internal counter
Common to All System Objects
clone

Create System object with same property values

getNumInputs

Expected number of inputs to a System object

getNumOutputs

Expected number of outputs of a System object

isLocked

Check locked states of a System object (logical)

release

Allow System object property value changes

Examples

expand all

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).

Use dsp.Counter System object™ to count at every rising edge of the input signal.

count = dsp.Counter('MaximumCount', 5, ...
    'CountOutputPort', true, ...
    'HitOutputPort', false, ...
    'ResetInputPort', false);
sgnl = [0 1 0 1 0 1 0 1 0 1 0 1 ];
for ii = 1:length(sgnl)
    cnt(ii) = count(sgnl(ii));
end
display(cnt);
cnt =

     0     1     1     2     2     3     3     4     4     5     5     0

Algorithms

This object implements the algorithm, inputs, and outputs described on the Counter block reference page. The object properties correspond to the block parameters.

  • The CountEventCondition object property does not have a free-running option. Set the CountEventInputPort property to false to obtain the free-running option.

  • The CounterSizeSource and CounterSize object properties correspond to the Counter size block parameter.

  • The CountOutputPort and HitOutputPort correspond to the Output block parameter.

  • There is no object property that corresponds to the Hit data type block parameter. The output type is logical in MATLAB®. (This logical is different from the popup logical in the block. For the object, logical corresponds to Boolean in the block.)

Extended Capabilities

Introduced in R2012a

Was this topic helpful?