xdas.signal.sosfiltfilt#
- xdas.signal.sosfiltfilt(sos, da, dim='last', padtype='odd', padlen=None, parallel=None)[source]#
Apply a forward-backward digital filter using cascaded second-order sections.
- Parameters:
sos (array_like) – Array of second-order filter coefficients, must have shape
(n_sections, 6). Each row corresponds to a second-order section, with the first three columns providing the numerator coefficients and the last three providing the denominator coefficients.da (DataArray) – The data to be filtered.
dim (str, optional) – The dimension of da to which the filter is applied. Default is last.
padtype (str or None, optional) – Must be ‘odd’, ‘even’, ‘constant’, or None. This determines the type of extension to use for the padded signal to which the filter is applied. If padtype is None, no padding is used. The default is ‘odd’.
padlen (int or None, optional) –
The number of elements by which to extend da at both ends of dim before applying the filter. This value must be less than
da.sizes[dim] - 1.padlen=0implies no padding. The default value is:3 * (2 * len(sos) + 1 - min((sos[:, 2] == 0).sum(), (sos[:, 5] == 0).sum()))
The extra subtraction at the end attempts to compensate for poles and zeros at the origin (e.g. for odd-order filters) to yield equivalent estimates of padlen to those of filtfilt for second-order section filters built with scipy.signal functions.
parallel (bool or int, optional) – Number of threads to use. True uses all cores, False uses one, an int uses that many, None defers to the global xdas configuration. Default is None.
- Returns:
The filtered output with the same coordinates as da.
- Return type:
Notes
Splits on data discontinuities along dim.
Examples
>>> import scipy.signal as sp >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts
>>> da = wavelet_wavefronts() >>> sos = sp.iirfilter(4, 0.5, btype="low", output="sos") >>> xs.sosfiltfilt(sos, da, dim='time') <xdas.DataArray (time: 300, distance: 401)> [[ 0.04968 -0.063651 0.078731 ... -0.146869 0.135149 -0.283111] [-0.01724 0.018588 -0.037267 ... 0.025092 -0.107095 0.127912] [-0.004291 -0.002956 -0.032369 ... 0.078337 -0.150316 0.155965] ... [-0.068308 -0.06057 0.165391 ... -0.115742 -0.005265 0.19878 ] [-0.014123 0.039773 -0.063194 ... -0.090854 -0.053728 0.206149] [ 0.122203 0.188674 -0.231442 ... 0.304675 -0.452161 0.041323]] Coordinates: * time (time): 2023-01-01T00:00:00.000 to 2023-01-01T00:00:05.980 * distance (distance): 0.000 to 10000.000