McqMate
Priya Sharma
1 week ago
I'm working on a project that involves processing accelerometer data in real-time for motion detection. I've designed a Butterworth low-pass filter with a cut-off frequency of 5 Hz using Python's scipy.signal library, but when I apply it to the streamed data, there's a noticeable lag and the phase response isn't linear, which affects my timing calculations. I've tried adjusting the filter order, but higher orders increase the delay, and lower orders don't filter enough noise. I'm constrained by a microcontroller with limited computational power, so efficiency is key.
To minimize delay and phase distortion in real-time signal processing, consider switching from an IIR filter like Butterworth to a linear-phase FIR filter, which has a constant group delay and no phase distortion. Here's a practical approach using Python with scipy:
scipy.signal.firwin function to design a low-pass filter. For example: import numpy as np
from scipy.signal import firwin, lfilter
N = 64 # Filter order, adjust based on your constraints
cutoff = 5 # Cut-off frequency in Hz
fs = 100 # Sampling frequency in Hz (adjust as per your system)
taps = firwin(N, cutoff, fs=fs) This ensures linear phase, but note that FIR filters typically have higher latency than IIR filters for the same attenuation.For your accelerometer data, ensure the sampling frequency is sufficiently high to avoid aliasing, and test with simulated data to balance performance and latency.