n=-5:20;
x=(2+cos(2*pi*n/3)).*(n>=0)
h=[1 1 1 1 1 1 1 1 1]/9
y=conv(x, h);
figure(1)
stem(-5:20, y(1:26))
title('x=(2+cos(2*pi*n/3)*u[n], length 9 moving average')
xlabel('n')
ylabel('x*h_2[n]')
shg

h=[1 1 1]/3
y=conv(x, h);
figure(2)
stem(-5:20, y(1:26))
title('x=(2+cos(2*pi*n/3)*u[n], length 3 moving average');
xlabel('n')
ylabel('x*h_1[n]')
shg