log2
Hi,
I just can't figure out how I can evaluate log base 2.
With [expr log($f1)], the log seems natural. log2($f1) is refused.
Thanks for your help!
NP
expr log($f1,2)
you give the base as second value, the values are separated by a
comma, and commas must be "escaped" by a backslash.
In the [expr] object it seems that log() and ln() bother calculate the natural logarithm. When I try putting two arguments into log() I get an error saying it only understands one argument.
What you want to do is use the base changing rule of logarithms which states loga(x) = (logb(x)/logb(a)) where the emphasised letters represent the base of the logarithm. So if you want to be in base two use something like:
[expr log10($f1)/log10(2)]
lh
Hey, in my version of expr that doesn't work. That's why I always do it like this: expr log10($f1)/log10(2).
let see first if my version of expr really can do what i suggested. :P
expr log($f1)/log(2)
or
expr log10($f1)/log10(2)
or
expr ln($f1)/ln(2)
Thank you for that precious help!
loga(x) = logb(x)/logb(a)
This is fascinating...
NP
thx to luke hall also from me.
Is it ever too late for thank you? I think not. Thanks for the math lesson Luke.
Hi,
In the same order, how could I write "2 e (x/64)" with "expr" object?
"2exp($f1/64)" is refused...
Thanks,
Laurent.
Something like this? Check out [expr] Help File, functions tab.
Or maybe that's the one:
Bonjour Jean-François,
Je dois simplement transformer une échelle linéaire de 0 à 128 (=x) (ou 127) en une échelle exponentielle de 0,5 à 2 (= y). La valeur 64 de la première échelle doit correspondre à la valeur 1 dans la seconde (voir schéma en pièce jointe). Puisque chaque fois qu"on ajoute 64 dans l' échelle de x cela double les valeurs dans l'échelle de y, il me semble que l'équation de base est la suivante: y = 2 exposant ( x / 64 )
Mais les valeurs obtenues par 2*exp($f1/64.) ne sont pas les chiffres escomptés.
2 exp 1= 2, non? Mais avec cette formule où $1 = 64., j'obtiens 5,437. Comment écrire simplement "2 exposant x?
Puis je dois faire correspondre les deux échelles: 0 de x à 0,5 de y, 64 de x à 1 de y, et 128 de x à 2 de y...
Je ne m'y retrouve pas...
Merci de votre aide.
Laurent.

Don't know who is Jean-François, but what you need is expr pow(2, $f1/64.)
Salutations.
Of course, Laurent! pow = power. So the good solution is finally "pow(2, $f1/64.)/2" and it makes the good draw like on the graphic. Thanks a lot my friend Roald! What would I do without you in my life? :D
En effet, exp() est la fonction e à la puissance... (e = 2.71...)
If you wanted 127 to correspond to 2., you could use something like this:
Merci! Je ne connaissais pas l'objet "split".
im not sure if this is directly related to the question but, i was hoping to use this ln($f1)/ln(2) trick to scale a frequency control, but im unclear on what my input is supposed to be to get 20, to 20000 (scaled correctly) as the output? also, is there a standard for doing this? ive been poking around but it kinda seems like people just do whatever to make the scaling sort of curve in the right way, is there a "correct" way to do this?
"but im unclear on what my input is supposed to be to get 20, to 20000 (scaled correctly) as the output?"
by doing the reverse function to find out which note value corresponds to 20 and 20k Hz - and then use the "normal" function which already exists (on the form of mtof and at least one other method) on this range.
mtof uses pow().
around here note/cent without range limits is the standard way to represent "linear", where in flowstone they use 0.-1. clipped - i dont think there is a right and wrong for this kind of thing, but imho, in our context midi note numbers make the most sense.
I usually send two values in Hz to a expr log($f1)/log(2.) then I got the extremes of the range I want to control. Then after the control I have a expr pow(2., $f1).