Variance - Compute variance of input or sequence of inputs

Library

Statistics

dspstat3

Description

The Variance block computes the unbiased variance of each row or column of the input, along vectors of a specified dimension of the input, or of the entire input. The Variance block can also track the variance of a sequence of inputs over a period of time. The Running variance parameter selects between basic operation and running operation.

Basic Operation

When you do not select the Running variance check box, the block computes the variance of each row or column of the input, along vectors of a specified dimension of the input, or of the entire input at each individual sample time, and outputs the array y. Each element in y is the variance of the corresponding column, row, vector, or entire input. The output y depends on the setting of the Find the variance value over parameter. For example, consider a 3-dimensional input signal of size M-by-N-by-P:

For purely real or purely imaginary inputs, the variance of an M-by-N matrix is the square of the standard deviation:

For complex inputs, the variance is given by the following equation:

Running Operation

When you select the Running variance check box, the block tracks the variance of successive inputs to the block. For sample-based M-by-N inputs, the output is a sample-based M-by-N matrix with each element yij containing the variance of element uij over all inputs since the last reset. For frame-based M-by-N inputs, the output is a frame-based M-by-N matrix with each element yij containing the variance of the jth column over all inputs since the last reset, up to and including element uij of the current input.

N-D signals cannot be frame based. When the block is set to Running mode, each element of the N-D signal is treated as a separate channel. There are channels, where di is the size of the ith dimension.

Resetting the Running Variance

The block resets the running variance whenever a reset event is detected at the optional Rst port. The reset sample time must be a positive integer multiple of the input sample time.

You specify the reset event in the Reset port parameter:

ROI Processing

To calculate the statistical value within a particular region of interest (ROI) of the input, select the Enable ROI processing check box. This option is only available when the Find the variance value over parameter is set to Entire input and the Running variance check box is not selected. ROI processing is only supported for 2-D inputs.

Use the ROI type parameter to specify whether the ROI is a binary mask, label matrix, rectangle, or line. ROI processing is only supported for 2-D inputs.

Use the Output parameter to specify the block output. The block can output separate statistical values for each ROI or the statistical value for all specified ROIs. This parameter is not available if, for the ROI type parameter, you select Binary mask.

If, for the ROI type parameter, you select Rectangles or Lines, the Output flag indicating if ROI is within image bounds check box appears in the dialog box. If you select this check box, the Flag port appears on the block. The following tables describe the Flag port output based on the block parameters.

Output = Individual Statistics for Each ROI

Flag Port OutputDescription
0ROI is completely outside the input image.
1ROI is completely or partially inside the input image.

Output = Single Statistic for All ROIs

Flag Port OutputDescription
0All ROIs are completely outside the input image.
1At least one ROI is completely or partially inside the input image.

If the ROI is partially outside the image, the block only computes the statistical values for the portion of the ROI that is within the image.

If, for the ROI type parameter, you select Label matrix, the Output flag indicating if input label numbers are valid check box appears in the dialog box. If you select this check box, the Flag port appears on the block. The following tables describe the Flag port output based on the block parameters.

Output = Individual Statistics for Each ROI

Flag Port OutputDescription
0Label number is not in the label matrix.
1Label number is in the label matrix.

Output = Single Statistic for All ROIs

Flag Port OutputDescription
0None of the label numbers are in the label matrix.
1At least one of the label numbers is in the label matrix.

Fixed-Point Data Types

The parameters on the Fixed-Point pane of the block dialog are only used for fixed-point inputs. For purely real or purely imaginary inputs, the variance of the input is the square of its standard deviation. For complex inputs, the output is the sum of the variance of the real and imaginary parts of the input.

The following diagram shows the data types used within the Variance block for fixed-point signals.

The results of the magnitude-squared calculations in the figure are in the product output data type. You can set the accumulator, product output, and output data types in the block dialog as discussed in Dialog Box.

Examples

