
%==========================================================================
%
% Description: this function computes the moving average of all data input as an array
%
% Author: C. Alex Simpkins
%
% Date: Thurs Oct 5, 2006
%
% Inputs: array of data x, and window size n
%
% Outputs: filtered data xf
%
%==========================================================================

function xf=Low_Pass(x,n);

%compute the window size...
window_size = 2*n+1;

%initialize the filtered data array as zeros the length of our data set...
xf = zeros(length(x),1);

%loop over all the data points...
for i=1:length(x),

    %the window loop...
    for j=(i-n):(i+n),
        if(j<1),
            xf(i) = xf(i)+x(1);
            
        elseif (j>=1 & j<=length(x)),
            xf(i) = xf(i)+x(j);
            
        else
            xf(i) = xf(i) + x(length(x));
            
        end          
    end
    
    %divide by the window size...
    xf(i) = xf(i)/window_size;

end
%now our code will return to where it was called from...