Forums > MaxMSP

C-like expressions and formulas

December 9, 2007 | 6:17 am

Dear Max list,
I have this value from a potentiometer that jitters about three digits,
even if I’m not moving it. I used this expression from someone. It
worked
to some extent:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 893 208 27 196617 f;
#B color 5;
#P newex 855 185 122 196617 expr 0.1*$f1 + 0.9*$f2;
#B color 5;
#P connect 0 0 1 0;
#P connect 1 0 0 1;
#P window clipboard copycount 2;

so then in order to make it work, I added more and more…

now I’m wondering if it is really ok. Because my computer is
slow and if it takes too much of the resources, it can jeopardize
the performance. I was wondering:
a) how to add a third variable to make this take into consideration
three numbers
b) for a novice who doesn’t quite know math/algebra is there any good
book, site that explains formulas
like this and what they do?
I really appreciate it!
Thanks.


December 9, 2007 | 11:19 am

On 09 Dec 2007, at 07:17, Dean wrote:

> Dear Max list,
> I have this value from a potentiometer that jitters about three
> digits,
> even if I’m not moving it. I used this expression from someone. It
> worked
> to some extent:
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 893 208 27 196617 f;
> #B color 5;
> #P newex 855 185 122 196617 expr 0.1*$f1 + 0.9*$f2;
> #B color 5;
> #P connect 0 0 1 0;
> #P connect 1 0 0 1;
> #P window clipboard copycount 2;

what you have here is a simple recursive lowpass filter of the form:
y[n] = a*x[n] + b*y[n-1], where a = 1.-b

instead of concatenating more and more of these, i would propose to
simply change the weight (a and b) of x[n] (input) and y[n-1] (last
output, fed back to input).
or you might like to have a look at [slide], which is a more
versatile filter for exactly these purposes.
hth,
volker.

ps: it might be a good idea to stabilize the sensor data *before*
digitizing it.

#P user multiSlider 180 448 183 109 0. 127. 1 3433 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 58 157 67 196617 slide 10. 10.;
#P flonum 271 125 35 9 0. 1. 3 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user multiSlider 180 336 183 109 0. 127. 1 3433 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 180 224 183 109 0. 127. 1 3433 15 0 0 2 0 0 0;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P toggle 139 32 15 0;
#P newex 139 60 52 196617 metro 50;
#P newex 139 96 71 196617 drunk 127 10;
#P newex 139 178 27 196617 f;
#B color 5;
#P newex 139 156 143 196617 expr (1-$f3)*$f1 + $f3*$f2;
#B color 5;
#P comment 310 127 100 196617 0. < -> 1.;
#P connect 8 0 1 2;
#P connect 3 0 9 0;
#P connect 3 0 1 0;
#P connect 3 0 6 0;
#P connect 2 0 7 0;
#P connect 2 0 1 1;
#P connect 9 0 10 0;
#P connect 1 0 2 0;
#P connect 4 0 3 0;
#P connect 5 0 4 0;
#P window clipboard copycount 11;


December 11, 2007 | 4:47 am

Quote: gransar wrote on Sat, 08 December 2007 22:17
—————————————————-

>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 893 208 27 196617 f;
> #B color 5;
> #P newex 855 185 122 196617 expr 0.1*$f1 + 0.9*$f2;
> #B color 5;
> #P connect 0 0 1 0;
> #P connect 1 0 0 1;
> #P window clipboard copycount 2;
>
>
>

There’s a patch in the CNMAT Max/MSP/Jitter Depot called "onepole" which implements a similar kind of filter, but with a variable weight. Another approach is to average the last few (say 5) inputs. All of these add a little latency to the response of your system, though. Alternately, you could not pass the signal unless the difference from the last passed input is > than some threshold.

cheers,

mz


December 12, 2007 | 5:46 pm

Quote: mzed wrote on Tue, 11 December 2007 05:47
—————————————————-
Another approach is to average the last few (say 5) inputs. All of these add a little latency to the response of your system, though. Alternately, you could not pass the signal unless the difference from the last passed input is > than some threshold.
—————————————————-

This you can do very easily with lp.stacey, instantiating with, say [lp.stacey 5].

It’s in the Litter Power Starter Pack which is (Good News) free but (Bad News) still PPC-only. The very good news is that the Pro Bundle version is UB.

Windows people don’t care about the UB thing, so they can just grab the Starter Pack "Tungsten" and run with it. Life is so unfair sometimes.

Best,
Peter


Viewing 4 posts - 1 through 4 (of 4 total)