View Single Post
Old 07-24-2009, 05:44 AM   #12
liteon
Human being with feelings
 
liteon's Avatar
 
Join Date: Apr 2008
Posts: 510
Default fast polynomial approximations of exp()

fast approximations of exp() with lagrange polynomials:

Code:
//stable range for x is [-1.5, 1.5]

//3 points polynomial
//y=x*(x*0.601+1.42)+1;
y=x;
y*=0.601;
y+=1.42;
y*=x;
y+=1;

//4 points polynomial
//y=x*(x*(x*0.189+0.612)+0.995)+0.975;
y=x;
y*=0.189;
y+=0.612;
y*=x;
y+=0.995;
y*=x;
y+=0.975;

//5 points polynomial
//y=x*(x*(x*(x*0.046+0.191)+0.498)+0.989)+1;
y=x;
y*=0.046;
y+=0.191;
y*=x;
y+=0.498;
y*=x;
y+=0.989;
y*=x;
y+=1;
plot comparisons with exp():

[img]http://img233.**************/img233/4125/explagrangen.gif[/img]

performance test - 100 executions per sample:
4 point -> 26% cpu
exp(x) -> 56% cpu

example:
Code:
//omega=2*$pi*fc=2*$pi*2000=12566.370614
//x=-omega/srate=-omega/44100=
x=-0.284951;
y0=exp(x);                              //0.7205110
y1=x*(x*(x*0.189+0.612)+0.995)+0.975;   //0.7367934
---
lubomir
liteon is offline   Reply With Quote