Filter_Length Warning filter_data

  • MNE version: 0.24.0
  • operating system: Windows 11

I am trying to filter raw data which consists of 4 channels.

raw_data = Df[["RAW_TP9", "RAW_TP10", "RAW_AF7", "RAW_AF8"]]

    raw_data = raw_data.to_numpy()

    before_data = raw_data

    low_freq, highFreq = 0.5, 50

    s_freq = 256

    filtered_data = mne.filter.filter_data(raw_data, s_freq, low_freq, highFreq)

This is the output with the warning:

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 0.50
- Lower transition bandwidth: 0.50 Hz (-6 dB cutoff frequency: 0.25 Hz)
- Upper passband edge: 50.00 Hz
- Upper transition bandwidth: 12.50 Hz (-6 dB cutoff frequency: 56.25 Hz)
- Filter length: 1691 samples (6.605 sec)

D:\..\general_filtering.py:84: RuntimeWarning: filter_length (1691) is longer than the signal (4), distortion is likely. Reduce filter length or filter a longer signal.

It seems as the signal_length is set to the amount of channels instead of the length of each channel. Reading the docs, my input parameters look right tho. Any tips what might have been gone wrong?

what does raw_data.shape say? The channels should be the first dimension, the timepoints should be the second dimension. Probably calling raw_data = raw_data.T would solve your problem.

Thank you very much, am still confused why it is supposed to be that way but now it works.

you have a DataFrame, with columns being the channel names. Calling the to_numpy method thus gives you an array that has channels in the column dimension (the 2nd dimension), and timepoints in the first dimension. MNE functions expect the exact opposite. Using the .T (“transpose”) method on an array will “flip the array around” so that the input matches what MNE expects.