This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

dsp.Variance System object

Variance of input or sequence of inputs

Description

The Variance object computes variance for an input or sequence of inputs.

Note

The Running mode in the dsp.Variance System object™ will be removed in a future release. To compute the running variance in MATLAB®, use the dsp.MovingVariance System object instead.

To compute the variance of an input or sequence of inputs:

  1. Create the dsp.Variance object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Creation

Syntax

var = dsp.Variance
var = dsp.Variance(Name,Value)

Description

example

var = dsp.Variance returns a variance System object, var, that computes the variance of an input or a sequence of inputs over the specified Dimension.

var = dsp.Variance(Name,Value) returns a variance System object, var, with each specified property set to the specified value.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Set this property to true to enable variance calculation over successive calls to the object algorithm.

Set this property to true to enable reset input port. When you set the property to true, specify a reset input for the step method. The running variance resets anytime the variance object achieves the condition you specify for the ResetCondition property.

Dependencies

This property applies when you set the RunningVariance property to true.

Specify which event resets the running variance as one of | Rising edge | Falling edge | Either edge | Non-zero |.

Dependencies

This property applies when you set the ResetInputPort property to true.

Specify how the object performs the variance calculation over the data as one of | All | Row | Column | Custom |.

Dependencies

This property applies when you set the RunningVariance property to false.

Specify the input signal dimension (one-based value) the object uses to compute variance. The cannot exceed the number of dimensions in the input signal.

Dependencies

This property applies when you set the Dimension property to Custom.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-Point Properties

Specify the rounding method as one of | Ceiling | Convergent | Floor | Nearest | Round | Simplest | Zero |.

Specify the overflow action as one of | Wrap | Saturate |.

Specify the input-squared product fixed-point data type as one of | Same as input | Custom |.

Specify the input-squared product fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property applies when you set the InputSquaredProductDataType property to Custom.

Specify the input-sum-squared product fixed-point data type as one of | Same as input-squared product | Custom |.

Specify the input-sum-squared product fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property applies when you set the InputSumSquaredProductDataType property to Custom.

Specify the accumulator fixed-point data type as one of | Same as input-squared product | Same as input | Custom |.

Specify the accumulator fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property applies when you set the AccumulatorDataType property to Custom.

Specify the output fixed-point data type as one of | Same as input-squared product | Same as input | Custom |.

Specify the output fixed-point type as a scaled numerictype object with a Signedness of Auto.

Dependencies

This property only applies when the OutputDataType property to Custom.

Usage

For versions earlier than R2016b, use the step function to run the System object algorithm. The arguments to step are the object you created, followed by the arguments shown in this section.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Syntax

y = var(x)
y = var(x,r)

Description

example

y = var(x) computes the variance, y, of input x over successive calls to the object algorithm, when the RunningVariance property is true.

y = var(x,r) resets its state based on the value of reset signal r , the ResetInputPort property and the ResetCondition property. This option applies when the RunningVariance property is true and the ResetInputPort property is set to true.

Input Arguments

expand all

Data input, specified as a vector or a matrix. If x is a matrix, each column is treated as an independent channel. The variance is computed along each channel. The object also accepts variable-size inputs. Once the object is locked, you can change the size of each input channel.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Reset signal used to reset the running variance, specified as a scalar value. The object resets the running variance if the reset signal satisfies the ResetCondition.

Dependencies

To enable this signal, set the RunningVariance property to true and the ResetInputPort property to true.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Output Arguments

expand all

Variance output, returned as a scalar, vector or a matrix. If RunningVariance is set to:

  • false –– The object computes the variance value of each input channel. If the input is a column vector, the output is a scalar. If the input is a multichannel signal, the output signal is 1-by-N vector, where N is the number of input channels.

  • true –– The object computes the running variance of the signal. The size of the output signal matches the size of the input signal.

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

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).

Compute the running variance of the signal. That is, compute the variance of each sample in the input signal with respect to all the previous samples.

var = dsp.Variance;
var.RunningVariance = true;
input = randn(100,1);
variance = var(input);

Algorithms

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

  • Reset port block parameter corresponds to both the ResetCondition and the ResetInputPort object properties.

Extended Capabilities

Introduced in R2012a