DSPRelated.com
Forums

Fit biquad to 5 frequency response points?

Started by Unknown December 2, 2016
Is it possible to fit a biquad filter to a curve given only 5 (complex) frequency response values?

I'm a relative newcomer. Any help would be greatly appreciated.

I have a gentle curve which I am looking to find a closed form solution for the coefficients in terms of the 5 known frequency response values.

More detailed problem description is here: https://dl.dropboxusercontent.com/u/9600561/question.pdf

The best attempt I've had is to use Mathematica's Solve which has given me something like...
https://dl.dropboxusercontent.com/u/9600561/biquadfit.m
...however it gives a division by zero and NaN's.

Many thanks in advance for your time,
John.
On Friday, December 2, 2016 at 7:31:18 AM UTC-6, thejoh...@gmail.com wrote:
> Is it possible to fit a biquad filter to a curve given only 5 (complex) frequency response values? > > I'm a relative newcomer. Any help would be greatly appreciated.
In general, at comp.dsp we don't solve homework problems for you, but since you asked so nicely I'll give you some hints. 1. You have 5 unknowns; a1, a2, b0, b1, b2. You have 5 measurements. You have enough information to create 5 equations in 5 unknowns. 2. Remember that z = exp(jwT) when dealing with frequency response on the unit circle. 3. Use Euler's Identity. 4. You have an expression for the transfer function H(z) in terms of z. You know the values of H(z) at several frequencies. You can compute the values of z are at those same frequencies. Turn the crank.
Thanks for the swift reply Greg!

Actually it's not homework, I typed up that pdf to make the question as clear as possible. I guess this is what I do for fun.

I am on the right track, I think...

I have these five equations:
https://dl.dropboxusercontent.com/u/9600561/q2.pdf

Using Mathematica I can rearrange the equation for appropriate back-substitution which has given me:
https://dl.dropboxusercontent.com/u/9600561/biquadfit.m

Which doesn't work :(

When you say 'turn the crank', is there something easier that I'm missing??

Are there pen and paper simplifications I should be making first?

Many thanks again, John.




On Friday, December 2, 2016 at 2:01:32 PM UTC, Greg Berchin wrote:
> On Friday, December 2, 2016 at 7:31:18 AM UTC-6, thejoh...@gmail.com wrote: > > Is it possible to fit a biquad filter to a curve given only 5 (complex) frequency response values? > > > > I'm a relative newcomer. Any help would be greatly appreciated. > > In general, at comp.dsp we don't solve homework problems for you, but since you asked so nicely I'll give you some hints. > > 1. You have 5 unknowns; a1, a2, b0, b1, b2. You have 5 measurements. You have enough information to create 5 equations in 5 unknowns. > 2. Remember that z = exp(jwT) when dealing with frequency response on the unit circle. > 3. Use Euler's Identity. > 4. You have an expression for the transfer function H(z) in terms of z. You know the values of H(z) at several frequencies. You can compute the values of z are at those same frequencies. > > Turn the crank.
On Friday, December 2, 2016 at 8:23:45 AM UTC-6, thejoh...@gmail.com wrote:

> When you say 'turn the crank', is there something easier that I'm missing?? > > Are there pen and paper simplifications I should be making first?
Use Euler's Identity to resolve the "exp(3pi/4)" terms. After that, it's algebra.
On Friday, December 2, 2016 at 3:09:52 PM UTC, Greg Berchin wrote:
> On Friday, December 2, 2016 at 8:23:45 AM UTC-6, thejoh...@gmail.com wrote: > > > When you say 'turn the crank', is there something easier that I'm missing?? > > > > Are there pen and paper simplifications I should be making first? > > Use Euler's Identity to resolve the "exp(3pi/4)" terms. After that, it's algebra.
Thanks Greg, Yes for these I have the complex value -1/sqrt(2) + j1/sqrt(2) or -0.70711 + 0.70711i. So yes I know these e^ terms are 'knowns'. My question then, is more about the algebra... Do I just start grinding with the DC equation to get b0 = -b2 - b1 + H1 * a2 + H1 * a1 + H1 Then substitute "-b2 - b1 + H1 * a2 + H1 * a1 + H1" for every b0 in the next equation. Rearrange that new equation so b1 = ...some complicated expression... Rearrange that new equation so b2 = ...some even more complicated expression... Rearrange... ... And on till the end? Is there an easier way?! Sorry if this is really obvious, I've been away from maths for 17 years so rusty isn't the word. Thanks!
On Friday, December 2, 2016 at 9:51:53 AM UTC-6, thejoh...@gmail.com wrote:

> Is there an easier way?!
Try putting the equations into matrix form.
Embarrassing, my code actually did work :/

Typo in the call...
biquadfit(hDc, hPi2, h3Pi4, h3Pi4Neg, hPi2)
...should have been...
biquadfit(hDc, hPi2, h3Pi4, h3Pi4Neg, hPi2Neg) <--

Unfortunately I end up with a pole outside the unit circle and only the magnitude but not the phase is matched.

Is the solution unique?

Since the unknowns are not squared/cubed/etc., I would have presumed that there is only one solution.

I'm wondering why the phase is not matched...

