ΣSigmaStudio Ask AI Русский Log in

Frequency Filters with customizable parameters

Processors & DSP Nando.One May 23, 2012 00:00 15 replies Original on forum ↗
Thread Summary

Thread Summary

The user inquired about implementing a tunable IIR or FIR filter on a DSP, specifically how to dynamically compute and update filter coefficients based on user-defined parameters such as Q factor, width, frequency, and roll-off. The solution involves calculating new coefficients on the host PC or DSP using formulas or functions like 'butter' in Octave/MATLAB, and then updating the coefficients in real-time. For higher-order filters, the transfer function can be factorized into second-order sections using the 'tf2sos' function. The user is experimenting with the SHARC EZ-KIT and has found RBJ's filter cookbook formulas and the 'FilterMathCalculations.pdf' document helpful for implementing cascaded IIR filters.
AI Generated Content
Subscribe
Nando.One Question
May 23, 2012 00:00

Hi There!

Let's say I need to implement a certain frequency filter, IIR or FIR, (HPF, LPF, Passband, Bandstop etc). Implementing a fixed filter is "easy", we come up with the filter coefficients and that's it. But what if I have to implement a filter that the user must be able to tune parameters like Q factor, width, frequency, roll-off etc?

The only way I could think of is that every time the user changes the "settings", the DSP must have internally the formulas so it can recompute itself the coefficients. Are there any alternatives?

How is that usually accomplished?

Sorry for the beginners question! If there is anywhere better in engineer's zone to post it, please feel free to move my post. I posted here because I'm experimenting with the SHARC EZ-KIT . Also, if anyone could indicate me a DSP forum for these "general" questions I would really appreciate too!

Thanks a lot!

All best,

Fernando

ADIApproved Reply
May 23, 2012 00:00

Hi Fernando,

I am not an expert, but I would still like to add my thoughts. I am not sure about your system, but, I assume that you have a host PC where you have custom GUI running which allows users to change the "settings". One way could be that, the host PC recomputes the coefficients whenever required and the updated coefficients can then be passed to the DSP via any means such as RS-232, USB etc.

EE-345 discusses a similar scenario with an example where there is a custom GUI where the user can select the ldr file and based on that the GUI performs file I/O operation to read the boot image and pass its contents byte by byte over RS-232 to the DSP. The application note is available at the link below:

http://www.analog.com/en/processors-dsp/sharc/processors/application-notes/resources/index.html

Hope this helps you to some extent. Probably, others in the community may have better comments.

Thanks,

Mitesh

Nando.One Reply
May 23, 2012 00:00

Hi Mitesh! Thanks a lot for your valuable input.

Well, I guess this is exactly as I thought then... You must compute new coefficients and load them "on-the-fly", right? So, the "procedure" for this type of thing would be:

1 - Define a certain filter, which could be IIR or FIR.

2 - Based on the filter chosen, learn how to compute "by hand" the coefficients, so you can implement it on a Microcontroller, Host-PC, or even the DSP itself

3 - Create an user interface that let's the user set the parameters and automatically generates the coefficients

4 - Update coefficients according to the parameters chosen

OMG, now I see how much I have to learn

In this case, I would like to know which section of EZ would be best to ask about the mathematical part of computing filter coefficients, or, if anyone here could recommend me a forum appropriated for this type of questions? I'll definitively need help calculating the coefficients myself.

AlClark Reply
May 23, 2012 00:00

There are a number of possibilities for this problem. If you stick to IIR filters, you could calculate the coefficients on the fly. You should search on Googlefor Robert Bristow-Johnson's rb-j cookbook.

You can calculate FIR filters on the DSP using Windowing methods (as opposed to PM remez exchange).

DSP Concepts' Audio Weaver can do tunable filters using a graphics interface.

Al Clark

www.danvillesignal.com

Nando.One Reply
May 23, 2012 00:00

Hi AlClark,

I've seen audioweaver already and I would like a lot to use that. Still, I'm skeptical about these type of facilitating tools because, despite it is easy and fun, it won't let you actually LEARN how to code a DSP.

Thanks a lot for the cookbook tip, indeed it is a very helpful material with all the formulas in a few pages!

Fernando

Nando.One Reply
May 23, 2012 00:00

Hi there again!

Let's say I wrote a program (actually I am writing) that lets me calculate the filter coefficients (a0, a1, a2, b0, b1, b2).

That's good, but what if my desired filter needs more than only one section?

For example, using Matlab's fdatool, I can enter any parameters I would like to. Then, it automatically calculates the filter order (based on slope, fpass, fstop, I suppose), as well as the number of sections necessary to accomplish that filter, so the coefficients for each required section.

Now, how do I manage to calculate myself the number of sections necessary for a user given filter?

Copy Reply
May 24, 2012 00:00

Hi Nando.One!

I think you can search "cookbook formulae by robert bristow-johnson" on Goolge just like AlClark said,it is what you need.It is the program about different type of 2-order IIR filter(can tune parameters),such as HPF, LPF, Passband, Bandstop,EQ.If you want to know how the formulae comes,you should see some books about digital filter.

Best Regard!

Copy

ADIApproved Reply
May 25, 2012 00:00

Hi Fernando,

