RedOnePole one pole filter with separate up and down coefficients


Very similar to OnePole but can have different coef going upward or downward and also a sclang method. Useful for smoothing sensor data.


see also: RedSlide


*ar(in, up, down)

*kr(in, up, down)

in - The signal to be filtered.

up - Lag amount for increasing numbers.

down - Lag amount for decreasing numbers. If nil then set to same as up.


*new(up, down)

up - Lag amount for increasing numbers.

down - Lag amount for decreasing numbers. If nil then set to same as up.

onepole(in)

in - The values to be filtered.

<>up

<>down

Set or get the amount of lag when using the slide method.



//--


b= 1; //target

a= RedOnePole(0.99, 0.98); //0.99= upwards lag, 0.98= downwards

b= a.onepole(1)

b= a.onepole(1)

b= a.onepole(1)

b= a.onepole(1)

b= a.onepole(1)



//--smoothing out an array of 0 and 1


b= {|i| i.div(500)%2}.dup(3000); //array

a= RedOnePole(0.99);

b.collect{|x| a.onepole(x)}.plot;



//--audio and control rate


{RedOnePole.ar(LFPulse.ar(30, 0.6), 0.99)}.plot(0.1);

{LFPulse.ar(30, 0.6).lagud(0.0155, 0.0155)}.plot(0.1); //compare lagud



{RedOnePole.ar(LFPulse.ar(30, 0.6), 0.99)}.plot(0.1);

{RedOnePole.kr(LFPulse.kr(30, 0.6), 0.5)}.plot(0.1); //rougly the same



//--audio examples


a= {SinOsc.ar(RedOnePole.ar(LFPulse.ar(MouseX.kr(1, 50, 1)), MouseY.kr(0.975, 1)).linexp(0, 1, 300, 3000), 0, 0.2)!2}.play

a.free