Contents
Initialize parameters and generate signals
N = 50;
n = 0:N;
Omega = 2*pi/50;
v = sin(Omega*n);
r = 0.2*randn(1,N+1);
x = v + r;
Moving average
M = 9;
h = (1/M)*ones(1,M);
y = conv(h,x);
Graphics
figure('Name',['FIR system : Moving average with M = ',num2str(M)],'NumberTitle','off');
subplot(3,1,1); stem(n,v,'filled')
axis([0 N -2 2]); ylabel('v[n] \rightarrow'); grid
subplot(3,1,2); stem(n,x,'filled')
axis([0 N -2 2]); ylabel('x[n] \rightarrow'); grid
hold on; plot(n,v,':k'); hold off
subplot(3,1,3); stem(0:length(y)-1,y,'filled')
axis([0 N+M-1 -2 2]); grid
xlabel('n \rightarrow'); ylabel('y[n] \rightarrow')
shift = fix(M/2);
hold on; plot(n+shift,v,':k'); hold off