473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help Simplifying This Logarithmic Function

88
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.
Dec 12 '08 #1
9 6634
JosAH
11,448 Expert 8TB
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
Dec 12 '08 #2
serdar
88
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) )?
Dec 12 '08 #3
Dormilich
8,658 Expert Mod 8TB
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.
@serdar
put a factor in front of x. you really want to go for a line (in the diagram)?
Dec 12 '08 #4
serdar
88
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.
Dec 12 '08 #5
JosAH
11,448 Expert 8TB
@serdar
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
Dec 12 '08 #6
serdar
88
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.
Dec 12 '08 #7
JosAH
11,448 Expert 8TB
@serdar
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
Dec 12 '08 #8
Dormilich
8,658 Expert Mod 8TB
@serdar
y = log(2x) is what I meant.
Dec 12 '08 #9
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.
Nov 15 '11 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: JN | last post by:
Hello. Sorry about the length of this post. I am trying to implement a hash table for my chess program, and decided to try using the VC++ . NET (Dinkumware) version of hash_map. The role of the...
5
by: news | last post by:
Well, I wrote my first PHP class today. Yeah! But to get it to work, in each function within the class I have to repeat the database connection lines, and that just seems redundant; there has to...
1
by: Andre | last post by:
Hi, I'm trying to plot a histogram on some data that I receive at runtime. I'm trying to measure distances between two points, and these distances can be from the range 1 to 5000000. I want to...
33
by: Prashanth Badabagni | last post by:
X-No-archive: yes I wonder why this code works .. can u please explain int main(void) { if (putchar((((main==main)+(main==main))*((main== main)+(main==main)) * ((main==main)+(main==main)) *...
8
by: Derek Basch | last post by:
Can anyone give any suggestions on how to make a logarithmic (base 10) x and y axis (loglog) plot in matplotlib? The scatter function doesn't seem to have any log functionality built into it. ...
8
by: Derek Basch | last post by:
Given a value (x) that is within the range (1e-1, 1e7) how do I round (x) up to the closest exact logarithmic decade? For instance: 10**3 = 1000 x = 4978 10**4 = 10000 x = 10000 Thanks...
5
by: different | last post by:
Hi, I have a program which reads a file containing integers in . The program reads the value of a variable every 2 seconds, then maps it to another interval, say , obtaining a new value. I already...
9
by: Dracenfels | last post by:
I've pulled together an online form that creates a number of tables dependant on the results of a dropdown list, i.e. 2 from the list creates two input tables, 10 creates 10 tables etc. The script...
10
by: Fred | last post by:
Hi guys, I was wondering how could i get a random number exemple between 1 and 100 but with n% of getting some value over a number x. Thanks a lot in advance. Fred
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.