-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add fast bandpass filter #29
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this first pass is mostly to address some styling for the code.
mne_realtime/rt_filter.py
Outdated
filter_bank : array | ||
filter coefficients stored in array of shape (n_franges, filter_len (in samples)) | ||
""" | ||
filter_list = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filter_list = [] | |
filter_list = list() |
I would much rather speed up In this case I'm guessing that a direct call to |
@teonbrooks Thanks a lot for the code review! I will adapt it. Then I only "apply" them in a np convolution in |
Ahh, and we don't provide a way to pass the FIR filter directly. We do this with IIR but not FIR... We could in theory provide some way to do this in MNE. For maximum efficiency you could even compute the FFT of the filter once, and use it with the signal. We'd have to figure out an API for it, though. |
@larsoner Do you mean the iir_params keyword in mne.filter.filter_data? Also I am not sure about the FFT approach. This would also require a frequency transformed version of the data itself? Sorry if I don't really get this. For my intuition the fast approach would be simply to do the filtering in the time domain via a convolution with the precalculated filterbank. |
Alright, so I adapted some changes, simply because of the nice comments of @teonbrooks :) |
I think for now just add a comment along the lines that "someday MNE-Python could add support for precomputed FIR filters like it does for IIR" and in the meantime a PR just using Then this PR can just focus on getting the API right and getting it to work, and optimization / refactoring of MNE-Python can be done later if someone gets motivated to do it by performance concerns. |
hey @timonmerk, I will have next week to work on the project. sorry i've run away for a while. If you want to make some final adjustment, I can then merge these and we can iterate on a faster cadence. |
sorry for the delay @timonmerk. thanks! |
Based on #26 I want to push a faster bandpass filter estimation than the mne.filter.filter_data.
I also wrote a notebook where I compare the two on my private repo:
https://github.com/neuromodulation/py_neuromodulation/blob/main/examples/speedtests/speedtest_filter_vs_MNE.ipynb
There you can see that the initialized rt_filter.py estimation took ~6 ms while the mne.filter.filter_data took ~31 ms. Both is based on a sampling frequency of 500 Hz and 6 channels.
@teonbrooks Do you think it might be a good idea to upload such an example as well maybe in a folder called "real time tests"?