exp(-2 * PI * X) approx

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

I think this is new. Or probably not, because it's so simple, I just haven't seen it before.

Image

Blue line, is exp(-2.0 * PI * x).
Green line is:
t = 1 - x
y = t*t*t*t*t

Plotted over -0.1 to 1.1

Post

Cool! :)

In most cases, x will be in the range of [0, 0.5]?

Post

You inspired me. This for X=0 to X=0.5

A = 0.44225212101E-01
B = 0.83381933629E+00
C = 0.23339518021E+01
A+(B-X)*(B-X)*(B-X)*(B-X)*(B-X)*C

Not fantastic, but cheap to calculate and closer to the curve.

Image
Swing is the difference between a drum machine and a sex machine.

Post

taylor series for Exp (most likely it'll be more accurate):

http://www.mathreference.com/ca,tfn.html
DOLPH WILL PWNZ0R J00r LAWZ!!!!

Post

tony tony chopper wrote:taylor series for Exp (most likely it'll be more accurate):

http://www.mathreference.com/ca,tfn.html
Bad link!

And I don't think the Taylor series will be anything close to as accurate until it's more expensive. The original given was 3 multiplies and an add and mine is 4 multiplies and 2 adds.
Swing is the difference between a drum machine and a sex machine.

Post

The original given was 3 multiplies and an add and mine is 4 multiplies and 2 adds.
of course the taylor series aren't practically written as in the formula, they're just multiplies & adds as well.

And you shouldn't count in just multiplies and adds. What also matters is how you can pair them - you can have more multiplies & adds eating less CPU.

(the link works here btw)
Last edited by tony tony chopper on Fri Sep 04, 2009 1:49 am, edited 1 time in total.
DOLPH WILL PWNZ0R J00r LAWZ!!!!

Post

tony tony chopper wrote:
The original given was 3 multiplies and an add and mine is 4 multiplies and 2 adds.
of course the taylor series aren't practically written as in the formula, they're just multiplies & adds as well.

And you shouldn't count in just multiplies and adds. What also matters is how you can pair them - you can have more multiplies & adds eating less CPU.
Yeah, I know. I'm confident that mine is better. :-)
Swing is the difference between a drum machine and a sex machine.

Post

in all cases I'd suggest using existing libraries like Intel's IPP for this, especially if you need to process blocks
DOLPH WILL PWNZ0R J00r LAWZ!!!!

Post

tony tony chopper wrote:in all cases I'd suggest using existing libraries like Intel's IPP for this, especially if you need to process blocks
Yeah, the performance primitives. I've been wanting to try that! Thanks!
Swing is the difference between a drum machine and a sex machine.

Post

Taylor series have the problem that accuracy is great near one point, but then gets progressively worse further from the point around which the series was generated. I'd really do some sort of min-max fit instead if you really want to approximate using polynomials.

In this particular case though, I want to ask what you're planning to use it for? For things like tuning, one should really try to minimize the errors on log-scale (otherwise you'll waste a lot of precision on trying to bring the large values closer to the ideal, making the log-scale performance of the small values worse and consequently causing larger perceptible tuning deviations on low frequencies).

For other situations it might be good idea to factor the exp into whatever formula you're going to use it for, and then get an approximation of the final result...

...from which we get to the main point: while it'd be nice to have inexpensive approximations for various curves that suit any situation you throw at them, in practice it's better to look at the actual problem and then find an approximation which minimizes the maximum error on whatever metric is actually important in the particular situation. :)

Post

I just wanted a cheap way of mapping modulation to a filter. I.E exact frequencies doesn't matter much. It just needs to sound reasonable in motion so to speak.

I figured it was pretty good since it's very close around 0 and 1. I forgot that the equation is supposed to be feed (freq/samplerate) and should reasonably not exceed 0.5.

Post

Well, I thought I'd throw this into the mix even though it's more expensive than Rock's formula and not as accurate as mistertoast's formula, i.e. it's not as good as either one. But what the hell.

Valid for f in the range of 0 to half the sample rate.

A = 0.956785967
B = 0.043214033
C = 0.88752

x = f / (sr / 2)

y = 1 - x * C
y = y * y * y
y = y * A + B

Where f is the frequency and sr is the sample rate. Since the sample rate rarely changes, we can store (sr / 2) somewhere and reuse it. The result of halfing the sample rate in the formula is that makes x is in the range of [0, 1]. This saves us from having to multiply x by 2.

The start and end points are exact with the mid-point coming very close. I could make the mid-point more accurate (it depends on the value of C), but I got tired of playing with it.

Image

Blue is exp(-2 * PI * x)
Yellow is my formula

Post

Leslie Sanford wrote: ...
x = f / (sr / 2)

y = 1 - x * C
y = y * y * y
y = y * A + B

Where f is the frequency and sr is the sample rate. Since the sample rate rarely changes, we can store (sr / 2) somewhere and reuse it. The result of halfing the sample rate in the formula is that makes x is in the range of [0, 1]. This saves us from having to multiply x by 2.
...
ok, first, why not (sr * 0.5) instead of multiply by 2.0?
second, as you said "since the sample rate rarely changes" well, usualy in a VST the sample rate can't change, not untill the plugin is destroyed, and reloaded with the new sampling rate
then why not calculate the reciprocal for (sr/2)

sr_rec = 1.0 / (sr / 2.0);

...
x = f * sr_rec; :hihi:
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!

irc.libera.chat >>> #kvr

Post

Approximations are funny things. Filters can be quite picky about them, as we've seen.

But when you want something like a way to adjust a knob, you can get away with a lot of slop.

And there's always look-up tables to compete against.

I'm all for seeing as many approximations as possible. You never know when one will be handy. I'm tempted to start a common approximations website. :-)
Swing is the difference between a drum machine and a sex machine.

Post

"usualy in a VST the sample rate can't change"

Is that true? I've been wondering whether I'll need to watch for sample rate change messages in my VSTi.
Swing is the difference between a drum machine and a sex machine.

Post Reply

Return to “DSP and Plugin Development”