Open cbrnr opened 8 months ago
This is probably because we use overlap-add filtering using FFTs. As soon as you take the FFT you get all NaNs so that whole chunk will be NaN. A potential fix would be to if not np.isfinite(x).all():
and in that case use slower time-domain convolution. We could do this just for the given segment of data that has the issue, i.e., within the overlap-add loop. I don't think it would be too painful performance wise since np.isfinite
should be much faster than the actual FFTs/IFFTs and triggering the slower time-domain path should be rare.
This would be great! Do you know why this only happens with high-pass and not with low-pass filters?
Also, I tried using raw.filter(l_freq=5, h_freq=None, method="iir")
, which should not use overlap-add (https://github.com/mne-tools/mne-python/blob/main/mne/filter.py#L1109-L1112), the entire channels gets zapped.
Do you know why this only happens with high-pass and not with low-pass filters?
The high-pass is likely a longer filter. Then somewhere we decide what length FFTs to use in overlap-add filtering. It's probably some combination of those two things.
Also, I tried using [IIR filtering], the entire channels gets zapped.
Yeah that's a consequence of the "infinite" in "infinite impulse response". One NaN value will spread to all other values when forward-backward filtering.
But do you think we can/should make IIR filtering work with missings?
No I think for IIR the right thing to do is for people to annotate_nan
then segments can/should be processed separately by raw.filter
by setting skip_by_annotation
appropriately
Description of the problem
I'm not sure if highpass filters play nicely with (raw) data containing NaNs. If I filter such a signal, the NaN segment seems to get extremely long, and I can't explain why. This does not happen with lowpass filters.
Steps to reproduce
The following MWE creates a raw object with 3 channels and a duration of 25s. The second channel (channel 1) has missing data (NaNs) in the first second. After highpass-filtering, the initial 14s are missing, which seems very long given the filter specs.
Expected results
I'd expect the filtered signal to contain fewer missing values.
Actual results
Original signals:
Filtered signals:
Filter design logging messages:
Additional information