xdas.signal.filtfilt#
- xdas.signal.filtfilt(b, a, da, dim='last', padtype='odd', padlen=None, method='pad', irlen=None, parallel=None)[source]#
Apply a digital filter forward and backward to a signal.
This function applies a linear digital filter twice, once forward and once backwards. The combined filter has zero phase and a filter order twice that of the original.
The function provides options for handling the edges of the signal.
- Parameters:
b ((N,) array_like) – The numerator coefficient vector of the filter.
a ((N,) array_like) – The denominator coefficient vector of the filter. If
a[0]is not 1, then both a and b are normalized bya[0].da (DataArray) – The array of 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 is3 * max(len(a), len(b)).method (str, optional) – Determines the method for handling the edges of the signal, either “pad” or “gust”. When method is “pad”, the signal is padded; the type of padding is determined by padtype and padlen, and irlen is ignored. When method is “gust”, Gustafsson’s method is used, and padtype and padlen are ignored.
irlen (int or None, optional) – When method is “gust”, irlen specifies the length of the impulse response of the filter. If irlen is None, no part of the impulse response is ignored. For a long signal, specifying irlen can significantly improve the performance of the filter.
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.
Notes
Splits on data discontinuities along dim.
- Returns:
The filtered output with the same coordinates as da.
- Return type:
Examples
>>> import scipy.signal as sp >>> import xdas.signal as xs >>> from xdas.synthetics import wavelet_wavefronts
>>> da = wavelet_wavefronts() >>> b, a = sp.iirfilter(4, 0.5, btype="low") >>> xs.lfilter(b, a, da, dim='time') <xdas.DataArray (time: 300, distance: 401)> [[ 0.004668 -0.005968 0.007386 ... -0.0138 0.01271 -0.026618] [ 0.008372 -0.01222 0.022552 ... -0.041387 0.046667 -0.093521] [-0.008928 0.002764 0.012621 ... -0.032496 0.039645 -0.076117] ... [ 0.012576 -0.1661 0.196026 ... 0.048191 -0.014532 -0.033122] [-0.06294 -0.092234 0.316862 ... 0.045337 -0.139729 0.094086] [-0.035233 0.036613 0.044002 ... -0.053585 -0.121344 0.241415]] Coordinates: * time (time): 2023-01-01T00:00:00.000 to 2023-01-01T00:00:05.980 * distance (distance): 0.000 to 10000.000