See this repo. This uses the inline Arm Thumb assembler throughout and so is only suitable for STM targets. Testing was on a Pyboard.
It supports real time finite impulse response (FIR) filtering, so you can input an analog signal, filter it and output it to a DAC. Filters may have arbitrary characteristics including high pass, low pass, bandpass and band stop. A link to an online calculator is provided; this enables FIR coefficients to be computed from a desired set of filter characteristics.
It now also supports non-realtime filtering, intended primarily for post-processing signals acquired using the ADC read_timed and read_timed_multi methods. It supports FIR filtering, convolution, decimation and auto- and cross-correlation. The non-realtime routines may also be applied to arbitrary float arrays, making them suitable for processing data from other sources.
While these algorithms are easy to implement in Python I found performance problematic in an application which iterated acquisition/filter passes, hence this fast solution.
Fast digital filters
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Fast digital filters
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Fast digital filters
I have enhanced the realtime filters with a view to making them cross-platform. The inline Assembler FIR and moving average filters now support ARMV6 so they can run on RP2 (Raspberry Pico etc). There is also a Viper version. This should be widely portable and has a simpler API, but runs at about 1/3 the speed of the Assembler solutions.
I find it impressive that Viper is that quick...
I find it impressive that Viper is that quick...
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.