View Single Post
Old 07-22-2009, 03:06 PM   #7
Mich
Human being with feelings
 
Join Date: May 2009
Posts: 1,265
Default

Quote:
Originally Posted by cern.th.skei View Post
and some filtering

Code:
desc:lowpass / weighted average
slider1:0.5<0,1,0.001>weight
@init
  n0 = 0;
  n1 = 0;
@slider
  weight = slider1*slider1;         // ???
@sample
  spl0 =  (n0+=((spl0-n0)*weight)); // lowpass
  spl1 -= (n1+=((spl1-n1)*weight)); // highpass
perhaps not scientifically correct, but useful when cpu and simplicity is important.
The low/highpass is a perfectly correct RC filter as far as I can tell.

The formula to calculate the "weight" from frequency is:
weight = 1-exp(-2*$pi*fc/srate);
and for time (that is RC time constant) it is:
weight = 1-exp(-1/t); where t is the time it takes the filter to decay to 36.8% of its initial input or reach 63.2% of its final output.

P.S. liteon you accidentally have a seed of 0 in one of your examples.

Last edited by Mich; 07-22-2009 at 03:15 PM. Reason: I'm an idiot! :(
Mich is offline   Reply With Quote