Fola-lad commited on
Commit
a79a9aa
·
1 Parent(s): 0dd88b3

Fix filtfilt padlen for 0.3Hz gravity filter, default 9-sample pad inadequate, use max safe pad

Browse files
Files changed (1) hide show
  1. src/phyphox_pipeline.py +5 -2
src/phyphox_pipeline.py CHANGED
@@ -83,10 +83,13 @@ def _butter_lp(data: np.ndarray, cutoff: float, fs: float = FS, order: int = 3)
83
  Filtered array, same shape as input
84
  """
85
  b, a = sp_signal.butter(order, cutoff / (fs / 2.0), btype="low")
 
 
 
86
  if data.ndim == 1:
87
- return sp_signal.filtfilt(b, a, data)
88
  return np.column_stack(
89
- [sp_signal.filtfilt(b, a, data[:, i]) for i in range(data.shape[1])]
90
  )
91
 
92
 
 
83
  Filtered array, same shape as input
84
  """
85
  b, a = sp_signal.butter(order, cutoff / (fs / 2.0), btype="low")
86
+ # Use maximum safe padding — critical for low cutoffs (e.g. 0.3 Hz needs
87
+ # ~167 samples to settle; scipy's default 9-sample pad is far too short).
88
+ padlen = min(len(data) - 1, max(3 * int(fs / cutoff), 9))
89
  if data.ndim == 1:
90
+ return sp_signal.filtfilt(b, a, data, padlen=padlen)
91
  return np.column_stack(
92
+ [sp_signal.filtfilt(b, a, data[:, i], padlen=padlen) for i in range(data.shape[1])]
93
  )
94
 
95