Reply by Tim Wescott December 5, 20162016-12-05
On Sun, 04 Dec 2016 03:18:01 -0800, thejohnflynn wrote:

>> there's no guarantee that Really Bad Things wouldn't happen > > Indeed this is what I've discovered! > >> I think the OP needs to step back a bit and ask what he _really_ wants >> to accomplish > > I have an audio EQ filter that deviates from some ideal. > > This deviation is gentle but arbitrary. I have an mag/phase expression > for the deviation (so I can take 'match point' measurements anywhere I > want). > > I'm looking to correct this deviation, yielding a filter that matches > the ideal. > > If I go down the FIR route, what options do I have for matching > arbitrary responses? Both magnitude and phase? > > Ultimately this will be realtime parameter controlled C++ software. > > Thanks all, for the enlightening discussion! > John.
Assuming that you can add arbitrary amounts of delay to your signal, the brute force way to do this is to do an inverse DFT (which ends up being an inverse FFT in most reasonable systems -- an FFT is just a fast DFT). It may not be the shortest-time way to do the job, but it'll always take the same amount of time, which is desirable in a real-time system. The algorithm becomes: (1) determine your desired frequency response, (2) window it, symmetrically around f = 0, to limit the extent of the time response, (3) do an IFFT, (4) shift the IFFT so that your filter is causal, (5) use the result as the set of taps in an FIR filter. The hardest part will be automagically figuring out the proper amount of shift, and making sure you have enough taps so that the impulse response has mostly died off before the end of the FIR (if you don't do this, then the tail end of the filter response will bleed into the beginning, because of the nature of the DFT). -- Tim Wescott Wescott Design Services http://www.wescottdesign.com I'm looking for work -- see my website!
Reply by robert bristow-johnson December 5, 20162016-12-05
On Sunday, December 4, 2016 at 6:18:09 AM UTC-5, thejoh...@gmail.com wrote:
> > I have an audio EQ filter that deviates from some ideal.
what is the ideal? do you have a prototype EQ or target response defined? ...
> If I go down the FIR route, what options do I have for matching arbitrary responses? Both magnitude and phase?
if causality isn't needed, you can do whatever magnitude and phase you want. Eric Jacobsen suggested a quick and dirty idea in the previous millennium. http://dspguru.com/dsp/tricks/using-parks-mcclellan-to-design-non-linear-phase-fir-filter to make it causal, add delay. r b-j
Reply by Greg Berchin December 4, 20162016-12-04
On Sunday, December 4, 2016 at 12:50:28 PM UTC-6, thejoh...@gmail.com wrote:

> Using FDLS with 8 measurements to give a 7 zero correction filter I get _extremely_ good results. (-60dB magnitude error. And very useable results with lower settings).
Understand that FDLS is more typically, and more preferably, used with hundreds or thousands of frequency response measurements. In addition to MA (FIR) models, it can create AR (all pole) models or ARMA (IIR) models. In fact, ARMA is the most commonly used configuration.
> Are there any other FIR methods I should be looking into? > > For low-zero correction FDLS seems to have it covered. But also, for example if I wanted to do an 'total overkill' match. 64, 128, 256 zeros and higher. > > Is there a method where I could 'pin down' the response exactly at 64, evenly spaced points?
Yeah; the inverse DFT.
Reply by December 4, 20162016-12-04
Greg, it's very reassuring to leave this forum, study the literature and experiment, come back to a post like this and see that I've been working along the right lines. Thank you.

> Of course, you have to have the > transfer function you can invert it.
Apologies, I don't have the transfer function of the error curve. The ideal filter is in the S domain.
> Another possibility is the aforementioned FDLS (Frequency Domain Least > Squares) approximation technique.
Now this is really helping. Using FDLS with 8 measurements to give a 7 zero correction filter I get _extremely_ good results. (-60dB magnitude error. And very useable results with lower settings). Are there any other FIR methods I should be looking into? For low-zero correction FDLS seems to have it covered. But also, for example if I wanted to do an 'total overkill' match. 64, 128, 256 zeros and higher. Is there a method where I could 'pin down' the response exactly at 64, evenly spaced points? (That also behaves pretty well between the points). Thanks, John.
Reply by Greg Berchin December 4, 20162016-12-04
On Sun, 4 Dec 2016 03:18:01 -0800 (PST), thejohnflynn@gmail.com wrote:

>I have an audio EQ filter that deviates from some ideal. > >This deviation is gentle but arbitrary. I have an mag/phase expression for the deviation (so I can take 'match point' measurements anywhere I want). > >I'm looking to correct this deviation, yielding a filter that matches the ideal. > >If I go down the FIR route, what options do I have for matching arbitrary responses? Both magnitude and phase?
If the deviation is minimum phase, then you can compute an inverse transfer function that is stable. Of course, you have to have the transfer function (poles and zeroes) before you can invert it. Note that in general this will not be a FIR filter. If the deviation is nonminimum phase, then you can use a FIR filter to approximate the inverse, but you will introduce delay in the process. That delay may or may not be a problem for you. Another possibility is the aforementioned FDLS (Frequency Domain Least Squares) approximation technique. There are no FDLS constraints upon stability, but if the "deviation inverse" frequency response turns out to be unstable, then the approximation will be unstable, too. Oh, for FDLS the "deviation inverse" must also be causal. Send me a PM if you want FDLS info and sample Matlab or C program. Change "chatter" to "charter" and remove "invalid". Others are welcome to do the same.
Reply by December 4, 20162016-12-04
> there's no guarantee that Really Bad Things wouldn't > happen
Indeed this is what I've discovered!
> I think the OP needs to step back a bit and ask what he _really_ wants to > accomplish
I have an audio EQ filter that deviates from some ideal. This deviation is gentle but arbitrary. I have an mag/phase expression for the deviation (so I can take 'match point' measurements anywhere I want). I'm looking to correct this deviation, yielding a filter that matches the ideal. If I go down the FIR route, what options do I have for matching arbitrary responses? Both magnitude and phase? Ultimately this will be realtime parameter controlled C++ software. Thanks all, for the enlightening discussion! John.
Reply by Tim Wescott December 3, 20162016-12-03
On Sat, 03 Dec 2016 05:42:01 -0800, Greg Berchin wrote:

