Hacker News new | ask | show | jobs
by buildingrobots 2 days ago
You can choose their version of alpha by picking a cutoff frequency f and setting alpha = exp(-2*pi*f*dt) where dt is your sample rate. f will be the ≈-3dB point of your filter where frequencies above it are reduced by 0.707 or more.
1 comments

That gives you the time constant for the 63% step response, but that's not quite the same thing as the 3-dB cutoff, due to frequency warping. I do this to get an alpha value for cutoff_Hz at a given sampling interval dt_s:

    double omega_c = TWO_PI * cutoff_Hz * dt_s;     
    double b = 4.0 - (2.0 * cos(omega_c));
    
    return 1.0 - ((b - sqrt(b*b - 4.0)) * 0.5);
Probably won't matter most of the time, though, when you're just trying to make some noise go away.