get_filter_coeff

selfeeg.augmentation.functional.get_filter_coeff(Fs: float, Wp: float, Ws: float, rp: float = np.float64(0.44552789422304506), rs: float = np.float64(16.478174818886377), btype: str = 'lowpass', filter_type: str = 'butter', order: int = None, Wn: float | List[float] = None, eeg_band: str = None) tuple[ArrayLike, ArrayLike][source]

returns the coefficients a and b necessary to run filtering augmentations.

It return two arrays a and b [coeff1] that are then passed to the scipy’s [coeff2] or torchaudio’s [coeff3] filtfilt function.

This function is internally called by other filtering functions when a and b coefficients are not given as input argument. It works following this priority pipeline:

  • if specific EEG bands are given, set Wp, Ws, rp, rs for filter design according to the given band

  • if order and Wn are not given, use previous parameter to design the filter

  • use Wn and order to get a and b coefficient to return

In other words the function will check if the following arguments were given using this order:

(Wp,Ws,rp,rs) –> (Wn, order) –> (a,b)

Parameters:
  • Wp (float or ArrayLike) – Passband edges in Hz. It can be a float for lowpass and highpass filters, or a length 2 scalar vector for bandpass and stopband filters.

  • Ws (float or ArrayLike) – Stopband edges in Hz. It can be a float for lowpass and highpass filters, or a length 2 scalar vector for bandpass and stopband filters.

  • rp (float, optional) –

    Ripple at bandpass in dB.

    Default = -20*log10(0.95)

  • rs (float, optional) –

    Ripple at stopband in dB.

    Default = -20*log10(0.15)

  • btype (str, optional) –

    Filter type. It can be any of the scipy’s btype argument. (e.g. ‘lowpass’, ‘highpass’, ‘bandpass’)

    Default = ‘lowpass’

  • filter_type (str, optional) –

    Which filter to design. The accepted values are ‘butter’, ‘ellip’, ‘cheby1’, ‘cheby2’.

    Default = “butter”

  • order (int, optional) –

    The order of the filter.

    Default = None

  • Wn (ArrayLike, optional) –

    The critical frequency or frequencies.

    Default = None

  • eeg_band (str, optional) –

    Any of the possible EEG bands. Accepted values are “delta”, “theta”, “alpha”, “beta”, “gamma”, “gamma_low”, “gamma_high”.

    Default = None

  • Fs (float, optional) –

    The sampling frequency in Hz. It must be given if eeg_band is also given.

    Default = None

Returns:
  • b (ArrayLike) – Array with the numerator coefficients of rational transfer function.

  • a (ArrayLike) – Array with the denominator coefficients of rational transfer function.

References