PDA

View Full Version : Lovely Curves


VMail
Apr27-05, 11:26 AM
This more of a maths question rather than a physics one, but I do remember doing something similar is my physics course.

Basically I trying to write a fade in and fade out function
for a volume control but I am stuck on the maths part. Thats where I
need you.

I've tryed a linear fade, but that does not sound good

so y = volume (0-100)
and x = time (0.5)

time is fixed to 0.5sec but can alter slightly if needed

volume will be one value from 0 to 100, but I dont know what the
volume will be until the function is needed

VMail
Apr28-05, 02:25 AM
Just putting this PM here because I cant read the formula in the PM

If a linear scaling doesn't sound good, you might try something that scales as a power of time other than 1. That is, something like t^{-\alpha} for some \alpha>0 (\alpha\neq 1). It will fade faster than linear for \alpha>1, and slower than linear for 0<\alpha<1.

However, you can't just use a straight power law, because it goes to infinity at t=0, and never drops completely to zero. So, you want a power law that's shifted to the left a bit (to be positive at t=0), and also down a bit (to drop to zero at finite t).

So, you want a volume function that looks something like this,

V(t) = A(t+t_0)^{-\alpha} + B[/itex]

for some constants A, B, and t_0.

Adding the constraints that you want the volume to have some initial volume at time t=0 (V(0) = V_0), and drop to zero volume after some finite time t=T (V(T) = 0), that leads to a volume function that fades with time like this,

[tex]V(t) = \frac{1-(\frac{1+T/t_0}{1+t/t_0})^\alpha}{1-(1+T/t_0)^\alpha} V_0

or,

V(t) = \frac{1-k/(1+t/t_0)^\alpha}{1-k} V_0

where k = (1+T/t_0)^\alpha -- assuming I haven't screwed up the algebra; you'll have to check it.

You'll have to play around with the parameters \alpha and t_0 to find something that sounds good. I already mentioned the effect that \alpha has on the fade; larger t_0 values will also make for a slower fade (getting out on the tail end of the power-law decay curve).

VMail
Apr28-05, 08:07 AM
ok, I'm using

to=0 to 475 (stepping by 25)
and alpha as 1.01
Vo is set at 50

The values that I am getting are 16-45(rounded up)
is this correct?