Implemenation of Length N Moving average filter using block covolution algorithm(overlap and save algorithm) I want to implement a Length N moving average filter using block convolution algorithm(overlap save algorithm)
I am copying block convolution algorithm(overlap save algorithm) from Proakis, DSP using MATLAB 3rd Ed
function [y] = ovrlpsav(x,h,N)
% Overlap-Save method of block convolution
% ----------------------------------------
% [y] = ovrlpsav(x,h,N)
% y = output sequence
% x = input sequence
% h = impulse response
% N = block length
%
Lenx = length(x); M = length(h);
M1 = M-1; L = N-M1;
h = [h zeros(1,N-M)];
%
x = [zeros(1,M1), x, zeros(1,N-1)]; % preappend (M-1) zeros
K = floor((Lenx+M1-1)/(L));         % # of blocks
Y = zeros(K+1,N);
% convolution with succesive blocks
for k=0:K
    xk = x(k*L+1:k*L+N);
    Y(k+1,:) = cconv(xk,h,N);
end

Y = Y(:,M:N)';                      % discard the first (M-1) samples
y = (Y(:))';                        % assemble output

Now using above function i am trying to implement a Length N moving average filter.
My script(m-file) is below
clc
clear all
close all
n=1:5
signal=n*pi;
subplot(221)
stem(n,signal);
xlabel('n');ylabel('amplitude');title('original signal')
noise=rand(1,5);
subplot(222)
stem(n,noise);
xlabel('n');ylabel('amplitude');title('noise signal');title('noise ')
p=ovrlpsav(signal,noise,6),
subplot(223)
stem(p);xlabel('n');ylabel('amplitude');title('corrupted signal')
m=5;
xu=0;
for i=1:m
    
    x=signal+noise;
    xu=xu+x;
end
xu=xu/m;
subplot(224)
stem(n,xu);xlabel('n');ylabel('amplitude');title('filtered signal')

I am getting a filtered signal similar to input signal as shown by above code,but am i following proper approach?
in psudo pyhon code
const tail = 5  

'inside loop where you feed it values

list.push(entry)
list.rotate.left(1)
if len(list)&gt;tail list.pop()
avg = sum(lst) / len(lst)
print avg