Simple software low pass filter - Signal Processing Stack Exchange most recent 30 from dsp.stackexchange.com 2019-11-12T18:21:31Z https://dsp.stackexchange.com/feeds/question/39063 https://creativecommons.org/licenses/by-sa/4.0/rdf https://dsp.stackexchange.com/q/39063 4 Simple software low pass filter jurij https://dsp.stackexchange.com/users/11644 2017-04-08T15:19:32Z 2017-04-13T02:32:35Z <p>I am measuring voltages and currents of a 3-phase electrical machine and I need to calculate the power. Every interrupt (frequency between 30-70kHz) I get values (voltages, currents) from analogue-digital converter and I need to do a simple calculation to determine power. However, I was told to use averaging with a first order filter with a time constant of approximate 1s for the power calculation. This, I believe, means low pass filter with a frequency of approximately 1Hz? What is the simplest solution to this? Moving average?</p> https://dsp.stackexchange.com/questions/39063/-/40070#40070 4 Answer by Juancho for Simple software low pass filter Juancho https://dsp.stackexchange.com/users/330 2017-04-08T18:02:18Z 2017-04-13T02:32:35Z <p>A first order lowpass filter is usually implemented like this:</p> <p>$$p[n] = \alpha p[n-1] + (1-\alpha) pi[n]$$</p> <p>Where $p[n]$ is your filtered power estimation, $p[n-1]$ is the previous result, $pi[n]$ is your new measurement (probably the product of instantaneous voltage and current measurements), and $\alpha$ is a positive parameter just less than 1.</p> <p>The nearer $\alpha$ gets to 1, the larger the time constant (lower cutoff frequency) of your filter. But beware, especially in embedded systems with limited precision, that getting too near to 1 can make your filter unstable, or at least have problems due to numerical precision.</p> <p>The <a href="https://en.wikipedia.org/wiki/Low-pass_filter#Simple_infinite_impulse_response_filter" rel="nofollow noreferrer">cutoff frequency</a> for that filter is around $f_s \frac{1-\alpha}{2\pi\alpha}$, where $f_s$ is your sampling frequency.</p>