Firstly, since this question is general for all the DSPs and not very specific to SHARC, I am moving this thread to the top of the "Processors and DSP" community for better visibility.

Some thoughts regarding your questions: I understand that you are planning to write some sort of C code on the DSP itself to compute the IIR coefficients dynamically. I am not sure which algorithm you are using and what arguments it expects. But, what I did in octave is that I used function "butter" which takes the order of the filter as one of the parameters and generates the coefficients only with that order. I know that by fixing the order, you may not be able to achieve all the filter characteristics perfectly. But, on the other hand, keeping memory and MIPS issues in mind, you might not be able to allow the filter order to go beyond certain limit.

Thanks,

Mitesh

SGiav Reply
May 26, 2012 00:00

I do believe that is a more general DSP question, and I was wondering the same.

From a theoretical point of view, I am more used to seeing higher order filters with further coefficients (i.e. b3, b4, b5, a3, a4, and so on). But instead, in the .flt files in the Equalizer Talkthrough sample, there are 3 sections of coefficients, which I understand are basically three filters being implemented in cascade to achieve a similar higher-order effect.

What I think the question is, how are the additional sections (filters) calculated? Which parameters change in the second and third sections? Since it is obviously not the same filter being implemented three times in a row, all of the coefficients are different.

Edit: Also, concerning the original question of this thread - I have a very similar goal which I have been discussing in the following thread. I just thought I'd link it since it is pretty relevant and may be able to help one another:

https://ez.analog.com/thread/12539

ADIApproved Reply
May 29, 2012 00:00

Hi,

I understand your concerns. Actually, the coefficients for all the sections can be calculated by "factorizing" the N order transfer function into smaller transfer functions of order =2. There is a function named "tf2sos" which can do this job for you in Octave. I think there should be similar function available in MATLAB as well. I am attaching one of the octave scripts I used for generating coefficients for IIR_VEC function.

Hope this helps.

Thanks,

Mitesh

Nando.One Reply
May 31, 2012 00:00

Hi there, I'm sorry for the delay, work has been crazy.

Mitesh, actually I don't have any "project requirements" now, so it would be totally fine to enter the filter order as one of the arguments. You're using the butter function in Octave. The question is, how do we put the "butter" function INTO the microcontroller or DSP itself?

SGiav, you definitively GOT IT.

SGiav wrote:

What I think the question is, how are the additional sections (filters) calculated? Which parameters change in the second and third sections? Since it is obviously not the same filter being implemented three times in a row, all of the coefficients are different.

So, apparently the answer is:

Mitesh wrote:
I understand your concerns. Actually, the coefficients for all the sections can be calculated by "factorizing" the N order transfer function into smaller transfer functions of order =2.

Mitesh, could you illustrate that mathematically? I think that with a working example, we could just port the math stuff into a C program so a microcontroller, custom PC program or even the DSP could calculate it.

Thanks for the octave Script. I just have no idea how to use... I have octave on cygwin and I couldn't get it working properly I think...

By the way, here is attached a little program that I wrote using RBJ's filter cookbook formulas. That's "half-way" to the final objective I think!

ADIApproved Reply
Jun 1, 2012 00:00

Hi Nando.One,

Regarding:

Nando.One wrote:

So, apparently the answer is:

Mitesh wrote:
I understand your concerns. Actually, the coefficients for all the sections can be calculated by "factorizing" the N order transfer function into smaller transfer functions of order =2.

Mitesh, could you illustrate that mathematically? I think that with a working example, we could just port the math stuff into a C program so a microcontroller, custom PC program or even the DSP could calculate it.

http://books.google.co.in/books?id=UuUKjdCpDRIC&pg=PT227&lpg=PT227&dq=tf2SOS&source=bl&ots=QYAgbDzaxb&sig=AI2G-fddI5slFWDtXGuFQflC5m8&hl=en&sa=X&ei=GF3IT4XzEsG2gwe_8o1_&ved=0CFcQ6AEwCQ#v=onepage&q=tf2SOS&f=false

This link has mathematical explanation of what I meant to say.

Hope this helps. Please let me know if you still have further doubts.

Thanks,

Mitesh

Nando.One Reply
Jun 3, 2012 00:00

It won't open

ADIApproved Reply
Jun 4, 2012 00:00

Hi,

I am attaching the screenshot of the related page hoping that it might help you this time..

Fullscreen
fb94e6025fdd3852f2ef9eed0f7a32c5.html
Download

<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>

Thanks,

Mitesh

Nando.One Reply
Jun 5, 2012 00:00

Hi Mitesh!

Thanks a lot for the consideration posting this image. It was certainly helpful so I saved here. Currently I'm implementing cascaded IIR filters by using traditional analog filters modeled, as I could get the equations "ready to use" from this document:

https://ez.analog.com/servlet/JiveServlet/download/1819-2-6143/FilterMathCalculations.pdf

It works beautifully! I think I won't need anything sharper than a 48Db/oct linkwitz-riley, so for now, I think I'm good for the IIR filters, since these equations can be programmed into any microcontroller. Now the next challenge is to update the DSP during execution loop, via I2C or SPI.

EZAdministrator Reply
Aug 2, 2018 00:00

This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.

Thank you,
EZ Admin