butter(ts, /, fc, *, order=2, btype='lowpass', filtfilt=True)[source]#

Apply a Butterworth filter to a TimeSeries.

Filtering occurs on the first axis (time). If the TimeSeries contains missing samples, a warning is issued, missing samples are interpolated using a first-order interpolation before filtering, and then replaced by np.nan in the filtered signal.

  • ts (TimeSeries) – Input TimeSeries.

  • fc (float | tuple[float, float]) – Cut-off frequency in Hz. This is a float for single-frequency filters (lowpass, highpass), or a tuple of two floats (e.g., (10., 13.) for two-frequency filters (bandpass, bandstop)).

  • order (int) – Optional. Order of the filter. Default is 2.

  • btype (str) – Optional. Can be either “lowpass”, “highpass”, “bandpass” or “bandstop”. Default is “lowpass”.

  • filtfilt (bool) – Optional. If True, the filter is applied two times in reverse direction to eliminate time lag. If False, the filter is applied only in forward direction. Default is True.


A copy of the input TimeSeries, which each data being filtered.

Return type



ValueError – If sample rate is not constant, or if there is no data to filter.