www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/DisableTheCorrectionStepInTheKalmanFilterExample.m

    %% Disable the Correction Step in the Kalman Filter
%%
% *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).

%%
% Create the signal, Kalman Filter, and Time Scope System objects:
numSamples = 4000;
R = 0.02;
hSig = dsp.SignalSource;
hSig.Signal = [  ones(numSamples/4,1);   -3*ones(numSamples/4,1);...
              4*ones(numSamples/4,1); -0.5*ones(numSamples/4,1)];
hTScope = dsp.TimeScope('NumInputPorts', 3, 'TimeSpan', numSamples, ...
          'TimeUnits', 'Seconds', 'YLimits',[-5 5], ...
          'Title', ['True(channel 1), noisy(channel 2) and ',...
          'estimated(channel 3) values'], ...
          'ShowLegend', true); 
hKalman = dsp.KalmanFilter('ProcessNoiseCovariance', 0.0001,...
          'MeasurementNoiseCovariance', R,...
          'InitialStateEstimate', 5,...
          'InitialErrorCovarianceEstimate', 1,...
          'ControlInputPort',false); 
ctr = 0;
%%
% Add noise to the signal. Step through the System objects to obtain the
% data streams, and plot the filtered signal.
while(~isDone(hSig))
    trueVal = hSig();
    noisyVal = trueVal + sqrt(R)*randn;
    estVal = hKalman(noisyVal);
    hTScope(trueVal,noisyVal,estVal);
    
    % Disabling the correction step of second filter for the middle
    % one-third of the simulation
    if ctr == floor(numSamples/3)
        hKalman.DisableCorrection = true;
    end
    if ctr == floor(2*numSamples/3)
        hKalman.DisableCorrection = false;
    end
    ctr = ctr + 1;
end