function y = movingavg(x, n)
%MOVINGAVG Moving average of x
%   Y = MOVINGAVG(X, N) computes the moving average of the elements
%   in X using a window size of N. The length of Y is equal to
%   LENGTH(X) - N + 1

ny = length(x) - n + 1;
y = zeros(1, ny);
for idx = 1:ny
    start = idx;
    stop = idx + n - 1;
    y(idx) = mean(x(start:stop));
end
