We have two lowpass filters with a different cutoff value:
b, a = signal.butter(2, 0.125)
b2, a2 = signal.butter(2, 0.140)
When applying the first filter to x[0:10000]
and the second to x[10000:20000]
with lfilter
, we have to use initial conditions for the output to be "continuous", as seen here in the answer of Continuity issue when applying an IIR filter on successive time-frames:
zi = lfilter_zi(b, a)
x[0:10000], zi = lfilter(b, a, x[0:10000], zi=zi)
x[10000:20000], zi = lfilter(b2, a2, x[10000:20000], zi=zi)
Question: how to do the same when applying filtfilt
(forward and backwards filtering), to ensure continuity when using filters on consecutive blocks, as there is no zi
initial conditions parameter?
filtfilt
lends itself to block-processing, unfortunately. You may have to search for a specialized implementation or implement something yourself. – Bondonlfilter
(that has thezi
initial condition parameter, so this one works well for block-processing) there is a delaydelta
for a step function (Heavyside) to reach, say, 95% of the final value. I noticedfiltfilt
compensates this delay (to the price of a pre-ringing), that's why I was using it. I could also uselfilter
and shift the time-axis bydelta/2
to avoid the too-big latency caused bylfilter
. How is called thisdelta
for a filter? Is there a way to compute it? – Loatsdelta
is usually called the time constant of the step response and is denoted by the greek letter tau. – Bondonx
is separated into several signalsx = x1 + x2 + x3
. Then I'm applying modifications (filtering, etc.) onx1
, this givesx1_modified
. Then I'm resummingx_modified = x1_modified + x2 + x3
. If there is some delay inx1
's modification, it will be weird when resumming withx2
andx3
which are not delayed. That's why I was looking for delay compensation, and that's why I was usingfiltfilt
instead oflfilter
. – Loatsx1
has to be modified with a cutoff that varies along time (thus this question), I have to do it "by blocks". Thus this problemfiltfilt
+ continuity when doing block processing! This is the full picture :) – Loats