DIY Digital Parametric EQ

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Correction to the equations that I posted earlier:
alpha = (tan(wc/2Q)-Gf)/(tan(wc/2Q)+Gf) for Gf<1, OR
alpha = (tan(wc/2Q)-1)/(tan(wc/2Q)+1) for Gf>=1

I guess that since nobody pointed out the mistake, nobody is playing with the math. Still it is nice to see a lot of interest here in something that isn't yet-another-DAC. Keep the discussion going.
 
If you like more control, consider using the Wavefront semiconductors AL3101. It's a small 24x18bit DSP core.
I have looked into the AL3101 in the past. It is an interesting device. It has a 1024-instruction code memory and a 1024-sample RAM, and can perform every instruction on every sample (giving about 50 MIPS at 48 kHz Fs). A bi-quad filter can be implemented on this device in only 5 instructions, meaning that you can do over 200 IIR filters on one little chip. The problem that I have with it is its accuracy/resolution. It performs 28x22 bit multiplies into a 28 bit result, which is very limited. (The TAS3103 by comparison performs 48x28 bit multiplies into a 76 bit result). Because the output samples of an IIR filter (bi-quad) form part of the input for the next sample, any error in calculation (due to limited resolution and rounding errors or anything else) will be compounded. This error is a source of noise, so compounded calculation/rounding errors can introduce unwanted noise into the signal. When higher resolution is used, the level of the noise is kept to much much lower than the least significant output bit (usually 24 bits are output).

Another possible result of low resolution is that under certain conditions, the filter's response will not trail off to zero after "infinite" time as it should, but instead it can oscilllate forever at a low amplitude, sometimes actually resulting in audible tones. The high mathematical resolution of the TAS3103 should avoid this, and any possible remaining oscillation will certainly be truncated off when the sample is reduced and dithered to 24 bits for output to the DAC. Samples are calculated to 48 bits within the TAS3103 filters, so noise, oscillations, and other uglies are well below the even the LSb of the signal. With the AL3101, you do not have the luxury of those additional "resolution bits", so any filter oscillation near the LSb could show up on the output. Of course, this is only a possibility, not sure thing.

So for implementing bi-quads I would pick the TAS3103. The AL3101 is capable of doing more generic tasks (including FIRs), so if I had an application that could not be done on the TAS3103 I might choose it instead.
 
I just wanted to give a brief update on my actual project status, since I did start this thread on the premise of building a project.

My PIC code is incomplete, but coming along. Most substantially, I have completed the section to calculate the filter coefficients in 32-bit floating point. First I had to create a custom math library by copying and pasting only exactly what I needed from Microchip's math libraries, since they are too big to be included in whole. After including the necessary 32-bit FP functions (Mult, Div, Add, Sub, sin(), cos(), and exp10()) and their dependancies, I ended up with code that just fit inside on code page (2k of code), which was a big relief. Then I wrote the algorithms to do the calculations. After fixing a few bugs, they work great, calculating the coefficients in 32 bit floating point to within +-1 LSb, even at very low and very high frequencies, which are the most difficult. A PIC16 at 20 MHz (5 MIPS) takes merely 5 ms to calculate all 5 coefficients. That is not bad considering the only math the PIC can do in hardware is add and subtract 8 bit integers! If run on a PIC18, it should reduce to less than 1 ms due to its ability to multiply (8x8) in hardware, and higher clock speed.

I still have a lot of work to do, notably the I2C interface to the DSP. I have a good start on the UI but is also is incomplete. All of that is more or less trivial, now that I have proven that the filter coefficients can be accurately and quickly calculated on a lowly little 8-bit microcontroller.
 
These are best used with the software that comes with its eval board
What are you refering to? :confused:

You don't need to calculate anything.
Why not? :confused:

I'm sure that our XOverWizard is much easier to use than the software that comes with the TAS3103EVM - I started out with it and it's damn hard to work with, but of course XOW only works with our digital crossover DCN23. Sorry.. :D

Robert
 
