def sosfilt_zi(sos):
 from scipy.signal import lfilter_zi
 sos = np.asarray(sos)
 if ((sos.ndim != 2) or (sos.shape[1] != 6)):
  raise ValueError('sos must be shape (n_sections, 6)')
 n_sections = sos.shape[0]
 zi = np.empty((n_sections, 2))
 scale = 1.0
 for section in range(n_sections):
  b = sos[section, :3]
  a = sos[section, 3:]
  zi[section] = (scale * lfilter_zi(b, a))
  scale *= (b.sum() / a.sum())
 return zi

def sosfilt_zi ( sos ) : from scipy . signal import lfilter_zi sos = np . asarray ( sos ) if ( ( sos . ndim != 2 ) or ( sos . shape [ 1 ] != 6 ) ) : raise ValueError ( 'sos must be shape (n_sections, 6)' ) n_sections = sos . shape [ 0 ] zi = np . empty ( ( n_sections , 2 ) ) scale = 1.0 for section in range ( n_sections ) : b = sos [ section , : 3 ] a = sos [ section , 3 : ] zi [ section ] = ( scale * lfilter_zi ( b , a ) ) scale *= ( b . sum ( ) / a . sum ( ) ) return zi
compute an initial state zi for the sosfilt function .