The Variance block in the next model calculates the running variance of a frame-based 3-by-2 (two-channel) matrix input, u. The running variance is reset at t=2 by an impulse to the block's Rst port.

The Variance block has the following settings:

The Signal From Workspace block has the following settings:

where

dsp_examples_u = [6 1 3 -7 2 5 8 0 -1 -3 2 1;1 3 9 2 4 1 6 2 5 0 4 17]'

The Discrete Impulse block has the following settings:

The next figure shows the block's operation.

Dialog Box

The Main pane of the Variance block dialog appears as follows.

Running variance

Enables running operation when selected.

Reset port

Determines the reset event that causes the block to reset the running variance. The rate of the reset signal must be a positive integer multiple of the rate of the data signal input. This parameter is enabled only when you select the Running variance parameter. For more information, see Resetting the Running Variance

Find the variance value over

Specify whether to find the variance along rows, columns, entire input, or the dimension specified in the Dimension parameter. For more information, see Basic Operation.

Treat sample-based row input as a column

Select to treat sample-based length-M row vector inputs as M-by-1 column vectors. This parameter is only visible when the Find the variance value over parameter is set to Each column.

Dimension

Specify the dimension (one-based value) of the input signal, over which the variance is computed. The value of this parameter cannot exceed the number of dimensions in the input signal. This parameter is only visible when the Find the variance value over parameter is set to Specified dimension.

Enable ROI Processing

Select this check box to calculate the statistical value within a particular region of each image. This parameter is only available when the Find the variance value over parameter is set to Entire input, and the block is not in running mode.

ROI type

Specify the type of ROI you want to use. Your choices are Rectangles, Lines, Label matrix, or Binary mask.

ROI portion to process

Specify whether you want to calculate the statistical value for the entire ROI or just the ROI perimeter. This parameter is only visible if, for the ROI type parameter, you specify Rectangles.

Output

Specify the block output. The block can output a vector of separate statistical values for each ROI or a scalar value that represents the statistical value for all the specified ROIs. This parameter is not available if, for the ROI type parameter, you select Binary mask.

Output flag indicating if ROI is within image bounds

If you select this check box, the Flag port appears on the block. For a description of the Flag port output, see the tables in ROI Processing. This parameter is visible if, for the ROI type parameter, you select Rectangles or Lines.

Output flag indicating if label numbers are valid

If you select this check box, the Flag port appears on the block. For a description of the Flag port output, see the tables in ROI Processing. This parameter is visible if, for the ROI type parameter, you select Label matrix.

The Fixed-point pane of the Variance block dialog appears as follows.

Rounding mode

Select the rounding mode for fixed-point operations.

Overflow mode

Select the overflow mode for fixed-point operations.

Input-squared product

Use this parameter to specify how to designate the input-squared product word and fraction lengths:

Input-sum-squared product

Use this parameter to specify how to designate the input-sum-squared product word and fraction lengths:

Accumulator

Use this parameter to specify the accumulator word and fraction lengths resulting from a complex-complex multiplication in the block:

Output

Choose how you specify the output word length and fraction length:

Lock scaling against changes by the autoscaling tool

Select this parameter to prevent any fixed-point scaling you specify in this block mask from being overridden by the autoscaling feature of the Fixed-Point Tool. See the fxptdlg reference page for more information.

Supported Data Types

PortSupported Data Types

Input

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

Reset

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

ROI

Rectangles and lines:

  • Double-precision floating point

  • Single-precision floating point

  • Boolean

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

Binary Mask:

  • Boolean

Label

  • 8-, 16-, and 32-bit unsigned integers

Label Numbers

  • 8-, 16-, and 32-bit unsigned integers

Output

  • Double-precision floating point

  • Single-precision floating point

  • Fixed point

  • 8-, 16-, and 32-bit signed integers

  • 8-, 16-, and 32-bit unsigned integers

Flag

  • Boolean

See Also

MeanSignal Processing Blockset
RMSSignal Processing Blockset
Standard DeviationSignal Processing Blockset
varMATLAB

  


 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS