CCS News

Easy Digital Filtering

Wednesday 22 December, 2021

This article gives an overview of how to implement a simple low pass and high pass filter for audio using dsPIC® processors. The example code implements a tone control pot. Center does not filter, and when turned counter-clockwise. the bass is increased and clockwise increases the trebble.

Our example uses a structure for each sample point that is a complex number. It has a real and imaginary part to allow other areas of the program that use them both. For our use we only need the real part.

The pseudo-code for a 3 pole filter looks like this:

The algorithm uses a set of coeficient constants that determine if the filter is low pass or high pass and what the cutoff frequency is. In our example we want the constants to change based on the pot setting. These constants are based on a 8khz sample rate.

The acca register is a built in accumulator in the processors with a DSP. The DSP engine has a bult in instruction to help with code like "acca += K[kp++] * window[j]." It looks like this in assembly:

mac W4*W5,A

Notice in the assembly language how C variables are referenced. Pay close attention to when pointers are being used as opposed to straight values.

Like us on Facebook. Follow us on Twitter.

About CCS:

CCS is a leading worldwide supplier of embedded software development tools that enable companies to develop premium products based on Microchip PIC® MCU and dsPIC® DSC devices. Complete proven tool chains from CCS include a code optimizing C compiler, application specific hardware platforms and software development kits. CCS' products accelerate development of energy saving industrial automation, wireless and wired communication, automotive, medical device and consumer product applications. Established in 1992, CCS is a Microchip Premier 3rd Party Partner. For more information, please visit

PIC® MCU, MPLAB® IDE, MPLAB® ICD2, MPLAB® ICD3 and dsPIC® are registered trademarks of Microchip Technology Inc. in the U.S. and other countries.