exponential scaling problem
Jul 27, 2009 at 11:27pm
exponential scaling problemi have a value form 0 to 2047 and i want it to be scaled from 0.375 to 0.375 with 5 in the middle. so 0 to 1024 is scaled 0.375 to 5 and 1024 to 2047 is scaled 5 to 0.375. the problem is i want it to be exponentially scaled but i can’t scale it like i want with scales optional exponential value argument. is there a way of smoothly doing this? – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.


Jul 28, 2009 at 12:10am
Something like this! I found 2.321928 by working backwards (as you can see on the right side of the patch) rather than being clever and doing all the maths. Then it’s just a case of scaling the values to fit your input and output. You could probably do it all in one [expr] with clever use of ($f1>1024) but using split is much easier. lh – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.


Jul 28, 2009 at 12:13am
Or if you want it all in one go try: [expr pow(((($f1>1024)*2048)(($f1>1024)*21)*$f1)/1024,2.321928)*5.] lh 

Jul 28, 2009 at 3:31am
i have abstractions for that, but they are not 100% perfect, it is a bit complicated: you first have to split the input range, then do the exponential scaling for both sides. and for a maximum of security and flexibilty you should only
[110.makepow.mxb] enjoy, 110 

Jul 28, 2009 at 3:37am
….. 

Jul 28, 2009 at 9:29am
thanks lh, it works precisely like i want. but i don’t understand what’s happening in the expr objects, i’ve never done much with them. thanks for your abstractions roman but they look way too complicated for me, i have very little time so i can’t take time to figure them out. 

Jul 28, 2009 at 10:30am
i also would like to know what i should do tho get one more close to the middle. for instance instead of 1 @ 512, 1 @ 768. 

Jul 28, 2009 at 6:49pm
I hate to bring up Litter Power again, but this is ridiculously easy to do with lp.scampf in any of its symmetry modes. Create a [lp.scampf map 0 2047 5. 0.375 pow 1.] object, send it the message ‘sym 2′, and your values will map like the enclosed picture. Send a number to the last inlet (or edit the last argument) for a more or less steep curve. Use exp instead of pow for true exponential shapes (although most people actually want the power curves). lp.scampf an lp.scampi are two of the most handy little utilities in the (free) Starter Pack, if I do say so myself. Max 5 doesn’t like the .help files in the Starter Pack a lot, but the objects themselves work on 5. The Pro Bundle is fully Max 5compatible. Hope this helps, – 

Jul 28, 2009 at 8:12pm
Right well if you have a simple [expr pow($f1,$f2)] and the base (first inlet) is limited to being between 0 and 1 then as long as the exponent (second inlet) is >0 the outlet will also always between 0 and 1 also. – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.
In your case you we set the base to 0.5, this is because 512 is half of the range 0 to 1024. We also want the result to be 0.2 becuase 1 is a fifth of the range 0 to 5. I worked it out by setting the base to 0.5 and gradually increasing the exponent until the answer was 0.2. – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.
If I was being clever and awake I would have worked it out using logarithms. If a^b = c then b = log a of c. (Either trust me or look it up in a textbook!) However we only have log10 available to use in [expr] so we use another rule of logarithms that states: If b = log a of c then b = (log10 of c)/(log10 of a) Put that in an [expr] where a=0.5 and c=0.2 and you get b=2.321928 – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.
Now we’ve calculated the exponent we just need to scale the input and output to get it into your desired range. This is where the /1024 and *5 come in. Put them all together and you get [expr pow($f1/1024,2.321928)*5.]. Simply change the scaling for when the input is >1024 and feed this half of the claculation using [split] and you arrive back at my orignal patch. – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.
And if you’re being really clever then use conditional operators in [expr] so that you don’t have to use [split] and two seperate scaling equations. I won’t explain this bit as I think what I have already is confusing enough. – Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.
lh 

Jul 28, 2009 at 11:50pm
thank very much you for explaining. but what does the [expr pow($f1,$f2]actually mean? i figured out pow is something like ^ (don’t know how to call that in english) but it’s not the same. what does it actualy do? 

Jul 29, 2009 at 12:09am
It calculates powers: pow(a,b) The first number in the brackets is the base and the second is the exponent. In shorthand typing its usually shown as a^b which is “a to the power (of) b”. For example: 4^2 is four squared which means 4×4 which is 16. And an inverse function: 64^(1/2) is the square root of 64 which is 8 because 8×8=64. It should be shown as I typed above: pow(a,b) but the comma is a reserved character in max so it has to be escaped with the backslash hence we get [expr pow(a,b)]. I hope that clears things up a bit better. lh
– Pasted Max Patch, click to expand. –
Copy all of the following text.Then, in Max, select New From Clipboard.


Jul 29, 2009 at 12:22am
that clears all up. 

Jul 29, 2009 at 12:25am
Not a problem, I always find it a bit easier to learn from exploring examples rather than just reading the theory, especially with maths related stuff. lh 

Jul 29, 2009 at 12:50am
the main problem is that if you do not have the time to this stuff really only works when you are willing to invest i dont even have visited a highschool and i found out the 

Jul 29, 2009 at 1:44am
i have a gig this friday and because i’m busy reprogramming the core element of my patch (because there are some bugs in the old version caused by new funtions) and i came across more ‘trial and error’ then expected along the way i have still pretty much to do and therefore not much time. telling me i should stop using a programming language because you assumed i’m lazy after reading a forum post is a bit lame. 

Jul 29, 2009 at 7:24pm
i just thought that typing “pow” into google could have been
you know what is good about expr? it has a lenght limit, so i just adopted tihfu´s idea to have comparison operators
the object now consists only of one single expression this expression now reads like that: [expr (((exp((($f1$f2)/((($f2+$f3)/2.)$f2))*log($f4))1)/($f41)* ((($f2+$f3)/2.)$f2))+$f2)*($f1< (($f2+$f3)/2.))+(((((exp(((( ($f1(($f2+$f3)/2.))/($f3(($f2+$f3)/2.)))*1.)+1.)*log($f4)) 1)/($f41)*1.)+1.)*($f3(($f2+$f3)/2.)))+(($f2+$f3)/2.)) *($f1>(($f2+$f3)/2.))+($f1+0.)*($f1==(($f2+$f3)/2.))] and guess what, the shit is too long, so you cannot write it like that in [expr], LOL! now i have to split it somewhere, maybe it is enough to take 110 . 
You must be logged in to reply to this topic.