macboy
I've read with interest the various posts about your project. Im getting ready to start something similar. I'll be using the TAS3103 along with a dsPIC6014 controller to design a fully parametric EQ. The dsPIC may seem like overkill but it will also support a 320x240 multi grey level LCD display, full spectral readout, rotary encoders, midi interface etc etc etc. The DSP math core should make filter calculations easier and faster.
This leads me to my weakness.... I have been working with microcontrollers since the late 70s and can do quite well with them. I am not well versed in DSP filter design though and am trying to draw help where I can.

This DSP will make a really nice DIY addition to my studio rack, so Im both focused and determined.

Best of luck with your project.

MarkE
 
HawkStudio said:
macboy
I've read with interest the various posts about your project. Im getting ready to start something similar. I'll be using the TAS3103 along with a dsPIC6014 controller to design a fully parametric EQ. The dsPIC may seem like overkill but it will also support a 320x240 multi grey level LCD display, full spectral readout, rotary encoders, midi interface etc etc etc. The DSP math core should make filter calculations easier and faster.
This leads me to my weakness.... I have been working with microcontrollers since the late 70s and can do quite well with them. I am not well versed in DSP filter design though and am trying to draw help where I can.

This DSP will make a really nice DIY addition to my studio rack, so Im both focused and determined.

Best of luck with your project.

MarkE

Thanks. My project like so many others has gone stale waiting for me to find time to finish it, which I still hope to do. I think I have too many projects in the works.

In the meantime I would be happy to help you. You mentioned that you are not strong in DSP filter design. You don't have to be if you use the TAS3103 or similar devices. They do all the hard work. You just have to provide the filter coefficients. And I have generously given you all the math needed to calculate those (see post 5 and 23). You just need to plug in the three parameters that define a parametric EQ filter: Gain (in dB, + or -), Q, and Frequency (in Hz), as well as the sampling frequency your digital system uses. How you do the math is up to you, but I have successfully done it on everything from an Excel spreadsheet down to a lowly 8 bit micro.

You mention a "full spectral readout", by which I assume you mean a real-time spectrum analyser (RTA). The TAS3103 has the capability to do about 90% of the work for a 10-band RTA. If you wanted say 30 bands (for a 1/3 octave display) then you could use 3 TAS3103 devices. Each band of the RTA requires a band-pass filter, for which you need to calculate the coefficients. The calculations are very similar to the ones for an EQ filter, just ask and I'll post them. You also need to configure the response of the RMS estimators, to get the desired attack and decay times for the display. After that you just need to periodically read some data out of the TAS3103 and update your display based on it.

Good luck.
 
Many thanks. Its appreciated.
Im just getting my feet wet now, and there are so many directions that I could take. I wanted to start with the TAS3103 as the basis for this first project. This chip kept jumping out at me during various phases of my initial research. On this first pass I plan to combine it with a TLV320AIC23B codec and just use the micro to compute coefficients and do housekeeping, thanks to your formulas!

Then there are many directions that I could take. I could let the TAS, or multiple TASs handle the spectrum readout, or let the dsPIC monitor the data stream and handle the FFT itself. I could also monitor the audio output of the codec with an onboard A/D in the dsPIC.

Luckily, I am using MikroElectronica's C compiler which has a decent DSP library. It will execute FIR/IIR/FFT easily so I could even eliminate the TAS3103, or do additional DSP functions to add other effects. Im not really sure right now. I just want to get everything up and running.

About the spectrum readout....Im hoping for 10 bands for both left and right channels. After playing with so many DSP plugins available for studio programs like Sonar, I would like to design some sort of graphical interface controlled by rotary encoders that would allow the adjustment of parameters on screen against the spectrum to see the effects in real time. I eventually would like to place this device at the output of my mixer panel for mastering and other purposes.

Thanks again for your help. I may have a question here or there on the filter stuff but Im well on my way. I'll post any results I accumulate on this thread in case it is of benefit to others.

MarkE
 
This project is well underway. I decided to base it around the TAS3103. I have the main processor (dsPIC60F3014), LCD display, encoder board, codec and TAS3103 up and running with the preliminary firmware. I started a thread on the new forum linked below with preliminary schematics etc, along with a blow by blow as its being constructed.

Home Studio Projects

