Frequency Filters with customizable parameters

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!

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:

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.

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.

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!

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?

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.

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:

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

Attachments

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!

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 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:

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.

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.