%% moving average
%x=serie de datos
%n=orden del promediado (en puntos)
function y=media_movil(x,n)

a=-n:n;
y=zeros(1,length(x));
for k=n+1:length(x)-n
	for i=1:length(a)
        y(k)=x(k+a(i))+y(k);   
    end
    y(k)=y(k)/length(a);
end

for k=1:n
    m=0;
    for i=1:length(a)
        if (k+a(i))<1
            m=m+1;
        else
            y(k)=x(k+a(i))+y(k);   
        end
    end
    y(k)=y(k)/(length(a)-m);
end

for k=length(x)-n+1:length(x)
    m=0;
    for i=1:length(a)
        if (k+a(i))>length(x)
            m=m+1;
        else
            y(k)=x(k+a(i))+y(k);   
        end
    end
    y(k)=y(k)/(length(a)-m);
end