Skip to content

[Class] Frequency Domain Filter

João Saraiva edited this page May 27, 2022 · 4 revisions

This class allows you to design frequency domain filters! Conventional frequency filters can be very useful to cancel noise and artifacts that come along with the acquisition of your Biosignals.

How to instantiate a Filter

Give the following design properties:

  • 📈 fresponse: The frequency response of the filter. Choose one from FrequencyResponse:

    • FIR - Finite Impulse Response
    • BUTTER - IIR Butterworth
    • CHEBY1 - IIR Chebyshev 1
    • CHEBY2 - IIR Chebyshev 2
    • ELLIP - IIR Elliptic
    • BESSEL - IIR Bessel
  • 📉 band_type: If frequency bands should be passed or rejected. Choose one from BandType:

    • LOWPASS - Low-pass
    • HIGHPASS - High-pass
    • BANDPASS - Band-pass
    • BANDSTOP - Band-stop
  • 🔪 cutoff: If LOWPASS or HIGHPASS are chosen, give 1 frequency cutoff in Hz (in float). If BANDPASS or BANDSTOP are chosen, give 2 frequency cutoffs in Hz (in a tuple of floats).

  • #️⃣ order: The filter order (in int), i.e., the number of coefficients of its H function. The more the better the result, but also the worst the computation time.

Example of 4th order Lowpass at 15 Hz

filter = FrequencyFilter(fresponse=FrequencyResponse.ELLIP, band_type=BandType.LOWPASS, cutoff=15, order=4)

Example of 4th order Bandpass between 5 and 30 Hz

filter = FrequencyFilter(fresponse=FrequencyResponse.ELLIP, band_type=BandType.BANDPASS, cutoff=(5, 30), order=4)

Getters and Setters

You can get and reset any of the four properties. You may also get the numerator and denominator coefficients of the H function computed for the last Biosignal filtered with the filter, using:

  • last_numerator_coeficients
  • last_denominator_coefficients

Raise AttributeError when no coefficients have been computed yet.

Apply Filter

It's so easy, let's do it 👩🏽‍💻! To apply a Filter you have designed (e.g. f1) to a Biosignal, just call filter from that Biosignal and give f1:

biosignal.filter(f1)

The filter will be applied to every channel of biosignal and return 0 in case of success.

Plot the Frequency Response

To draw a Bode plot of the Filter applied to a Biosignal, use plot_bode. Example:

filter.plot_bode(show=True)

For details about plotting, see the rules of methods plot_{}.