Help Simplifying This Logarithmic Function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • serdar
    New Member
    • Nov 2008
    • 88

    Help Simplifying This Logarithmic Function

    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:
    Code:
    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.
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    • serdar
      New Member
      • Nov 2008
      • 88

      #3
      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) )?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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.
        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)?

        Comment

        • serdar
          New Member
          • Nov 2008
          • 88

          #5
          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 "accelerati ng slope" if this is the correct term.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            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

            Comment

            • serdar
              New Member
              • Nov 2008
              • 88

              #7
              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.

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                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

                Comment

                • Dormilich
                  Recognized Expert Expert
                  • Aug 2008
                  • 8694

                  #9
                  Originally posted by serdar
                  Something like y=2x ?
                  y = log(2x) is what I meant.

                  Comment

                  • franknagy
                    New Member
                    • Oct 2011
                    • 27

                    #10
                    Take in account that
                    log(a*f^4/((f^2+b)*(f^2+c ))=log(a)+4*log (f)-log(f^2+b)-log(f^2+c).
                    So yo can count g=f^2 in advance before calculating each members like this then sum the [log(a)+4*log(f)-log(f^2+b)-log(f^2+c)] values.

                    Comment

                    Working...