Skip to content

DanSop/CMSIS-DSP-with-SciPy-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CMSIS-DSP & SciPy IIR Coefficients Generation and Testing

Information.

This project uses SciPy and the CMSIS-DSP library to calculate IIR filter coefficients. These coefficients are printed and can be implemented in any C/C++ project that utilizies the ARM CMSIS DSP library. The script uses Butterworth bandpass filters to create a filter bank. Each signal is added up at the end to reconstruct the original signal with gain modifiers if desired. The block diagram is shown below:

block

The C file, Eq_ARM.c, shows an example of how to apply the IIR filter using the coefficients. This file is generic and does not include data obtaining or streaming. The Python file, Eq_SciPi_ARM.py, shows how the coefficients are generating alongside applying the coefficients via SciPy and an ARM CMSIS-DSP library which is a direct wrapper to the C library. The Python code is in a single file for simplicity.

The goal here is to have the SciPy and CMSIS-DSP plots to "mirror" one another to ensure the filters are being applied properly. It essentially provides a quick way to generate a filter bank, test the filter bank with any signal, and copy the generated coefficients in the Q31 format to any external project utizling CMSIS-DSP. The scripts and filters, of course, can be editted and used however needed.

SciPy: https://docs.scipy.org/doc/scipy/
CMSIS-DSP : https://www.keil.com/pack/doc/CMSIS/DSP/html/index.html

Installation and Usage

To install the packges: pip install -r requirements.txt

To launch the Python script: python Eq_SciPy_ARM.py or python3 Eq_SciPy_ARM.py

Tested with Python 3.11.x. as the distutils package is removed in python version 3.12. A work around for this version is cited in "https://stackoverflow.com/questions/69919970/no-module-named-distutils-but-distutils-installed". Note you will need some Wav input file named "input_file.wav" for testing if the Wav input is selected as True. A default wav file was included.

If you wish to apply gains to the signals before they are reconstructed, line 206 & 277 in Eq_SciPy_ARM.py show an example of gaining the first band (signal_list[0]) by a factor of 1. Add more and change the gain factor as needed.

Example Plot with a 16 kHz Wav file input - no filtering.

The input signal:

input

The filter being apply via SciPy:

scipy

The filter being apply via the ARM CMSIS-DSP library:

arm

The logarithmic plot of the filter bank. Note that the edge and center frequencies for the bands not calculated are shown:

log-filter

The linear plot of the filter bank:

linear

Example Plot with a generated signal input - filtering.

The signal input is a simple sign wave with a base frequency of 80 Hz and a noise frequency at 2 kHz. Every band except the band containing 80 Hz is attenutately heavily.

The original signal plot:

forig

The signal filtered via SciPy:

fscipy

The signal filtered via the ARM CMSIS-DSP library:

farm

About

IIR Filter Implementation and coefficient calculator.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published