neurodsp.filt.filter_signal_fir¶
- neurodsp.filt.filter_signal_fir(sig, fs, pass_type, f_range, n_cycles=3, n_seconds=None, remove_edges=True, print_transitions=False, plot_properties=False, return_filter=False)[source]¶
Apply an FIR filter to a signal.
- Parameters
- sigarray
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, defined at the ‘f_lo’ frequency. This parameter is overwritten by n_seconds, if provided.
- n_secondsfloat, optional
Length of filter, in seconds. This parameter overwrites n_cycles.
- remove_edgesbool, optional
If True, replace samples within half the kernel length to be np.nan.
- print_transitionsbool, optional, default: False
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 of the FIR filter.
- Returns
- sig_filtarray
Filtered time series.
- filter_coefs1d array
Filter coefficients of the FIR filter. Only returned if return_filter is True.
Examples
Apply a band pass FIR filter to a simulated signal:
>>> 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_fir(sig, fs=500, pass_type='bandpass', f_range=(1, 25))
Apply a high pass FIR filter to a signal, with a specified number of cycles:
>>> sig = sim_combined(n_seconds=10, fs=500, ... components={'sim_powerlaw': {}, 'sim_oscillation' : {'freq': 10}}) >>> filt_sig = filter_signal_fir(sig, fs=500, pass_type='highpass', ... f_range=(2, None), n_cycles=5)