2
$\begingroup$

I had this question after seeing that polynomial regressions fit polynomial functions of different degrees to a time-series, since the mean of a time series is a constant and that a constant is also a polynomial of degree 0 i wondered if the SG filter who also fit polynomial functions to a signal over a period window can be called a moving average.

So is it correct to say that a Savitsky-Golay Filter that try to fit a polynomial of order 0 to a signal is considered a moving average filter ?

$\endgroup$

1 Answer 1

6
$\begingroup$

Yes you can consider a zeroth (or first) order SG filter as a moving average filter. Below MATLAB / Octave code computes the impulse response of a SG filter of order $N$ and length $2M+1$ :

% Savitzky-Golay Filter
%
clc; clear all; close all;

N = 0;                      % a0,a1,...,aN : Nth order polynomial
M = 3;                      % x[-M],...,x[M] : 2M + 1 data

A = zeros(2*M+1,N+1);
for n = -M:M
    A(n+M+1,:) = n.^[0:N];
end

H = (A'*A)^(-1)* A';        % LSE fit matrix

h = H(1,:);                 % S-G filter impulse response (non-causal symmetric FIR)

figure,subplot(2,1,1)
stem([-M:M],h);
title(['Impulse response h[n] of Savitzky-Golay filter of order N = ' num2str(N), ' and window size 2M+1 =  ' , num2str(2*M+1)]);

subplot(2,1,2)
plot(linspace(-1,1,1024), abs(fftshift(fft(h,1024))));
title('Frequency response magnitude of h[n]');

figure,plot(linspace(-1,1,1024), 20*log10(abs(fftshift(fft(h,1024)))));
title('Frequency response magnitude of h[n]');

The impulse response for $N=0$ is :

enter image description here

as can be seen, it's a moving average (constant) impulse response.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.