If the error is saying:
ValueError: The length of the input vector x must be greater than padlen, which is 6 [or whatever].
Why not filtering the length of the signal sub-elements > 6?
df = df[[len(x) > 6 for x in df['listSignal']]]
For me, it was already enough to filter for a len(x) > 1 to avoid the error.
I had quite a few 0-length and 1-length signal lists in the nested 'test' column. I assume that > 1 is needed since only a length of 2 provides one item on the left and one on the right.
The functions that I borrowed from https://github.com/leilamr/LowPassFilter stay untouched:
import pandas as pd
from scipy.signal import butter, freqz, filtfilt
def butter_lowpass(cutoff, fs, order=5):
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(order, normal_cutoff, btype='low', analog=False, fs=None)
return b, a
def butter_lowpass_filter(x, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
return filtfilt(b, a, x)
No error with the filtered df len(x) > 1 (try yourself, yours might be higher):
df = df[[len(x) > 1 for x in df['test']]]
df['testFilt'] = [butter_lowpass_filter(x, cutoff, fs, order) for x in df['test']]
Thanks go to @DavideNardone with his idea of filtering the return value of the function, wheras I am now filtering the main df in advance, the idea is the same.