www.gusucode.com > vision 源码程序 matlab案例代码 > vision/RemoveNoiseFromASignalExample.m
%% Remove Noise From a Signal % Use Kalman filter to remove noise from a random signal corrupted by a zero-mean Gaussian noise. %% % Synthesize a random signal that has value of 1 and is corrupted by a zero-mean Gaussian noise with standard deviation of 0.1. % Copyright 2015 The MathWorks, Inc. x = 1; len = 100; z = x + 0.1 * randn(1,len); %% % Remove noise from the signal by using a Kalman filter. The state is expected to be constant, and the measurement is the same as state. stateTransitionModel = 1; measurementModel = 1; obj = vision.KalmanFilter(stateTransitionModel,measurementModel,'StateCovariance',1,'ProcessNoise',1e-5,'MeasurementNoise',1e-2); z_corr = zeros(1,len); for idx = 1: len predict(obj); z_corr(idx) = correct(obj,z(idx)); end %% % Plot results. figure, plot(x * ones(1,len),'g-'); hold on; plot(1:len,z,'b+',1:len,z_corr,'r-'); legend('Original signal','Noisy signal','Filtered signal');