> On Friday, December 2, 2016 at 2:28:20 PM UTC-6, Greg Berchin wrote: > >> Hmmm ... Tim, you are correct. I didn't think about it long enough. So >> the algebraic problem is overspecified. > > I thought about this some more, and now I'm not certain whether the > problem is overspecified or redundantly-specified. > > If the coefficients are constrained to be real, then the constraint that > the poles and zeroes have conjugate symmetry is redundant; there are 5 > real unknowns and 5 measurements. > > If the coefficients are allowed to be complex, then the constraint that > the poles and zeroes have conjugate symmetry causes the imaginary parts > of the coefficients to be zero; there are 10 unknowns (5 coefficients, > each with a real part and an imaginary part) and 10 measurements.
Hmm. Going back to the original problem, the OP wants to specify a biquad (with, presumably, five available coefficients) at five complex frequency points. You've got five degrees of freedom in specifying a single-stage biquad with real coefficients (one master gain, two poles and two zeros). But five complex frequency points have ten degrees of freedom. You could expand this to two biquads and a single-order stage, and then you'd have 11 degrees of freedom (one master gain, five poles, and five zeros). That might be better. However, I'm not sure even this is a good approach, because the fit to the curve in between those specified points would be totally unconstrained, and there's no guarantee that Really Bad Things wouldn't happen (at worst, the problem as stated does nothing to guarantee a stable filter, and even if that doesn't happen the frequency response could be wildly different from what's desired). I think the OP needs to step back a bit and ask what he _really_ wants to accomplish (equalization, effects, what?) and then go forward along some other path. -- Tim Wescott Control systems, embedded software and circuit design I'm looking for work! See my website if you're interested http://www.wescottdesign.com
Reply by Greg Berchin December 3, 20162016-12-03
On Saturday, December 3, 2016 at 9:10:02 AM UTC-6, thejoh...@gmail.com wrote:

> How else does one constrain the coefficients to be real?
There are a couple of interrelated concepts at work here. Probably back in algebra class, we learned that polynomials with real coefficients have either real roots or conjugate-symmetric roots. And there's an old method by which one can determine constraints upon the number of positive and negative real roots by counting the number of transitions of the algebraic signs of the coefficients of the polynomial. In signal processing we learn that a real-valued impulse response has a frequency response that is conjugate-symmetric about DC. If it is a discrete-time impulse response, then its frequency response is also symmetric about Fs/2 because it is periodic. Can we say that a real-valued discrete-time impulse response can only be generated by a z-domain difference equation that has only real coefficients? I can't say so for certain off the top of my head, but it seems intuitively satisfying. And a z-domain difference equation can be mapped directly to a z-domain transfer function by applying a causality constraint, so if the difference equation has real coefficients, then so does the transfer function.
Reply by December 3, 20162016-12-03
Hi all, yes, you clearly know a lot more about the theory than me. This is helping me learn!

Through a trial-and-error approach I chose conjugate symmetric match points as I wanted to end up with real coefficients (I thought this was the way it needed to be done). In my implementation this seems to work, all imaginary parts are zero.

How else does one constrain the coefficients to be real?

Thanks, John.



> I thought about this some more, and now I'm not certain whether the problem is overspecified or redundantly-specified. > > If the coefficients are constrained to be real, then the constraint that the poles and zeroes have conjugate symmetry is redundant; there are 5 real unknowns and 5 measurements. > > If the coefficients are allowed to be complex, then the constraint that the poles and zeroes have conjugate symmetry causes the imaginary parts of the coefficients to be zero; there are 10 unknowns (5 coefficients, each with a real part and an imaginary part) and 10 measurements.
Reply by Greg Berchin December 3, 20162016-12-03
On Friday, December 2, 2016 at 2:28:20 PM UTC-6, Greg Berchin wrote:

> Hmmm ... Tim, you are correct. I didn't think about it long enough. So the algebraic problem is overspecified.
I thought about this some more, and now I'm not certain whether the problem is overspecified or redundantly-specified. If the coefficients are constrained to be real, then the constraint that the poles and zeroes have conjugate symmetry is redundant; there are 5 real unknowns and 5 measurements. If the coefficients are allowed to be complex, then the constraint that the poles and zeroes have conjugate symmetry causes the imaginary parts of the coefficients to be zero; there are 10 unknowns (5 coefficients, each with a real part and an imaginary part) and 10 measurements.