Two links discussing software implementations of low pass filters can be found at stackexchange and Kirit Chatterjee’s blog.
From stackexchange:
The main benefit of a “proper” low pass filter is that you have a zero at Nyquist and you get much more attenuation very close to Nyquist.
If you care, the C code is almost identical and easy enough to write. Using your notation it looks like
y[n]=(1−a)⋅y[n−1]+a⋅(x[n]+x[n−1])/2
The only difference is that instead of adding just the current input sample, you add the average of the last two inputs.
and from Kirit Chatterjee:
int RawData;
signed long SmoothDataINT;
signed long SmoothDataFP;
int Beta = 4; // Length of the filter < 16
void main (void){
while(1){
// Function that brings Fresh Data into RawData
RawData = GetRawData();
RawData <<= FP_Shift; // Shift to fixed point
SmoothDataFP = (SmoothDataFP<< Beta)-SmoothDataFP;
SmoothDataFP += RawData;
SmoothDataFP >>= Beta;
// Don't do the following shift if you want to do further
// calculations in fixed-point using SmoothData
SmoothDataINT = SmoothDataFP>> FP_Shift;
}
}