Thanks for all your input, it's been very helpful,
John.


On Fri, 02 Dec 2016 06:01:24 -0800, Greg Berchin wrote:

> On Friday, December 2, 2016 at 7:31:18 AM UTC-6, thejoh...@gmail.com > wrote: >> Is it possible to fit a biquad filter to a curve given only 5 (complex) >> frequency response values? >> >> I'm a relative newcomer. Any help would be greatly appreciated. > > In general, at comp.dsp we don't solve homework problems for you, but > since you asked so nicely I'll give you some hints. > > 1. You have 5 unknowns; a1, a2, b0, b1, b2. You have 5 measurements. You > have enough information to create 5 equations in 5 unknowns. > 2. Remember that z = exp(jwT) when dealing with frequency response on > the unit circle. > 3. Use Euler's Identity. > 4. You have an expression for the transfer function H(z) in terms of z. > You know the values of H(z) at several frequencies. You can compute the > values of z are at those same frequencies. > > Turn the crank.
Given five complex frequency-response values and five real coefficient values, you have _ten_ equations in five unknowns. That may be a tougher nut to crack. I don't know where the OP is trying to go with this, but sometimes even when there is a closed-form solution, it's better to just numerically optimize. As a for-instance: when was the last time that you factored a 5-th order polynomial using the formula? Do you even know where to FIND the formula? I think the CRC handbook only goes up to 3rd order. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com I'm looking for work -- see my website!
On 12/2/2016 13:10, Tim Wescott wrote:
> On Fri, 02 Dec 2016 06:01:24 -0800, Greg Berchin wrote: > >> On Friday, December 2, 2016 at 7:31:18 AM UTC-6, thejoh...@gmail.com >> wrote: >>> Is it possible to fit a biquad filter to a curve given only 5 (complex) >>> frequency response values? >>> >>> I'm a relative newcomer. Any help would be greatly appreciated. >> >> In general, at comp.dsp we don't solve homework problems for you, but >> since you asked so nicely I'll give you some hints. >> >> 1. You have 5 unknowns; a1, a2, b0, b1, b2. You have 5 measurements. You >> have enough information to create 5 equations in 5 unknowns. >> 2. Remember that z = exp(jwT) when dealing with frequency response on >> the unit circle. >> 3. Use Euler's Identity. >> 4. You have an expression for the transfer function H(z) in terms of z. >> You know the values of H(z) at several frequencies. You can compute the >> values of z are at those same frequencies. >> >> Turn the crank. > > Given five complex frequency-response values and five real coefficient > values, you have _ten_ equations in five unknowns. That may be a tougher > nut to crack. > > I don't know where the OP is trying to go with this, but sometimes even > when there is a closed-form solution, it's better to just numerically > optimize. As a for-instance: when was the last time that you factored a > 5-th order polynomial using the formula? Do you even know where to FIND > the formula? I think the CRC handbook only goes up to 3rd order. >
In general, you can't factor a 5th order polynomial. I'm not sure about CRC (mine is from '67), but Maxima will crank out the solutions for general 3rd and 4th order polynomials. They're huge, messy expressions. Best wishes, --Phil -- Best wishes, --Phil pomartel At Comcast(ignore_this) dot net
On Fri, 02 Dec 2016 13:39:39 -0500, Phil Martel wrote:

> On 12/2/2016 13:10, Tim Wescott wrote: >> On Fri, 02 Dec 2016 06:01:24 -0800, Greg Berchin wrote: >> >>> On Friday, December 2, 2016 at 7:31:18 AM UTC-6, thejoh...@gmail.com >>> wrote: >>>> Is it possible to fit a biquad filter to a curve given only 5 >>>> (complex) >>>> frequency response values? >>>> >>>> I'm a relative newcomer. Any help would be greatly appreciated. >>> >>> In general, at comp.dsp we don't solve homework problems for you, but >>> since you asked so nicely I'll give you some hints. >>> >>> 1. You have 5 unknowns; a1, a2, b0, b1, b2. You have 5 measurements. >>> You have enough information to create 5 equations in 5 unknowns. >>> 2. Remember that z = exp(jwT) when dealing with frequency response on >>> the unit circle. >>> 3. Use Euler's Identity. >>> 4. You have an expression for the transfer function H(z) in terms of >>> z. You know the values of H(z) at several frequencies. You can compute >>> the values of z are at those same frequencies. >>> >>> Turn the crank. >> >> Given five complex frequency-response values and five real coefficient >> values, you have _ten_ equations in five unknowns. That may be a >> tougher nut to crack. >> >> I don't know where the OP is trying to go with this, but sometimes even >> when there is a closed-form solution, it's better to just numerically >> optimize. As a for-instance: when was the last time that you factored >> a 5-th order polynomial using the formula? Do you even know where to >> FIND the formula? I think the CRC handbook only goes up to 3rd order. >> > In general, you can't factor a 5th order polynomial. I'm not sure about > CRC (mine is from '67), but Maxima will crank out the solutions for > general 3rd and 4th order polynomials. They're huge, messy expressions.
I thought 5th was the highest you could crack, not the lowest that you couldn't. My bad. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com I'm looking for work -- see my website!