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.

  • $\begingroup$ The delay is equals to N? The lenght of the data? I don't understand $\endgroup$ – San Riente Apr 8 at 13:52
  • $\begingroup$ No, $N$ as in $2N+1$ filter length. Signal length is arbitrary. This is another $N$ than the one in my answer ;-) $\endgroup$ – Max Apr 8 at 13:56
  • $\begingroup$ Thanks! In this way... My filter have 31 coefficients (just the windows lenght...), so it has a delay=15. Is it correct? $\endgroup$ – San Riente Apr 8 at 14:18
  • $\begingroup$ Why the result is so different than solving it as in the Max answer? $\endgroup$ – San Riente Apr 8 at 14:21
  • $\begingroup$ @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$. $\endgroup$ – Matt L. Apr 8 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)

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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