neurodsp.filt.filter_signal

neurodsp.filt.filter_signal(sig, fs, pass_type, f_range, filter_type='fir', n_cycles=3, n_seconds=None, remove_edges=True, butterworth_order=None, print_transitions=False, plot_properties=False, return_filter=False)[source]

Apply a bandpass, bandstop, highpass, or lowpass filter to a neural signal.

Parameters
sig1d or 2d array

Time series to be filtered.

fsfloat

Sampling rate, in Hz.

pass_type{‘bandpass’, ‘bandstop’, ‘lowpass’, ‘highpass’}

Which kind of filter to apply:

  • ‘bandpass’: apply a bandpass filter

  • ‘bandstop’: apply a bandstop (notch) filter

  • ‘lowpass’: apply a lowpass filter

  • ‘highpass’ : apply a highpass filter

f_rangetuple of (float, float) or float

Cutoff frequency(ies) used for filter, specified as f_lo & f_hi. For ‘bandpass’ & ‘bandstop’, must be a tuple. For ‘lowpass’ or ‘highpass’, can be a float that specifies pass frequency, or can be a tuple and is assumed to be (None, f_hi) for ‘lowpass’, and (f_lo, None) for ‘highpass’.

n_cyclesfloat, optional, default: 3

Length of filter, in number of cycles, at the ‘f_lo’ frequency, if using an FIR filter. This parameter is overwritten by n_seconds, if provided.

n_secondsfloat, optional

Length of filter, in seconds, if using an FIR filter. This parameter overwrites n_cycles.

filter_type{‘fir’, ‘iir’}, optional

Whether to use an FIR or IIR filter. The only IIR filter offered is a butterworth filter.

remove_edgesbool, optional, default: True

If True, replace samples within half the kernel length to be np.nan. Only used for FIR filters.

butterworth_orderint, optional

Order of the butterworth filter, if using an IIR filter. See input ‘N’ in scipy.signal.butter.

print_transitionsbool, optional, default: True

If True, print out the transition and pass bandwidths.

plot_propertiesbool, optional, default: False

If True, plot the properties of the filter, including frequency response and/or kernel.

return_filterbool, optional, default: False

If True, return the filter coefficients.

Returns
sig_filt1d array

Filtered time series.

kernel1d array or tuple of (1d array, 1d array)

Filter coefficients. Only returned if return_filter is True.

Examples

Apply an FIR band pass filter to a signal, for the range of 1 to 25 Hz:

>>> from neurodsp.sim import sim_combined
>>> sig = sim_combined(n_seconds=10, fs=500,
...                    components={'sim_powerlaw': {}, 'sim_oscillation' : {'freq': 10}})
>>> filt_sig = filter_signal(sig, fs=500, pass_type='bandpass',
...                          filter_type='fir', f_range=(1, 25))

Examples using neurodsp.filt.filter_signal

Filtering

Filtering

FIR Filters

FIR Filters

IIR Filters

IIR Filters

Filter Checks

Filter Checks