exp(-2 * PI * X) approx
-
- KVRAF
- Topic Starter
- 1718 posts since 3 Sep, 2003
I think this is new. Or probably not, because it's so simple, I just haven't seen it before.
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
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
-
Leslie Sanford Leslie Sanford https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=131095
- KVRAF
- 1596 posts since 4 Dec, 2006
Cool!
In most cases, x will be in the range of [0, 0.5]?
In most cases, x will be in the range of [0, 0.5]?
-
- KVRAF
- 3404 posts since 15 Sep, 2002
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.
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.
Swing is the difference between a drum machine and a sex machine.
-
tony tony chopper tony tony chopper https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=3103
- KVRAF
- 3561 posts since 20 Jun, 2002
taylor series for Exp (most likely it'll be more accurate):
http://www.mathreference.com/ca,tfn.html
http://www.mathreference.com/ca,tfn.html
DOLPH WILL PWNZ0R J00r LAWZ!!!!
-
- KVRAF
- 3404 posts since 15 Sep, 2002
Bad link!tony tony chopper wrote:taylor series for Exp (most likely it'll be more accurate):
http://www.mathreference.com/ca,tfn.html
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.
-
tony tony chopper tony tony chopper https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=3103
- KVRAF
- 3561 posts since 20 Jun, 2002
of course the taylor series aren't practically written as in the formula, they're just multiplies & adds as well.The original given was 3 multiplies and an add and mine is 4 multiplies and 2 adds.
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!!!!
-
- KVRAF
- 3404 posts since 15 Sep, 2002
Yeah, I know. I'm confident that mine is better.tony tony chopper wrote:of course the taylor series aren't practically written as in the formula, they're just multiplies & adds as well.The original given was 3 multiplies and an add and mine is 4 multiplies and 2 adds.
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.
Swing is the difference between a drum machine and a sex machine.
-
tony tony chopper tony tony chopper https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=3103
- KVRAF
- 3561 posts since 20 Jun, 2002
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!!!!
-
- KVRAF
- 3404 posts since 15 Sep, 2002
Yeah, the performance primitives. I've been wanting to try that! Thanks!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
Swing is the difference between a drum machine and a sex machine.
- KVRAF
- 7892 posts since 12 Feb, 2006 from Helsinki, Finland
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.
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.
-
- KVRAF
- Topic Starter
- 1718 posts since 3 Sep, 2003
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.
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.
-
Leslie Sanford Leslie Sanford https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=131095
- KVRAF
- 1596 posts since 4 Dec, 2006
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.
Blue is exp(-2 * PI * x)
Yellow is my formula
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.
Blue is exp(-2 * PI * x)
Yellow is my formula
- KVRAF
- 2554 posts since 4 Sep, 2006 from 127.0.0.1
ok, first, why not (sr * 0.5) instead of multiply by 2.0?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.
...
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;
It doesn't matter how it sounds..
..as long as it has BASS and it's LOUD!
irc.libera.chat >>> #kvr
..as long as it has BASS and it's LOUD!
irc.libera.chat >>> #kvr
-
- KVRAF
- 3404 posts since 15 Sep, 2002
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.
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.
-
- KVRAF
- 3404 posts since 15 Sep, 2002
"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.
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.