No problems so far. The encode board is interfaced through a pair of IO expanders which generate interrupts for the processor. Its fully debounced in firmware and works great! I have converted the 2 bit gray code into something usable by the firmware, and also wrote "slider" graphics for the display. its really cool.

Macboy...have you continued on your project or is it stalled for another?

Now that I have most of the hardware up and running I am beginning to focus on all the little things I need write. I started flowcharting a float to 5.23 conversion routine so I can send the variables down to the mixer channels via I2C. Do yu by any chance have anything prewritten in C for this? I hate reinventing the wheel. Any help would be appreciated.

Thanks

Mark
 
HawkStudio said:
...Macboy...have you continued on your project or is it stalled for another?
It is stalled, while I build my home theatre in my basement.

Now that I have most of the hardware up and running I am beginning to focus on all the little things I need write. I started flowcharting a float to 5.23 conversion routine so I can send the variables down to the mixer channels via I2C. Do yu by any chance have anything prewritten in C for this? I hate reinventing the wheel. Any help would be appreciated.

Well, not in C, but I did write something in PIC assembly!

This is actually quite easy once you take a look at the two formats. The 32 bits in IEEE float are used like this:
SEEEEEEEEFFFFFFFFFFFFFFFFFFFFFFF
where S=sign (0=positive), E (8 bits) is the exponent and F (23 bits) is the fraction, or the 'significant' digits. Really there are 24 significant digits because there is an assumed "1" as the first digit (so it is 1.F). The exponent is 'biased' by 127. That is, for an exponent of 0, E is set to 127; for 2, it is 129; for -3, it is 124, and so on (it is not simply a signed integer byte).

PIC float is only slightly different, where the Exponent is separated to its own 8-bit number, and the sign is placed at the beginning of the Fraction. This is easier to manipulate for 8-bit microcontrollers. Other than this minor re-arrangement, it is identical to IEEE. I would recommend ensuring that your data is in PIC float format, not IEEE format before converting to 5.23 format. You might have to dig around in your compiler documentation to figure out which it is. I use assembly so I don't need to worry about that.

The 5.23 format is not "floating point", but it is close. Technically it is fixed point, with 5 integer digits (actually 4+sign) and 23 fractional digits.

Read over that again if you need to.

Got that? good. That was the hard part. Now the easy part.

