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

The Importance of PCB Design in Consumer Products

April 25, 2024
Explore the importance of PCB design and how Fusion 360 can help your team react to evolving consumer demands.

PCB Design Mastery for Assembly & Fabrication

April 25, 2024
This guide explores PCB circuit board design, focusing on both Design For Assembly (DFA) and Design For Fabrication (DFab) perspectives.

What is Design Rule Checking in PCBs?

April 25, 2024
Explore the importance of Design Rule Checking (DRC) in manufacturing and how Autodesk Fusion 360 enhances the process.

Unlocking the Power of IoT Integration for Elevated PCB Designs

April 25, 2024
What does it take to add IoT into your product? What advantages does IoT have in PCB related projects? Read to find answers to your IoT design questions.

Comments

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