# Delay in Savitzky-Golay filtering

I am applying a Savitzky-Golay filter to a signal, using the scipy function.

I need to calculate the lag of the filtered signal, and how much is it behind the original signal.

Could someone shed some light on this matter? How could I calculate it with scipy? How should I interpret the result correctly?

I would be very grateful!

Standard Savitzky-Golay filters are linear phase (type I) FIR filters. So they have an odd number of filter coefficients $$2N+1$$, and the delay equals $$N$$.

For a good overview of Savitzky-Golay filters see this article by Ronald Schafer.

For the definition of the four types of linear phase FIR filters see this answer.

• The delay is equals to N? The lenght of the data? I don't understand – San Riente Apr 8 '19 at 13:52
• No, $N$ as in $2N+1$ filter length. Signal length is arbitrary. This is another $N$ than the one in my answer ;-) – Max Apr 8 '19 at 13:56
• Thanks! In this way... My filter have 31 coefficients (just the windows lenght...), so it has a delay=15. Is it correct? – San Riente Apr 8 '19 at 14:18
• Why the result is so different than solving it as in the Max answer? – San Riente Apr 8 '19 at 14:21
• @SanRiente: As pointed out by Max, $2N+1$ is the (odd) filter length. If you denote the odd filter length by $M$, the delay is $(M-1)/2$. – Matt L. Apr 8 '19 at 14:48

Just do a cross correlation with cc = scipy.signal.correlate(original,filtered)

By position of the maximum, you can find out the filter delay. Just notice that the result will have length $$2N-1$$ with $$N$$ being the length of the original signal. So the delay in samples will be

numpy.argmax(cc) -len(original)

• The both answers are very differents! I don't understand what to do! – San Riente Apr 8 '19 at 14:36