So, to convert float to 5.23 'fixed', what you need to do is take the 23, err, 24 fractional bits (remember to add that extra '1' bit to the 23 "F" bits stored in the float; so you start with 1.F), and appropriately increase or decrease it by the exponent. For an exponent of +1 (don't forget the bias, E=128 here), you would neet to multiply by 2. That means shifting left once. For an exponent of -2, you shift right twice. And so on. Remember, there is a limit on the exponent of +3 since you have only 4 bits to work with (plus sign). This shouldn't be a problem if you have normalised your coefficients. Also remember that shifting right (negative exponent) causes you to lose some significant digits. You may want to round up/down after shifting right. Now set the sign bit. You're done.

So here's a more algorithmic view:
1. copy the 32 bit float data to a new 32 bit var.
2. zero the upper 8 bits (i.e. sign and exponent).
3. Set bit 23 (zero-based) to "1".
(you now have 00000000 1FFFFFFF FFFFFFFF FFFFFFFF)
4. Determine the sign and magnitude of the exponent in the float.
5. Shift left (+) or right (-), magnitude number of times. (check the limits)
6. Set the sign bit (bit 27) the same as that in the float (bit 31).
(congrats, you now have 0000SIII IFFFFFFF FFFFFFFF FFFFFFFF)
See, that was easy.

I think TI had a spreadsheet that calculated filter coeficients and gave the conversion to 5.23 format. You can use it to verifiy your algorithm. Here is an excel formula to do the conversion:
RIGHT(DEC2HEX(anyNumber*2^23,8),8)
 
Thank you for the detailed explanation. I had something similar planned, and also another algorithm that would handle both the 5.23 and the 25.23 conversions with the same function. I like your idea and will probably try it.

By the way, the 3103 really is some chip. Im impressed with its ability to route signals around through the various mixers. I also like the DRC and Im sure it will be beneficial.

Im anxious to try your math on the biquads, but I wont get there for a while. Our group currently has 5 songs in production and they are keeping me pretty busy. I also have a new carvin bass on the way and Im SURE that will provide a bit of a distraction too.

This is a fun and interesting project though. I'll let you know when I post the first pictures on Home Studio Projects. Its been about three years since I worked in my field and it feels good to be back in the saddle.

Thanks again

Mark
 
Macboy
I have the i2c up and running on the TAS3101 in i2c slave mode and no problems to report. Im exploring my way around the chip and writing necessary firmware along the way.

I have a single function, written in C, for both float to 5.23 and float to 25.23. It seems to work using test values. It wasnt difficult at all. Thanks for the suggestions there.


I just wanted you to know that I started working with the biquads today using the formulas that you posted earllier in this thread. I've written a function around it called set_biquad(), which I pass a center freq, Q, gain factor and biquad address. Sample rate is set, fixed at 48000 with a macro.

When I upload a single biquad to the chip the audio cuts out. I obviously have a problem somewhere. Im fairly certain that the 5.23 conversion is working properly so Im focused on the filter parameters as the culprit. I have a few questions if I may....

You are using Tan and Cos as part of your equations. Do your formulas expect radians or degrees? As you know, C outputs radians in most compilers so Im converting it to degrees using .. degrees=radians*180/PI.

Also, if you have a scrap of paper lying around with some example values that you used in testing....lets say a bandwith filter with Fc=5000, Q=.5, G=2 or some other reference that you may have used to test your formulas I could really use it to test the output of set_biquad(). I guess you know how finicky micros can be with math of this type. I want to check the values of a1, a2, b0, b1, b2 for some known filter setup. The TAS doesnt need a0.

Thanks!
 
Im currently designing a DSP using TI’s TAS3103. Everything is going well but I am having a bit of trouble with the biquad coefficients.

Does anyone have a spreadsheet or set of formulas to calculate a1, a2, b0, b1 and b2 given Fc, Q and Gain (in db)? I have used others posted here on this thread and on other boards but when I upload any biquad to the chip the audio simply cuts out.

I have verified the following in my design…

---I2C communication with the chip operates perfectly. I can read, write and verify values.

---My mixer paths within the chip are correct and verified.

---My float to 5.23 format function is operating properly and verified for positive and negative numbers.

I’m fairly certain that I’m simply not calculating the coefficients correctly. My sample rate is fixed at 48000 for now.

If anyone can help it would be greatly appreciated. My response may be slow because, for some reason, I am still under moderation on this board even after posting several messages.

Thanks!
 
Hi. Sorry for not replying earlier. I must have missed the post. I have attached an excel spreadsheet I use. I contains all calculations for many types of filters (EQ, bandpass, high pass, shelving, etc. etc.) and even plots their frequency response. It gives you the coefficients in both float and 5.23 hex format, so you can confirm not only the coefficients but the conversions to 5.23 fixed point. The equations use radians, this is virtually always the case for trig equations in audio. Some of this (frequency response plotting stuff) was copied from TI's spreadsheet. Do you have that? Anyway, I hope it helps.
 

Attachments

  • filters.zip
    95.7 KB · Views: 323
Thank you very much! I have been fighting with this for a few days now but I'm getting closer. I'm fairly convinced that I'm missing one step somewhere and having trouble putting my finger on it.

The spreadsheet is nice. I need to dig into it deeper when I wake up but Im sure that I can verify my formulas and results using it.

I have been looking for the TI spreadsheet but it seems that they may have posted it for a while and removed it.

During the time that I have been fighting with the biquads I have been writing firmware to get the rest of the project running. It's coming along very nicely. Im using the rotary encoders to control mixer volumes and other variables in real time. Driving the encoders through an interrupt structure was certainly the way to go. I have the BT (bass/treble) section up and running as well as some preliminary reverb/delay stuff. Once I get the biquads working reliably I will move on to getting the spectrum analyser/VU working.

Its funny...the most difficult decision Im currently facing is coming up with a comfortable user interface. Im planning to save presets through a menu structure (written for a previous project). I already have the EEPROM map written out for most of it.

Mark
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.