Spaces:
Runtime error
Runtime error
Revert to window-mean gravity
Browse files- src/phyphox_pipeline.py +12 -9
src/phyphox_pipeline.py
CHANGED
|
@@ -495,23 +495,26 @@ def process_phyphox_files(
|
|
| 495 |
if duration > 60:
|
| 496 |
warnings.append(f"Long recording ({duration:.0f} s) — {n_windows} windows extracted.")
|
| 497 |
|
| 498 |
-
# Apply noise filters
|
| 499 |
-
# windowing — this is the UCI pipeline order. The 0.3 Hz LP filter needs
|
| 500 |
-
# the full continuous signal to settle; applying it per-window (128 samples)
|
| 501 |
-
# produces transient artefacts because 0.3 Hz requires ~167 samples to settle.
|
| 502 |
acc_50 = _butter_lp(_median_filt(acc_50), cutoff=20.0)
|
| 503 |
gyro_50 = _butter_lp(_median_filt(gyro_50), cutoff=20.0)
|
| 504 |
-
grav_full = _butter_lp(acc_50, cutoff=0.3)
|
| 505 |
-
body_full = acc_50 - grav_full
|
| 506 |
|
| 507 |
all_features = []
|
| 508 |
dt = 1.0 / FS
|
| 509 |
|
| 510 |
for start in range(0, n - WINDOW + 1, STEP):
|
| 511 |
end = start + WINDOW
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 515 |
|
| 516 |
# Jerk: finite difference → (127, 3)
|
| 517 |
body_jerk = np.diff(body, axis=0) / dt
|
|
|
|
| 495 |
if duration > 60:
|
| 496 |
warnings.append(f"Long recording ({duration:.0f} s) — {n_windows} windows extracted.")
|
| 497 |
|
| 498 |
+
# Apply noise filters to the full signal before windowing.
|
|
|
|
|
|
|
|
|
|
| 499 |
acc_50 = _butter_lp(_median_filt(acc_50), cutoff=20.0)
|
| 500 |
gyro_50 = _butter_lp(_median_filt(gyro_50), cutoff=20.0)
|
|
|
|
|
|
|
| 501 |
|
| 502 |
all_features = []
|
| 503 |
dt = 1.0 / FS
|
| 504 |
|
| 505 |
for start in range(0, n - WINDOW + 1, STEP):
|
| 506 |
end = start + WINDOW
|
| 507 |
+
aw = acc_50[start:end] # (128, 3)
|
| 508 |
+
gw = gyro_50[start:end] # (128, 3)
|
| 509 |
+
|
| 510 |
+
# Gravity separation: window mean as gravity estimate.
|
| 511 |
+
# The UCI pipeline used a 0.3 Hz LP on a full continuous recording.
|
| 512 |
+
# That filter needs ~167 samples to settle; a 10-second clip gives only
|
| 513 |
+
# ~500 samples total, so the filter corrupts all but the central window.
|
| 514 |
+
# The window mean is equivalent for symmetric activities (oscillations
|
| 515 |
+
# cancel over a stride cycle) and exact for static activities.
|
| 516 |
+
grav = np.tile(aw.mean(axis=0), (WINDOW, 1))
|
| 517 |
+
body = aw - grav
|
| 518 |
|
| 519 |
# Jerk: finite difference → (127, 3)
|
| 520 |
body_jerk = np.diff(body, axis=0) / dt
|