-
Notifications
You must be signed in to change notification settings - Fork 1
[Abstract] Filter
Filter classes allow you to design digital filters! Filters can be very useful to cancel noise and artifacts that come along with the acquisition of your Biosignals.
Filter is an abstract class, meaning objects cannot be instantiated from it. You need to instantiate one of its types:
- Frequency Filter [See Class] >> applies an H function in the Fourier domain.
- Time Filter [See Class] >> applies a convolution operation in the time domain.
It's so easy, let's do it 👩🏽💻! To apply any 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.
To restore the raw samples of a Biosignal, just call undo_filters
. Like this:
biosignal.undo_filters()
If you want to use your own personalized Filter, you can code it to work with this framework. Just create a class (e.g. MyFilter
) that extends Filter
and complies with its structure. To do so, you'll need to implement two methods:
-
_setup(sampling_frequency:float)
will be called before the Filter is applied to each channel. It is generally used to get some information from the sampling frequency of a channel that the Filter will need to operate. If you don't need to setup anything before application, just leave its body empty withpass
. -
_visit(samples:array) -> array
will visit every segment of samples the Biosignal contains and apply the filter operation to them. Just return what the output is to be when the filter is applied to some input sequence of samples.
You don't need to worry about how the Filter will be applied to every segment of samples. That is already part of the framework. The only thing we need from you is to implement your personalized operation inside _visit
🧑🏻💻.