Hello all,
I recently wanted to use Puredata to do some simple simulation.
In particular this required the first order filters lop~ and hip~,
Both emulate what would be a simple RC filter in the analog world.
Results were not what I expected, and after some further
investigation it turned out the both filters were not doing
what one could reasonably expect.
First order LP and HP would be something like
x = *inp++;
z += c * (x - z);
out++ = z; // for LP
out++ = x - z; // for HP
where z is the filter state and c is the filter coefficient
dependent on the cutoff (-3 dB) frequency.
The pd versions don't even add up to unity gain when configured
for the same cutoff frequency. Apparently they use different ways
to calculate c, and in both cases that calculation is wrong.
How something so simple and basic is still completely broken
after more than 30 years escapes me. [1]
Now, to be 'constructive', the correct way to compute c
would be
f = cutoff_frequency / sample_rate;
a = 2 * (1 - cos (2 * pi * f);
c = (sqrt (a * (a + 4)) - a) / 2;
A good approximation (less than 1% relative error)
for 0 <= f <= 0.5 could be
c = 2 * pi * f * (1 + f * (3.45f + 4.27f * f));
Now one may want to have f > 0.5 to emulate the analog
version in some cases. In that case this will work fine:
if (f <= 0.474f)
{
c = 6.2831853f * f / (1 + f * (3.45f + 4.27f * f));
}
else
{
c = 0.79799 + f / 16;
if (c >= 1.0f) c = 1.0f;
}
With this c will continue to rise for f > 0.5, and reach
unity at approx f = 3.23.
[1] I know the IEM externals have better versions.
But that's IMHO no excuse to leave this mess as it is,
both wrong AND nowhere documented.
Ciao,
--
FA
I've seen quite a few adverts for MIDI2 keyboard controllers now, so has anyone
tried interfacing with this yet?
If so, what sort of problems have you had to resolve.
--
Will J Godfrey {apparently now an 'elderly'}