## 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).

## Successive Approximation

While Successive Approximation is generally an accurate approach to Analog-to-Digital conversion, it is not a panacea. Its main flaw is in the fact that the D/A converter within, will eventually show inconsistencies. When that happens, some of the least-significant bits output will either be an overestimated one, followed by nothing but zeroes, or an underestimated zero, followed by nothing but ones.

Although circuit specialists do what they can to make this device consistent, there are quantitative limits to how successful they can be. And, whether 24 bits can be achieved depends mainly on frequency. In analog circuits, voltages tend to zero in on an ideal voltage exponentially, even when there is no signal-processing taking place. So the real question should be, ‘Can 24 bits still be achieved, far above 48kHz?’

And, if we insist that the low-pass filter should be purely numeric, we are also implying that one A/D conversion must be taking place at the highest sample-rate, such as at 192kHz, while if the low-pass filter could be partially analog, this would not be required.

Dirk

## A Thought on SRS

Today, when we buy a laptop, we assume that its internal speakers offer inferior sound by themselves, but that through the use of a feature named ‘SRS’, they are enhanced, so that sound which simply comes from two speakers in front of us, seems to fill the space around us, kind of how surround-sound would work.

The immediate problem with Linux computers is, that they do not offer this enhancement. However, technophiles have known for a long time that this problem can be solved.

The underlying assumption here is, that the stereo being sent to the speakers should act as if each channel was sent to one ear in an isolated way, as if we were using headphones.

The sound that leaves the left speaker, reaches our right ear with a slightly longer time-delay, than the time-delay with which it reaches our left ear, and a converse truth exists for the right speaker.

It has always been possible to time-delay and attenuate the sound that came from the left speaker in total, before subtracting the result from the right speaker-output, and vice-verso. That way, the added signal that reaches the left ear from the left speaker, cancels with the sound that reached it from the right speaker…

The main problem with that effect, is that it will mainly seem to work when the listener is positioned in front of the speakers, in exactly one position.

I have just represented a hypothetical setup in the time-domain. There can exist a corresponding representation in the frequency-domain. The only problem is, that this effect cannot truly be achieved just with one graphical equalizer setting, because it affects (L+R) differently from how it affects (L-R). (L+R) would be receiving some recursive, negative reverb, while (L-R) would be receiving some recursive, positive reverb. But reverb can also be expressed by a frequency-response curve, as long as that has sufficiently fine resolution.

This effect will also work well with MP3-compressed stereo, because with Joint Stereo, an MP3 stream is spectrally complex in its reproduction of the (L-R) component.

I expect that when companies package SRS, they do something similar, except that they may tweak the actual frequency-response curves into something simpler, and they may also incorporate a compensation, for the inferior way the speakers reproduce frequencies.

Simplifying the curves would allow the effect to break down less, when the listener is not perfectly positioned.

We do not have it under Linux.

(Edit 02/24/2017 : A related effect is possible, by which 2 or more speakers are converted into an effectively-directional speaker-system. I.e., the intent could be, that sound which reaches our filter as the (L) channel, should predominantly leave the speaker-set at one angle, while sound which reaches our filter as the (R) channel, should leave the speaker-set at an opposing angle.

In fact, if we have an entire array of speakers – i.e. a speaker-bar – then we can apply the same sort of logic to them, as we would apply to a phased-array radar system.

The main difference with such a system, as opposed to one based on the Inter-Aural Delay, is that this one would absolutely require we know the distance between the speakers. And then we would use that distance, as the basis for our time-delays… )