I have a stream of 250 samples per second arriving at a pipeline stage which looks something like this simplified example.
class PipeLineStage(...):
historical_buffer = []
def _process(self, sample):
historical_buffer.append(sample)
altered_sample = ...
return altered_sample
_process
gets called indirectly by the pipeline manager whenever a new sample arrived from the device and the returned value it passed to the next stage.
I want the effect of the function to apply a 50hz notch filter.
So my question is: how should I ideally window/buffer the signal of the incoming samples?
Specifically, How should I:
- decide how many samples are optimal to filter out a 50hz signal when the sample rate is 250hz? (with minimal delay for live viewing)
- manage the windowing of a continuous signal; worth applying an lfilter over overlapping buffers e.g. samples 1-100, then 50-150, then 100-200 etc? or is it just as good to clear the buffer after each application of the lfilter and have separate/discrete windows, e.g. samples 0-100, 100-200 etc?
In other words, my concern it whether applying a butterfilter with lfilter to discrete windows will introduce discontinuities or other artefacts in the filtered signal significant enough to justify the performance cost of a rolling window.
Does the way I'm thinking about this make sense?