chipmuenk / pyfda

Python Filter Design Analysis Tool
http://chipmuenk.github.io/
MIT License
643 stars 94 forks source link

Biquad Filters #213

Closed PAk-CatchFire closed 4 months ago

PAk-CatchFire commented 2 years ago

I wonder if it is possible with this marvellous tool to generate Biquad IIR filters.

Some DSPs and MCUs, do have biquad libraries as a very efficient implementation form, so expanding this tool could be really useful for this purpose.

Thank you. Best Regards

chipmuenk commented 2 years ago

That's indeed on my todo list for quite a while now. Currently, I'm working on some file I/O issues and I'm planning to add an export option for coefficients in second-order sections format (i.e. biquads). What would be most useful to you - exporting

Contributing examples and / or templates would be most helpful!

PAk-CatchFire commented 2 years ago

Thank you @chipmuenk

Actually I plan to use it for ARM CMSIS in floating point (f32) format (I don't use integer for signal processing anymore), where probably the most common way is direct form II. https://www.keil.com/pack/doc/CMSIS/DSP/html/group__BiquadCascadeDF2T.html

To help you, maybe this blog post is quite interesting: http://gaidi.ca/weblog/implementing-a-biquad-cascade-iir-filter-on-a-cortex-m4

also linking to this other post (where an octave implementation is also presented): https://hackernoon.com/fast-iir-filtering-on-arm-cortex-m-with-cmsis-dsp-and-gnu-octave-qk1n3y66

Here the Github: https://github.com/matteoscordino/iir-designer-cmsis-dsp?ref=hackernoon.com

From my point of view, pyfda will have a lot of acceptance within the ARM community with this Biquad feature!!

PS: This link is also nice for an example: http://gaidi.ca/weblog/implementing-a-biquad-cascade-iir-filter-on-a-cortex-m4

PAk-CatchFire commented 2 years ago

In case it helps with python, a couple of links from ARM, where even the CMSIS library could be used from python with a wrapper:

https://developer.arm.com/documentation/102463/0100

https://developer.arm.com/documentation/102463/0100/How-to-implement-biquads-to-filter-an-Electrocardiography-signal

and a PDF (however for df1, not df2): https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/How%20to%20use%20the%20Python%20wrapper%20for%20CMSIS-DSP%20with%20biquads%20as%20an%20example.pdf?revision=9a6360f1-e2eb-4d18-83d2-3825c9486dc1

chipmuenk commented 2 years ago

Thanks for all the links! If I understand you correctly, you would like to get the biquad coefficients in the format {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...} as floats as described in https://www.keil.com/pack/doc/CMSIS/DSP/html/group__BiquadCascadeDF2T.html ? That should be possible without a big effort.

PAk-CatchFire commented 2 years ago

Yes, that could be a fantastic direct first step.

The idea later could be to use the CMSIS library wrapper for testing the embedded library coefficients with your graphic tool - so powerful and handy!!

Again, congratulations on your work on this awesome tool. I will use it with some of our internship students for filter designing (I try to avoid MATLAB as much as possible to provide them opensource engineering tools).

PAk-CatchFire commented 2 years ago

Hello Christian. I wonder if you had the time to include the biquad filters for ARMs processors.

Best regards

PAk-CatchFire commented 1 year ago

Hello @chipmmuenk, do you plan on a new release any time soon?

Best Regards

chipmuenk commented 1 year ago

Sorry for leaving you waiting for so long - I'm justing implementing some Github Actions at the moment to automate building and releasing to PyPI and then there will be a full new release during the next week. The main branch already contains the CMSIS export, somewhat hidden in the CSV options and is fully functional. In my opinion a new tab / subwidget is required in the future to allow a.o. selecting the order of second order sections and setting fixpoint options.

PAk-CatchFire commented 1 year ago

Thank you. I am converting Pyfda in my preferred tool for filter designing (so fast and powerful!!) However, I don't see how to get the CMSIS format export in the CSV.

What I see is the same coefficients as the npy format when I import it in python: image

Maybe I am missing something?

On the other hand, do you have a time frame for implementing in the GUI the Biquad Cascade IIR Filters Using a Direct Form II Transposed format? Like in Matlab: https://es.mathworks.com/help/dsp/ref/dsp.biquadfilter-system-object.html

I am seeing that many embedded applications are porting into this format because they are a quite efficient implementation.

Regards

chipmuenk commented 1 year ago

I've started working on fixpoint filters again. The export option for CMSIS SOS format is implemented for quite a while now but it is hidden somewhat: Open CSV option (the little cog) in the b,a tab and select CMSIS SOS format.

Does this export format work for you?

Regards

chipmuenk commented 4 months ago

Since v0.9.0b1, coefficients can be saved directly in CMSIS SOS format via "save coefficients".