I am trying to measure the delay introduced by smoothening filters to my data, including a double-exponential smoothening filter. I run my series data through this function:

def double_exponential_smoothing(series, alpha, beta, n_preds=1):
    Given a series, alpha, beta and n_preds (number of
    forecast/prediction steps), perform the prediction.
    # first value is same as series
    result = [series[0]]
    for n in range(1, len(series)+1):
        if n == 1:
            level, trend = series[0], series[1] - series[0]
        if n >= len(series): # forecasting
            value = result[-1]
            value = series[n]
        last_level, level = level, alpha*value + (1-alpha)*(level+trend)
        trend = beta*(level-last_level) + (1-beta)*trend
    return result

And then measure the time delay by comparing the filtered data with the raw data (y2 & y1 respectively):

def lag_finder(y1, y2, sample_rate):
    n = len(y1)
    corr = signal.correlate(y2, y1, mode='same') / np.sqrt(signal.correlate(y1, y1, mode='same')[int(n/2)] * signal.correlate(y2, y2, mode='same')[int(n/2)])
    delay_arr = np.linspace(-0.5*n/sample_rate, 0.5*n/sample_rate, n)
    delay = delay_arr[np.argmax(corr)]
    return delay

From the results of this function, and from plotting the data, I can see the filtered data can lead the raw data. Why is that? Am I calculating the delay between the two signals correctly?


1 Answer 1


This is because you are measuring group delay which is not the causal time delay. See this existing post that demonstrates how a negative group delay can result and an intuition as to how it occurs.


  • $\begingroup$ Interesting. Practically, what does this mean with respect to the lag introduced by the filter? How can I measure it when such phenomenon occurs? $\endgroup$
    – dnclem107
    Feb 1 at 17:12
  • $\begingroup$ @dnclem107 read on to the next post linked at the bottom of the post I linked here where I explain how to compute the actual time delay instead of group delay. There are additional related posts linked at the bottom of that one. Read through those and it should hopefully answer your additional questions. $\endgroup$ Feb 1 at 18:56

Your Answer

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

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