% hilopassdemo.m % show smoothing an differecing as a moving mask pausetime = .1; % Define filters L = [1,1]/2; H = [1,-1]/2; n = size(L,2); %define signal N = 128; Dt = 0:(N-1); t = (0:(N-1))/N; X = sin(5*t) + 0.75*cos(50*t)+0.5*unitnois(size(t)); mx = 2; mn = -2; % inital plot figure(1) subplot(2,1,1) plot(Dt,X); title('original signal') axis([0,N-1,mn,mx]) subplot(2,1,2) plot(Dt,0); axis([0,N-1,mn,mx]) title('window for filtered signals') disp('Press a key for moving filtering demo') pause % now the filtering demo Xl = []; Xh = []; for j = 1:N inds = j:(-1):(j-n+1); inds = rem(inds + N-1,N)+1; Xl =[Xl,X(inds)*L']; Xh =[Xh,X(inds)*H']; Dtf = 0:(j-1); subplot(2,1,1) plot(Dt,X,'b-',inds-1,X(inds),'r.'); axis([0,N-1,mn,mx]) title('current selected values') subplot(2,1,2) plot(Dtf,Xl,'r-',Dtf,Xh,'g-'); axis([0,N-1,mn,mx]) title('filtered signals') pause(pausetime) end