neurosity/eeg-pipes

Compute initial state when creating filter operators

jdpigeon opened this issue · 2 comments

Currently, whenever data starts flowing through a pipe with a filter operator the outputs of the filter fluctuate wildly for a few seconds due to 'ringing' as the filter state adjusts to the signal.

In python projects such as muse-lsl, we've overcome this issue by computing an initial state for the filter before the signal is applied. This is easy to do in scipy with the lfilter_zi function, but does not appear to be implemented in fili.

Implementing this might require significant changes to our filtering code so we should probably wait on it until we've figured out how we're going to proceed with filtering, either sticking to fili or forking and developing our own library.

Spent a bunch of time on this today and think I'm close to having it implemented.

It turns out that the initial state for all fili's filters are arrays of 0s. I'm trying to improve this by calculating more appropriate initial states, like we do in muse-lsl's lsl-viewer. I've ported scipy's lfilter_zi function to JS and will experiment with adding into eeg pipes soon.

I've made the changes to fili and am assessing how it impacts EEG artifacts. Oddly, I don't see any large filter artifacts with or without the precomputation when testing against Muse data. Maybe these filter artifacts only appear at high frequency sampling rates.