As an example, let’s assume a sampling rate of 44.1Khz and a desired cutoff frequency of 100Hz. Then, we can derive k from:
Our difference equation that realizes this filter becomes:
To be sure, we can substitute the identity term:
into the equation for H(z) above and then use Mathcad to create a bode plot:
According to Mathcad, the magnitude of the above plot equals 0.707 at 100 Hz which is equivalent to the response of an analog filter at the same frequency.
The code to implement this filter looks like:
// Example code for 100Hz Digital Low Pass Filter
// Coefficients are designed for 44.1Khz Sampling rate
// The int type is assumed to be 16 bits
#define k1 0.9859 // the k coefficient
#define k2 1-k1 // 1-k
int 100hz_lpf(int x)
{
static int y1 = 0;
int y0;
y0 = k2*x + k1*y1;
y1 = y0;
return y0;
}
advertisement
advertisement