Docsity

Monte Filter M-Stochastic Process-Codes, Exercises of Stochastic Processes

Toggle sidebar
bg1
% 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.2*rand; % random noise is introduced
end
for i=2: N
I(i) = 0.9*I(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)
docsity.com

Partial preview of the text

Download Monte Filter M-Stochastic Process-Codes and more Exercises Stochastic Processes in PDF only on Docsity!

% 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)

docsity.com