## Guessing at the discretization, of the Sallen-Key Filter, with Q-Multiplier.

One concept that exists in modern digital signal processing is, that a simple algorithm can often be written, to perform what old-fashioned, analog filters were able to do.

But then, one place where I find lacking progress – at least, where I can find the information posted publicly – is, about how to discretize slightly more complicated analog filters. Specifically, if one wants to design 2nd-order low-pass or high-pass filters, one approach which is often recommended is, just to chain the primitive low-pass or high-pass filters. The problem with that is, the highly damped frequency-response curve that follows, which is evident, in the attenuated voltage gain, at the cutoff frequency itself.

In analog circuitry, a solution to this problem exists in the “Sallen-Key Filter“, which naturally has a gain at the corner frequency of (-6db), which would also result, if two primitive filters were simply chained. But beyond that, the analog filter can be given (positive) feedback gain, in order to increase its Q-factor.

I set out to write some pseudo-code, for how such a filter could also be converted into algorithms…


Second-Order...

LP:
for i from 1 to n
Y[i] := ( k * Y[i-1] ) + ((1 - k) * X[i]) + Feedback[i-1]
Z[i] := ( k * Z[i-1] ) + ((1 - k) * Y[i])
Feedback[i] := (Z[i] - Z[i-1]) * k * α
(output Z[i])

BP:
for i from 1 to n
Y[i] := ( k * Y[i-1] ) + ((1 - k) * X[i]) + Feedback[i-1]
Z[i] := ( k * (Z[i-1] + Y[i] - Y[i-1]) )
Feedback[i] := Z[i] * (1 - k) * α
(output Z[i])

HP:
for i from 1 to n
Y[i] := ( k * (Y[i-1] + X[i] - X[i-1]) ) + Feedback[i-1]
Z[i] := ( k * (Z[i-1] + Y[i] - Y[i-1]) )
Feedback[i] := Z[i] * (1 - k) * α
(output Z[i])

Where:

k is the constant that defines the corner frequency via ω, And
α is the constant that peaks the Q-factor.

ω = 2 * sin(π * F0 / h)
k = 1 / (1 + ω), F0 < (h / 4)

h   Is the sample-rate.
F0  Is the corner frequency.

To achieve a Q-factor (Q):
α = (2 + (sin^2(π * F0 / h) * 2) - (1 / Q))
'Damping Factor' = (ζ) = 1 / (2 * Q)

Critical Damping:
ζ = 1 / sqrt(2)
(...)
Q = 1 / sqrt(2)



(Algorithm Revised 2/08/2021, 23h40. )

(Computation of parameters Revised 2/09/2021, 2h15. )

(Updated 2/10/2021, 18h25… )

## Butterworth Filters

There exists a basic type of low-pass filter, called a Butterworth Filter, which is a 2nd-order filter, which therefore has a falloff-rate of -12db /Octave, far above the corner frequency, and this is its general diagram:

Even though it is clear from this diagram that the two capacitors, or the two resistors, are allowed to have different values, the way the design of this filter is mainly taught today, both resistors are made equal, as are both capacitors, thus simplifying the computation of each, once the other has been determined according to what seems practical, applying the same principle as what would be applied for a 1st-order filter.

One basic weakness of this filter, especially in modern applications, is the fact that it will attenuate frequency-components considerably, which are below its corner-frequency. There have historically been two approaches taken to reduce this effect, if any attempt has been made to do so at all:

1. C1 can be given twice the value of C2, but R1 and R2 kept equal. This poses the question of whether the corner-frequency will still be correct. And my estimation is that because of the way Electrical Engineers have defined the corner-frequency, the specific frequency-response at that frequency should remain the square root of 1/2 (or, -3db). But, if C1 is larger than C2, then the frequency-response will not be the same at any other point in the curve. I.e., the curve could be flatter, with response-values closer to unity, at frequencies considerably lower than the corner-frequency.
2. The operational amplifier stage, which in the basic design is just a voltage-follower, can be transformed into a gain-stage, with a gain slightly higher than one. This is done by placing a voltage-divider from the output of an operational amplifier, to yield the feedback voltage, fed to its inverting input. What needs to be stressed here, is that significantly high gain leads to an unstable circuit.

While either approach can be taken, it is important not to apply both at the same time, as the amount of feedback given by C1 would be exaggerated, and would lead to a hot-spot somewhere in the pass-band of this filter. In general, the trend today would be to use approach (2).