
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

% Program name: monte_filter.m % A program for a first order filter to remove the random noise % introduced by sensors and to find a smooth function tmax = 1; % Maximum time N = 1000; % Total number of time steps h = tmax/N; % Step size t(1) = 0; f(1)=0; p(1)=0; I(1) = f(1); rand('state',0) % to initialize the generator for i=2: N t(i) = t(i-1) + h; p(i)= exp(-200(t(i)-0.2)^2) + exp(-400(t(i)-0.4)^2)+ ... exp(-2000(t(i)-0.6)^2) + exp(-8500(t(i)-0.8)^2); f(i) = p(i) + 0.2rand; % random noise is introduced end for i=2: N I(i) = 0.9I(i-1) + 0.1*f(i); end for i=2: N subplot(2, 1, 1); plot(t(i), f(i), '.r','LineWidth',2) hold on axis([0 tmax 0 1.2]) subplot(2, 1, 2); plot(t(i), I(i),'.b','LineWidth',2) axis([0 tmax 0 1.2]) hold on m(i) = getframe; end xlabel('time, t') ylabel('I(i)') grid movie(m, 20)