Filtering Workflow¶
This example illustrates a filtering and signal conditioning workflow using qsp-filter.
Note
This is a conceptual example. Code snippets are illustrative. Verify against the current package API before use.
Overview¶
Filtering is a common preprocessing step in signal processing pipelines. qsp-filter provides tools for applying filters to quaternionic and structured signals, with filter designs that respect the algebraic properties of quaternionic data.
Scenario¶
You have a noisy quaternionic sensor signal and want to:
- Apply a low-pass filter to remove high-frequency noise
- Check that the filtered signal is suitable for downstream processing (e.g., orientation estimation)
Example¶
# Conceptual example — not a tested API call
import numpy as np
import qsp_core
import qsp_filter
# Load sensor data
raw = np.load("imu_data.npy") # Shape: (N, 4)
signal = qsp_core.QuaternionSignal(raw, sample_rate_hz=200.0)
# Design a low-pass filter at 10 Hz cutoff
filt = qsp_filter.design_lowpass(
cutoff_hz=10.0,
sample_rate_hz=200.0,
order=4,
)
# Apply the filter
filtered = qsp_filter.apply(filt, signal)
# Inspect the result
print(f"Input length: {len(signal)}")
print(f"Output length: {len(filtered)}")
print(f"Output dtype: {filtered.dtype}")
Frequency-domain filtering¶
For frequency-domain filtering, combine qsp-fft and qsp-filter:
# Conceptual example
import qsp_fft
import qsp_filter
# Transform to frequency domain
spectrum = qsp_fft.transform(signal)
# Apply a frequency-domain mask
masked = qsp_filter.mask_spectrum(spectrum, passband_hz=(0.5, 10.0))
# Inverse transform back to time domain
filtered = qsp_fft.inverse(masked)
Notes¶
- Filter boundary effects may affect the first and last few samples. Trim as needed.
- For causal real-time applications, prefer FIR filters over zero-phase IIR designs.
- The
applyfunction may support both forward and forward-backward (zero-phase) modes depending on the package version.