Parameter smoothing with low pass filter using time in ms. instead of frequency cut
-
- KVRer
- Topic Starter
- 25 posts since 21 Dec, 2010
Hi,
I have a question related to how to set the frequency cut of a low pass filter based on time, I would like to find a way to set the parameter smoothing in ms instead of using frequency cut (which I believe is not very intuitive at first sight).
Let's say I want to smooth a parameter in 20 ms. how you know which frequency cut to choose?
I was trying to use:
fs = 44100.0;
smoothingTime = 0.02;
fc = 1 / (2 * PI * smoothingTime);
b1 = exp(-2 * PI * (fc / fs));
a0 = 1 - b1;
But this reaches up to 63% of the "capacitor charge".
I read that at 5tau the capacitor reach the theoretical 100% but even using that it doesn't reach the desired value at smoothingTime. I had to use about 9tau to get the best approximation but I don't understand why 9tau.
Do I'm missing something?
Thanks!
I have a question related to how to set the frequency cut of a low pass filter based on time, I would like to find a way to set the parameter smoothing in ms instead of using frequency cut (which I believe is not very intuitive at first sight).
Let's say I want to smooth a parameter in 20 ms. how you know which frequency cut to choose?
I was trying to use:
fs = 44100.0;
smoothingTime = 0.02;
fc = 1 / (2 * PI * smoothingTime);
b1 = exp(-2 * PI * (fc / fs));
a0 = 1 - b1;
But this reaches up to 63% of the "capacitor charge".
I read that at 5tau the capacitor reach the theoretical 100% but even using that it doesn't reach the desired value at smoothingTime. I had to use about 9tau to get the best approximation but I don't understand why 9tau.
Do I'm missing something?
Thanks!
- KVRAF
- 7890 posts since 12 Feb, 2006 from Helsinki, Finland
After one time constant, it has charged 63% of the full range. After another time-constant, it has charged 63% of the remaining range and so on for any additional periods. It will never actually reach the target value, each period just covers 63% of the remaining range.alexirae wrote: I read that at 5tau the capacitor reach the theoretical 100% but even using that it doesn't reach the desired value at smoothingTime. I had to use about 9tau to get the best approximation but I don't understand why 9tau.
-
- Banned
- 12368 posts since 30 Apr, 2002 from i might peeramid
20ms = 50Hz
smoke weed every day
smoke weed every day
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.
-
- KVRer
- Topic Starter
- 25 posts since 21 Dec, 2010
I found a good solution for this:
b1 = exp(-TWO_PI / (smoothingTimeInMs * 0.001 * sampleRate))
ao = 1.0 - b1;
Sometimes you want to set the smoothing time in ms. (maybe for larger transition periods like a parameter change for delay time) instead of using frequency cut (I think is ok to use Hz for signal filtering, but for parameter filtering I think is a lot more intuitive to use time instead).
b1 = exp(-TWO_PI / (smoothingTimeInMs * 0.001 * sampleRate))
ao = 1.0 - b1;
Sometimes you want to set the smoothing time in ms. (maybe for larger transition periods like a parameter change for delay time) instead of using frequency cut (I think is ok to use Hz for signal filtering, but for parameter filtering I think is a lot more intuitive to use time instead).
-
- Banned
- 12368 posts since 30 Apr, 2002 from i might peeramid
the thing is, you can convert from ms to hz.
and back again.
in secret, behind what is seen by the user, so they will never know, ever. and you will never have to tell.
and back again.
in secret, behind what is seen by the user, so they will never know, ever. and you will never have to tell.
you come and go, you come and go. amitabha neither a follower nor a leader be tagore "where roads are made i lose my way" where there is certainty, consideration is absent.
-
- KVRer
- Topic Starter
- 25 posts since 21 Dec, 2010
Yeap indeed:
T = 1/f (Hz. to ms.)
f = 1/T (ms. to Hz.)
As I found in "The Scientist and Engineer's Guide to Digital Signal Processing" b1 can be found using:
By definition:
For sampled systems frequency cut in normalized radians is:
If we substitute Eq. 2 in Eq. 3 we get:
If we substitute Eq. 4 in Eq. 1:
Which is the solution I presented in my last post but converting the smoothing time from milliseconds to seconds (so T = smoothingTimeInMs * 0.001):
T = 1/f (Hz. to ms.)
f = 1/T (ms. to Hz.)
As I found in "The Scientist and Engineer's Guide to Digital Signal Processing" b1 can be found using:
Code: Select all
exp(-2 * PI * w) // w is frequency cut in normalized radians. Eq. 1
Code: Select all
fc = 1 / (2 * PI * T) //Eq. 2
Code: Select all
w = 2 * PI * fc/fs //Eq. 3
Code: Select all
w = 1/(T * fs) //Eq. 4
Code: Select all
exp(-(2 * PI) / (T * fs))
Code: Select all
exp(-TWO_PI / (smoothingTimeInMs * 0.001 * sampleRate))