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.MovingStandardDeviation System object

Moving standard deviation

Description

The dsp.MovingStandardDeviation System object™ computes the moving standard deviation of the input signal along each channel, independently over time. The object 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 is moved over the data, sample by sample, and the object computes the standard deviation over the data in the window. In the exponential weighting method, the object computes the exponentially weighted moving variance, and takes the square root. For more details on these methods, see Algorithms.

The object accepts multichannel inputs, that is, m-by-n size inputs, where m ≥ 1, and n > 1. The object also accepts variable-size inputs. Once the object is locked, you can change the size of each input channel. However, the number of channels cannot change. This object supports C and C++ code generation.

To compute the moving standard deviation of the input:

  1. Create a dsp.MovingStandardDeviation object and set the properties of the object.

  2. Call step to compute the moving standard deviation.

Note

Alternatively, 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

MovStd = dsp.MovingStandardDeviation returns a moving standard deviation object, MovStd, using the default properties.

MovStd = dsp.MovingStandardDeviation(Len) sets the WindowLength property to Len.

MovStd = dsp.MovingStandardDeviation(Name,Value) specifies additional properties using Name,Value pairs. Unspecified properties have default values.

Example:

MovStd = dsp.MovingStandardDeviation('Method','Exponential weighting','ForgettingFactor',0.999);

Properties

expand all

  • 'Sliding window' — A window of length specified by SpecifyWindowLength is moved over the input data along each channel. For every sample the window moves by, the object computes the standard deviation over the data in the window.

  • 'Exponential weighting' — The object computes the exponentially weighted moving variance, and takes the square root.

For more details on these methods, see Algorithms.

Flag to specify a window length, specified as a scalar boolean.

  • true — The length of the sliding window is equal to the value you specify in the WindowLength property.

  • false — The length of the sliding window is infinite. In this mode, the standard deviation is computed using the current sample and all the past samples.

This property applies when you set Method to 'Sliding window'.

Length of the sliding window, specified as a positive scalar integer. This property applies when you set Method to 'Sliding window' and SpecifyWindowLength to true.

Exponential weighting factor, specified as a positive real scalar in the range (0,1].

This property applies when you set Method to 'Exponential weighting'.

This property is tunable. You can change its value even when the object is locked.

Methods

resetReset internal states of System object
stepMoving standard deviation of input signal
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

Compute the moving standard deviation of a noisy square wave signal with varying amplitude using the dsp.MovingStandardDeviation object.

Initialization

Set up movstdWindow and movstdExp objects. movstdWindow uses the sliding window method with a window length of 800. movstdExp uses the exponential weighting method with a forgetting factor of 0.999. Create a time scope for viewing the output.

FrameLength = 100;
Fs = 100;
movstdWindow = dsp.MovingStandardDeviation(800);
movstdExp = dsp.MovingStandardDeviation('Method','Exponential weighting',...
    'ForgettingFactor',0.999);
scope  = dsp.TimeScope('SampleRate',Fs,...
    'TimeSpanOverrunAction','Scroll',...
    'TimeSpan',1000,...
    'ShowGrid',true,...
    'BufferLength',1e7,...
    'YLimits',[0 3e-2]);
title = 'Actual (yellow) Sliding Window (blue) Exponentially Weighted (red) standard deviation';
scope.Title = title;

Compute the Standard Deviation

Generate a noisy square wave signal. Vary the amplitude of the square wave after a given number of frames. Apply the sliding window method and the exponential weighting method on this signal. The actual standard deviation is sqrt(np). This value is used while adding noise to the data. Compare the actual standard deviation with the computed standard deviation on the time scope.

count = 1;
noisepower = 1e-4 * [1 2 3 4];
index = 1;
for index = 1:length(noisepower)
    np = noisepower(index);
    yexp = sqrt(np)*ones(FrameLength,1);
    for i = 1:250
        x = sqrt(np) * randn(FrameLength,1);
        y1 = movstdWindow(x);
        y2 = movstdExp(x);
        scope([yexp,y1,y2]);
    end
end

Algorithms

expand all

References

[1] Bodenham, Dean. “Adaptive Filtering and Change Detection for Streaming Data.” PH.D. Thesis. Imperial College, London, 2012.

Extended Capabilities

Introduced in R2016b

Was this topic helpful?