Main Content

Moving Standard Deviation

Moving standard deviation

  • Moving Standard Deviation block

Libraries:
DSP System Toolbox / Statistics

Description

The Moving Standard Deviation block computes the moving standard deviation of the input signal along each channel independently over time. The block uses either the sliding window method or the exponential weighting method to compute the moving standard deviation. In the sliding window method, a window of specified length moves over the data sample by sample, and the block computes the standard deviation over the data in the window. In the exponential weighting method, the block computes the exponentially weighted moving variance and takes the square root. For more details on these methods, see Algorithms.

Examples

Ports

Input

expand all

The block computes the moving standard deviation of the data specified at this input port. Specify real- or complex-valued multichannel inputs of the size m-by-n, where m ≥ 1 and n ≥ 1.

When the Allow arbitrary frame length for fixed-size input signals parameter appears and is not selected, and you input a fixed-size signal, the frame length must be a multiple of the hop size (window length − overlap length). In all other cases, the input frame length can be arbitrary.

The block accepts variable-size inputs (frame length changes during simulation). When you input a variable-size signal, the frame length of the signal can be arbitrary.

This port is unnamed until you set Method to Exponential weighting and select the Specify forgetting factor from input port parameter.

Data Types: single | double
Complex Number Support: Yes

Specify the forgetting factor as a non-negative real scalar in the range [0,1]. The forgetting factor determines how much weight past data is given. A forgetting factor of 0.9 gives more weight to the older data than does a forgetting factor of 0.1. A forgetting factor of 1.0 indicates infinite memory and all previous samples are given an equal weight. A forgetting factor of 0 indicates no memory and the past samples have no weight on the current computation.

Dependencies

This port appears when you set Method to Exponential weighting and select the Specify forgetting factor from input port parameter.

Data Types: single | double

Output

expand all

Moving standard deviation output, returned as a vector or a matrix. The block computes the moving standard deviation based on the Method parameter settings using either the sliding window method or the exponential weighting method. For more details, see Algorithms.

This table provides more details on the dimensions of the output signal.

Input SignalInput DimensionsOutput Dimensions When Allow arbitrary frame length for fixed-size input signals AppearsOutput Dimensions When Allow arbitrary frame length for fixed-size input signals Does Not Appear
Fixed-size signalm-by-n, where m is a multiple of the hop size (window length − overlap length)

(m/hop size)-by-n

m-by-n

Fixed-size signalm-by-n, where m is not a multiple of the hop size (window length − overlap length)

ceil(m/hop size)-by-n when you select Allow arbitrary frame length for fixed-size input signals

If you do not select Allow arbitrary frame length for fixed-size input signals, the block errors.

m-by-n

Variable-size signalm-by-n ceil(m/hop size)-by-n

m-by-n

When the output has an upper bound size of ceil(m/hop size)-by-n, during simulation, the size of the first dimension varies within this bound and the size of the second dimension remains constant. For an example that shows this behavior, see Compute Moving Standard Deviation of Noisy Square Wave Signal.

Data Types: single | double
Complex Number Support: Yes

Parameters

expand all

If a parameter is listed as tunable, then you can change its value during simulation.

  • Sliding window — A window of length Window length moves over the input data along each channel. For every sample the window moves by, the block computes the standard deviation over the data in the window.

  • Exponential weighting — The block computes the exponentially weighted moving standard deviation and takes the square root. The magnitude of the weighting factors decreases exponentially as the age of the data increases, but the magnitude never reaches zero.

For more details on these methods, see Algorithms.

When you select this check box, the length of the sliding window is equal to the value you specify in Window length. When you clear this check box, the length of the sliding window is infinite. In this mode, the block computes the standard deviation of the current sample with respect to all the previous samples in the channel.

Dependencies

To enable this parameter, set Method to Sliding window.

Specifies the length of the sliding window in samples.

Dependencies

To enable this parameter, set Method to Sliding window and select the Specify window length check box.

Specify the overlap length between sliding windows as a nonnegative integer. The value of overlap length varies in the range [0, Window length − 1].

Dependencies

To enable this parameter, set Method to Sliding window and select the Specify window length check box.

Specify whether fixed-size input signals (whose size does not change during simulation) can have an arbitrary frame length, where the frame length does not have to be a multiple of the hop size. Hop size is defined as Window lengthOverlap length. The block uses this parameter setting only for fixed-size input signals and ignores this parameter if the input has a variable-size.

When the input signal is a variable-size signal, the signal can have arbitrary frame length, that is, the frame length does not have to be a multiple of the hop size.

For fixed-size input signals, if you:

  • Select the Allow arbitrary frame length for fixed-size input signals parameter, the frame length of the signal does not have to be a multiple of the hop size. If the input is not a multiple of the hop size, then the output is generally a variable-size signal. Therefore, to support arbitrary input size, the block must also support variable-size operations, which you can enable by selecting the Allow arbitrary frame length for fixed-size input signals parameter.

  • Clear the Allow arbitrary frame length for fixed-size input signals parameter, the input frame length must be a multiple of the hop size.

Dependencies

To enable this parameter, set Method to Sliding window and select the Specify window length check box.

When you select this check box, the forgetting factor is input through the lambda port. When you clear this check box, the forgetting factor is specified on the block dialog through the Forgetting factor parameter.

Dependencies

To enable this parameter, set Method to Exponential weighting.

Specify the exponential weighting factor as a non-negative real scalar in the range [0,1]. This value determines how much weight the past data is given. A forgetting factor of 0.9 gives more weight to the older data than does a forgetting factor of 0.1. A forgetting factor of 1.0 indicates infinite memory and all the past samples are given an equal weight. A forgetting factor of 0 indicates no memory and the past samples have no weight on the current computation.

Tunable: Yes

Dependencies

To enable this parameter, set Method to Exponential weighting and clear the Specify forgetting factor from input port check box.

Specify the type of simulation to run. You can set this parameter to:

  • Interpreted execution –– Simulate model using the MATLAB® interpreter. This option shortens startup time.

  • Code generation –– Simulate model using generated C code. The first time you run a simulation, Simulink generates C code for the block. The C code is reused for subsequent simulations as long as the model does not change. This option requires additional startup time but provides faster subsequent simulations.

Block Characteristics

Data Types

double | single

Multidimensional Signals

No

Variable-Size Signals

Yes

Algorithms

expand all

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2016b

expand all