Continuity issue when applying an IIR filter on successive time-frames

后端 未结 1 1530
孤独总比滥情好
孤独总比滥情好 2020-12-20 05:51

I would like to apply a FIR or IIR filter (example: lowpass filter) on successive blocks/time-frames of 1024 samples each.

Possible applications:

相关标签:
1条回答
  • 2020-12-20 06:02

    As mentioned by @sobek in a comment, it's of course needed to specify the initial conditions to allow continuity. This is done with the zi parameter of lfilter.

    The problem is solved by changing the main loop by:

    while True:
        b, a = butter(2, 2.0 * f / sr, btype='low')
        if pos == 0:
            zi = lfilter_zi(b, a)
        y[pos:pos+N], zi = lfilter(b, a, x[pos:pos+N], zi=zi)
        pos += N
        f -= 1 
        if pos+N > len(x):
            break
    

    This seems to work even if the filter's cutoff (and thus the a and b) is modified at each iteration.

    0 讨论(0)
提交回复
热议问题