Help Simplifying This Logarithmic Function | Member | | Join Date: Nov 2008
Posts: 80
| |
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: -
function AWeightLevel()
-
{
-
var f = parseFloat(AWeightForm.Frequency.value);
-
var K = 3.5041384 * Math.pow(10,16);
-
var M1 = Math.pow(Math.pow(f,4),2);
-
var N1 = Math.pow(Math.pow(20.598997,2) + Math.pow(f,2),2);
-
var N2 = Math.pow(107.65265,2) + Math.pow(f,2);
-
var N3 = Math.pow(737.86223,2) + Math.pow(f,2);
-
var N4 = Math.pow(Math.pow(12194.217,2) + Math.pow(f,2),2);
-
var Level = K * M1 / (N1 * N2 * N3 * N4);
-
Level = 10 * Math.log(Level) / Math.log(10);
-
Level = Math.round(Level * 1000) / 1000;
-
AWeightForm.Level.value = " " + Level;
-
}
-
-
Again, any equation that more or less matches with the curve is ok with me.
Thank you.
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | 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
| | | 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) )?
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,640
| | | 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 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
| | | 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.
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | re: Help Simplifying This Logarithmic Function Quote:
Originally Posted by serdar 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
| | | 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.
|  | Expert | | Join Date: Mar 2007
Posts: 10,611
| | | re: Help Simplifying This Logarithmic Function Quote:
Originally Posted by serdar 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
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,640
| | | re: Help Simplifying This Logarithmic Function Quote:
Originally Posted by serdar Something like y=2x ? y = log(2x) is what I meant.
|  | Similar Algorithms / Advanced Math bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|