Simple First Order Digital Filter Design

April 9, 2009
Introduction It is often necessary to filter data from sensors or audio streams in order to suppress unwanted noise. And, most of the time, a simple first order filter is all that is required. The technique discussed below...

Introduction

It is often necessary to filter data from sensors or audio streams in order to suppress unwanted noise. And, most of the time, a simple first order filter is all that is required. The technique discussed below describes a quick design solution that will allow you to design and implement a first order using fixed-point math.

Background

In the z-domain, the equation for a first order filter looks like:

Where:

In the time domain, the above transforms into:

The Meat of the Matter

If we replace:

with k and solve the above to get unity gain, then our difference equation can be simplified to:

The trick now is to determine what those k values need to be. First, let’s translate a to our cutoff frequency and T to our sampling rate:

a=2πfc
T=1/fs

k can now be readily derived given our desired cutoff frequency and sampling rate:

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:

yn = (1-0.9859)xn+0.9859yn-1
=0.0141xn+0.9859yn-1

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;

\}

Sponsored Recommendations

What are the Important Considerations when Assessing Cobot Safety?

April 16, 2024
A review of the requirements of ISO/TS 15066 and how they fit in with ISO 10218-1 and 10218-2 a consideration the complexities of collaboration.

Wire & Cable Cutting Digi-Spool® Service

April 16, 2024
Explore DigiKey’s Digi-Spool® professional cutting service for efficient and precise wire and cable management. Custom-cut to your exact specifications for a variety of cable ...

DigiKey Factory Tomorrow Season 3: Sustainable Manufacturing

April 16, 2024
Industry 4.0 is helping manufacturers develop and integrate technologies such as AI, edge computing and connectivity for the factories of tomorrow. Learn more at DigiKey today...

Connectivity – The Backbone of Sustainable Automation

April 16, 2024
Advanced interfaces for signals, data, and electrical power are essential. They help save resources and costs when networking production equipment.

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!