From: robert bristow-johnson on 20 Nov 2009 15:39 On Nov 20, 2:55 pm, "JCH" <ja...(a)nospam.arcornews.de> wrote: > "kc6zut" <mmil...(a)ushio.com> schrieb im Newsbeitragnews:ZKOdnSkx57PrfZvWnZ2dnUVZ_smdnZ2d(a)giganews.com... > > > > > I need an algorithm for computing the exponential of a real number using > > only elementary operations (addition, subtraction, multiplication and/or > > division). I have a PLC (Programmable Logic Controller - used in > > industrial controls) as the processor. It has no built-in math functions > > other that the above. I need to convert a voltage from a pressure > > transducer to a displayed value. The transducer output is scaled to > > produce X volts per decade of pressure e.g. 1 volt is 1.6e-10 Torr, 1.6 > > volts is 1.6e-9 Torr. The conversion formula is; pressure = > > 10^(1.667*Voltage - 11.46). I only need 2 - 3 significant figures for the > > display. I've tried using a Taylor series but even with 5 terms it is > > only > > good over a small range. The available memory would only support a small > > look up table. Any other ideas? Any references? > > > Thanks > > Max Miller > > Ushio America, Inc. > > Polynomial Approximation: > > f(x) = 10^(1.667*Voltage - 11.46) for 0...5 Volt > > f(x) = 5.645269595656*10^-07 + -2.029821929602*10^-05 * x^1 + > 1.370173830494*10^-04 * x^2 + -3.743361811228*10^-04 * x^3 + > 5.303021991490*10^-04 * x^4 + -4.367768375904*10^-04 * x^5 + > 2.207952436761*10^-04 * x^6 + -6.951425744642*10^-05 * x^7 + > 1.329999350325*10^-05 * x^8 + -1.416971184009*10^-06 * x^9 + > 6.459316020694*10^-08 * x^10 Max, i have two questions: 1. how good do you need your exponential, must it be accurate all the way to the LSB? 2. among your "elementary operations" (addition, subtraction, multiplication and/or division), is arithmetic shifting among them? i s'pose there is a third question: 3. your "real number[s]" are fixed- point or floating-point? if the answer to 3 is "floating-point" then then 2 is not exactly applicable. if the answer to 3 is "fixed-point", then i would hope that the answer to 2 is "yes". in either the fixed or float case, i think your exponential should be base 2 and cover one octave well. you can fit it very well (like to 1/10000 dB or something like that) with a 4th-order polynomial. a truncated Maclauren (Taylor) series is a good place to start, but not the optimal polynomial coefficients. for 0 <= x <= 1 2^x ~= 1.0 + 0.69303212081966*x + 0.24137976293709*x^2 + 0.05203236900844*x^3 + 0.01355574723481*x^4 r b-j
From: robert bristow-johnson on 20 Nov 2009 16:07 On Nov 20, 3:20 pm, mblume <mbl...(a)socha.net> wrote: > > And don't forget to implement it using Horner's method: > y = ((a*x + b)*x + c)*x + d that may not always be the best method. if you're doing this in C and you don't have access to the double-wide results of the multiplications, you may as well use Horner's method. but with a DSP where you *can* accumulate the summation in a double-wide accumulator, it is not the best method. the straight-forward y = a*x^3 + b*x^2 + c*x + d is better. there is still truncation of the x^n function as you go up the power, but with Horner's method there is more truncation going on. r b-j
From: JCH on 20 Nov 2009 16:08 "mblume" <mblume(a)socha.net> schrieb im Newsbeitrag news:4b06fa06$0$4037$5402220f(a)news.sunrise.ch... > Am Fri, 20 Nov 2009 20:55:07 +0100 schrieb JCH: >>> I need an algorithm for computing the exponential of a real number >>> using only elementary operations (addition, subtraction, multiplication >>> and/or division). ... >> >> Polynomial Approximation: >> >> f(x) = 10^(1.667*Voltage - 11.46) for 0...5 Volt >> >> f(x) = 5.645269595656*10^-07 + -2.029821929602*10^-05 * x^1 + >> 1.370173830494*10^-04 * x^2 + -3.743361811228*10^-04 * x^3 + >> 5.303021991490*10^-04 * x^4 + -4.367768375904*10^-04 * x^5 + >> 2.207952436761*10^-04 * x^6 + -6.951425744642*10^-05 * x^7 + >> 1.329999350325*10^-05 * x^8 + -1.416971184009*10^-06 * x^9 + >> 6.459316020694*10^-08 * x^10 > > And don't forget to implement it using Horner's method: > y = ((a*x + b)*x + c)*x + d > y = (...(a*x + b)*x + c)*x + d Alternative: Loop similar to Private Function PolynomApprox(ByVal x As Double) As Double Dim c(11), y As Double Dim i, m As Integer m = 10 c( 0)= 5.645269595656E-07 c( 1)=-2.029821929602E-05 c( 2)= 1.370173830494E-04 c( 3)=-3.743361811228E-04 c( 4)= 5.303021991490E-04 c( 5)=-4.367768375904E-04 c( 6)= 2.207952436761E-04 c( 7)=-6.951425744642E-05 c( 8)= 1.329999350325E-05 c( 9)=-1.416971184009E-06 c( 10)= 6.459316020694E-08 y = 0 For i = 0 To m y = y + c(i) * x ^ i Next i PolynomApprox = y End Function -- Regards JCH
From: JCH on 20 Nov 2009 16:33 "robert bristow-johnson" <rbj(a)audioimagination.com> schrieb im Newsbeitrag news:e5a00717-ada5-4ef1-9b41-2b92a1d176a5(a)d21g2000yqn.googlegroups.com... > On Nov 20, 2:55 pm, "JCH" <ja...(a)nospam.arcornews.de> wrote: >> "kc6zut" <mmil...(a)ushio.com> schrieb im >> Newsbeitragnews:ZKOdnSkx57PrfZvWnZ2dnUVZ_smdnZ2d(a)giganews.com... >> >> >> >> > I need an algorithm for computing the exponential of a real number >> > using >> > only elementary operations (addition, subtraction, multiplication >> > and/or >> > division). I have a PLC (Programmable Logic Controller - used in >> > industrial controls) as the processor. It has no built-in math >> > functions >> > other that the above. I need to convert a voltage from a pressure >> > transducer to a displayed value. The transducer output is scaled to >> > produce X volts per decade of pressure e.g. 1 volt is 1.6e-10 Torr, 1.6 >> > volts is 1.6e-9 Torr. The conversion formula is; pressure = >> > 10^(1.667*Voltage - 11.46). I only need 2 - 3 significant figures for >> > the >> > display. I've tried using a Taylor series but even with 5 terms it is >> > only >> > good over a small range. The available memory would only support a >> > small >> > look up table. Any other ideas? Any references? >> >> > Thanks >> > Max Miller >> > Ushio America, Inc. >> >> Polynomial Approximation: >> >> f(x) = 10^(1.667*Voltage - 11.46) for 0...5 Volt >> >> f(x) = 5.645269595656*10^-07 + -2.029821929602*10^-05 * x^1 + >> 1.370173830494*10^-04 * x^2 + -3.743361811228*10^-04 * x^3 + >> 5.303021991490*10^-04 * x^4 + -4.367768375904*10^-04 * x^5 + >> 2.207952436761*10^-04 * x^6 + -6.951425744642*10^-05 * x^7 + >> 1.329999350325*10^-05 * x^8 + -1.416971184009*10^-06 * x^9 + >> 6.459316020694*10^-08 * x^10 > > Max, > > i have two questions: > > 1. how good do you need your exponential, must it be accurate all the > way to the LSB? > > 2. among your "elementary operations" (addition, subtraction, > multiplication and/or division), is arithmetic shifting among them? > > i s'pose there is a third question: 3. your "real number[s]" are fixed- > point or floating-point? > > if the answer to 3 is "floating-point" then then 2 is not exactly > applicable. if the answer to 3 is "fixed-point", then i would hope > that the answer to 2 is "yes". in either the fixed or float case, i > think your exponential should be base 2 and cover one octave well. > you can fit it very well (like to 1/10000 dB or something like that) > with a 4th-order polynomial. > > a truncated Maclauren (Taylor) series is a good place to start, but > not the optimal polynomial coefficients. > > for 0 <= x <= 1 > > 2^x ~= 1.0 > + 0.69303212081966*x > + 0.24137976293709*x^2 > + 0.05203236900844*x^3 > + 0.01355574723481*x^4 > > I'm still uncertain about the range of 0...5 Voltage and expect some comments from the OP. In a range of 0...3 Voltage the results would be much better. What I've done so far is just mathematics. -- Regards JCH
From: Scott Hemphill on 20 Nov 2009 16:50 "kc6zut" <mmiller(a)ushio.com> writes: > I need an algorithm for computing the exponential of a real number using > only elementary operations (addition, subtraction, multiplication and/or > division). I have a PLC (Programmable Logic Controller - used in > industrial controls) as the processor. It has no built-in math functions > other that the above. I need to convert a voltage from a pressure > transducer to a displayed value. The transducer output is scaled to > produce X volts per decade of pressure e.g. 1 volt is 1.6e-10 Torr, 1.6 > volts is 1.6e-9 Torr. The conversion formula is; pressure = > 10^(1.667*Voltage - 11.46). I only need 2 - 3 significant figures for the > display. I've tried using a Taylor series but even with 5 terms it is only > good over a small range. The available memory would only support a small > look up table. Any other ideas? Any references? Over what range do you want the approximation to be good? Are you displaying the result in exponential form? If you are displaying the result in exponential form, you will need to pick off the decade part of the answer first. Then you can use a Chebyshev polynomial approximation on the remainder. Otherwise, if you are converting to fixed point, you can use Chebyshev polynomials on the entire quantity. Chebyshev polynomials will minimize the maximum absolute error for a given order of polynomial. http://en.wikipedia.org/wiki/Approximation_theory Scott -- Scott Hemphill hemphill(a)alumni.caltech.edu "This isn't flying. This is falling, with style." -- Buzz Lightyear
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Channel simulation in matlab Next: Window and/or Filter - possibly naive question |