%MAandEWMA.m script program.
%plot the coefficients of N-point MA Filter and 
%the coefficients of N-point EWMA Filter 
%Use 'input' matlab command to control the input for the length
%of the two filters (N), the parameter B.
% B must be 0 < B < 1, this condition must be validate

% Get the input from the user
N = input('Please, enter the length for MA and EWMA Filters   ');
B = input ('Please, enter the value for B, 0 < B < 1   ');
if (B <= 0 | B>=1)
    error('B must be greater than 0 and less than 1');
end

% MA Filter coefficients generation
n = 0:N-1;
MAW = (1/N)*ones(size(n));
subplot(2,1,1);
stem(n,MAW,'filled');
title('Impulse Response of MA filter');
xlabel('samples');
ylabel('MA Coefficients');
axis auto;

% EWMA Filter coefficients generation
A = (1-B)/(1-B^N); 
EWMAW = A*B.^n; %EWMA Coefficients
subplot(2,1,2);
stem(n, EWMAW, 'filled');
title('Impulse Response of EWMA Filter ');
xlabel ('samples');
ylabel ('EWMA Coefficients');
axis auto
