Create FIR Filters in Software

Jon Titus

October 2, 2013

2 Min Read
Create FIR Filters in Software

A demonstration of FIR filters in operation completes this series of columns. For this demonstration, I used an ARM mbed module with an NXP LPC1768 microcontroller (ARM Cortex-M3 processor). Although the Cortex-M3 lacks floating-point-math hardware, ARM software libraries can handle 32-bit floating-point math. Also, the mbed community of programmers has created many examples, including an FIR filter.

The programmers used MATLAB to produce 29 coefficients for a low-pass FIR filter with a 6000Hz cut-off frequency (fc). Unfortunately, they provided no other filter specifications. The discrete Fourier transform (DFT) plot for the 29 coefficients provided the missing data (Figure A). At -3 dB, fc equals 5500Hz and stop-band attenuation reaches -55 dB at 9000Hz.

113155_544754.jpg

The filter programmers used an algorithm within the code to produce sine waves at 1000Hz and at 15kHz. They added the two signals to create a test values "sampled" at 48 ksamples/sec. The program worked well and produced filtered values I analyzed with an Excel DFT. The result showed one main frequency at about 1125Hz.

The original C/C++ program compared the FIR-filter's output data with the original 1000Hz signal and gave a "Success" or "Failed" result. I changed the code to transmit the filtered values to my lab PC so I could drop them into Excel and run a DFT. Next, I changed the 15kHz signal to 7500Hz and ran the program. You can see the DFT results in Figure B. The original 1000- and 7500-Hz test signals had the same amplitude.

113205_925174.jpg

113237_126116.jpg

I then used the ScopeFIR software's Parks-McClellan algorithm to create new FIR coefficients for the 29-tap low-pass filter. I specified fc at 5500Hz, and a stop-band frequency of 9000Hz, with a stop-band attenuation at -55 dB and one dB of ripple in the pass band. The results gave a maximum 0.87-dB ripple and a 56.2-dB attenuation. A plot of the frequency response for the resulting coefficients shows an attenuation of about 12.5 dB at 7500Hz, which agrees with the DFT plot of the filter's output data shown in Figure C.

Unlike discrete components, the coefficient values in FIR-filter software do not drift with time, temperature shifts, or supply-voltage changes. If you require adaptive filtering, software can use a lookup table and change filter coefficients on the fly. And simulation of filters gives the exact response you will find in practice.

A thank you goes to Grant Griffin at Iowegian International for use of the Professional ScopeFIR software.

The original mbed filter software can be found here and my code can be found here.

Related posts:

Sign up for the Design News Daily newsletter.

You May Also Like