Connecting Tech Pros Worldwide Help | Site Map

Help Simplifying This Logarithmic Function

Member
 
Join Date: Nov 2008
Posts: 80
#1: Dec 12 '08
Hi,

I'll use a function called A-weighting Filter for a spectrum analyzer I'm designing in Flash. Here is the equation of A-Weighting Filter:



I thought the function is a little heavy to compute (for hundreds of values) realtime in Actionscript.

I won't need a precise computation of the a-weighting filter.

Can you provide a simpler function example which produces more or less the same curve as below.



A javascript example to compute a-weigthing:
Expand|Select|Wrap|Line Numbers
  1. function AWeightLevel()
  2. {
  3.   var f = parseFloat(AWeightForm.Frequency.value);
  4.   var K = 3.5041384 * Math.pow(10,16);
  5.   var M1 = Math.pow(Math.pow(f,4),2);
  6.   var N1 = Math.pow(Math.pow(20.598997,2) + Math.pow(f,2),2);
  7.   var N2 = Math.pow(107.65265,2) + Math.pow(f,2);
  8.   var N3 = Math.pow(737.86223,2) + Math.pow(f,2);
  9.   var N4 = Math.pow(Math.pow(12194.217,2) + Math.pow(f,2),2);
  10.   var Level = K * M1 / (N1 * N2 * N3 * N4);
  11.   Level = 10 * Math.log(Level) / Math.log(10);
  12.   Level = Math.round(Level * 1000) / 1000;
  13.   AWeightForm.Level.value = "  " + Level;
  14. }
  15.  
  16.  
Again, any equation that more or less matches with the curve is ok with me.

Thank you.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Dec 12 '08

re: Help Simplifying This Logarithmic Function


You can reduce the calculations needed for that expression quite a bit by substituting x= f^2 and expanding the expressions; I'll do the first one:

ax^2/((x+b)*(x+c) ==

(-(ac^2)/(b-c)-ab-ac)/(x+b) + ac^2/(b-c)/(x+c) ==

A == ac^2/(b-c) ==>

(-A-ab-ac)/(x+b) + A/(x+c)

Note that the constant expressions only need to be calculated once. The second expression is similar but I'm far too lazy to expand that one as well ;-) I suspect the second expression to be dominant w.r.t. the first expression.

kind regards,

Jos
Member
 
Join Date: Nov 2008
Posts: 80
#3: Dec 12 '08

re: Help Simplifying This Logarithmic Function


Thanks, I decided something simple like:

y=log(x)

would do the work with some adjustments. (There is no way to get exact frequency amplitudes in Flash so implementing a real a-weighting on the data would be hard anyway.)

I don't do maths since high school :) so can you tell me what to add to change the slope of such a curve ( y=log(x) )?
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,640
#4: Dec 12 '08

re: Help Simplifying This Logarithmic Function


the second expression looks a bit strange considering the exponents. the numerator got exp 4 while the denominator got exp 8 giving an overall exp -4. as far as I know you need exp 0 with respect to the units to compute the logarithm.
Quote:

Originally Posted by serdar View Post

I don't do maths since high school :) so can you tell me what to add to change the slope of such a curve ( y=log(x) )?

put a factor in front of x. you really want to go for a line (in the diagram)?
Member
 
Join Date: Nov 2008
Posts: 80
#5: Dec 12 '08

re: Help Simplifying This Logarithmic Function


Quote:
put a factor in front of x. you really want to go for a line (in the diagram)?
Something like y=2x ?

No, I did not mean a fixed slope. By slope of the curve I mean the curve being more oblique etc, an "accelerating slope" if this is the correct term.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#6: Dec 12 '08

re: Help Simplifying This Logarithmic Function


Quote:

Originally Posted by serdar View Post

Thanks, I decided something simple like:

y=log(x)

would do the work with some adjustments. (There is no way to get exact frequency amplitudes in Flash so implementing a real a-weighting on the data would be hard anyway.)

I don't do maths since high school :) so can you tell me what to add to change the slope of such a curve ( y=log(x) )?

If all you need is a crude approximation, have a look at your own graph: it's a sort of upside down parabola with a logarithmic x scale and a linear y scale. The roots of the parabola are at x == 1000 and x == 7000, so the parabola looks something like this: a*(x-log(1000))*(x-log(7000)). A third point, say at x == 1 (which is log(10)) and y= -70; solves for the constant a.

kind regards,

Jos
Member
 
Join Date: Nov 2008
Posts: 80
#7: Dec 12 '08

re: Help Simplifying This Logarithmic Function


Thanks Jos,

I think I have what I need now. Sorry for the complicated equation I posted at first, but I was not aware that a simple log. function would be enough for me.

Btw, what I'm trying to match is this analyzer which produces the best results (most accurate weighting for my taste): Winamp Plug-in Details - Customize Winamp Media Player

I'm still not there but just a little closer.
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#8: Dec 12 '08

re: Help Simplifying This Logarithmic Function


Quote:

Originally Posted by serdar View Post

Thanks Jos,

I think I have what I need now. Sorry for the complicated equation I posted at first, but I was not aware that a simple log. function would be enough for me.

Btw, what I'm trying to match is this analyzer which produces the best results (most accurate weighting for my taste): Winamp Plug-in Details - Customize Winamp Media Player

I'm still not there but just a little closer.

You're welcome of course; I think that 'logarithmic parabola' does fine, especially because you don't need the range > 20,000Hz; the differences will be larger there.

kind regards,

Jos
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,640
#9: Dec 12 '08

re: Help Simplifying This Logarithmic Function


Quote:

Originally Posted by serdar View Post

Something like y=2x ?

y = log(2x) is what I meant.
Reply


Similar Algorithms / Advanced Math bytes