www.gusucode.com > signal 案例源码程序 matlab代码 > signal/CusumDefaultValuesExample.m

    %% |cusum| Default Values
% Generate and plot a 100-sample random signal with a linear trend. Reset
% the random number generator for reproducible results.

%%

rng('default')

rnds = rand(1,100);
trnd = linspace(0,1,100);

fnc = rnds + trnd;

plot(fnc)

%%
% Apply |cusum| to the function using the default values of the input
% arguments.

cusum(fnc)

%%
% Compute the mean and standard deviation of the first 25 samples. Apply
% |cusum| using these numbers as the target mean and the target standard
% deviation. Highlight the point where the cumulative sum drifts more than
% five standard deviations beyond the target mean. Set the minimum
% detectable mean shift to one standard deviation.

mfnc = mean(fnc(1:25));
sfnc = std(fnc(1:25));

cusum(fnc,5,1,mfnc,sfnc)

%%
% Repeat the calculation using a negative linear trend.

nnc = rnds - trnd;

cusum(nnc)