Digital Filtering Aim of the text is to arrive at a solid construction of a 4th order low pass filter with resonance, implemented with standard operations and allowing 16 bit effective accuracy. The *method* used is to simulate the analog implementation of the desired filter as closely as possible, because the aim is to at least be able to do the same as existing analog (music synthesizer) filters. This means that at first, approximations such as subsampled digital filtering techniques (with low pass but different transfer characteristics) are not taken into consideration, even though their implementation could draw less an computing resources, and fir approximations of the samples equivalent of the analogs iir characteristics are also not selected, in spite of their superior signal processing properties, such as inherent stability and lower sensitivity to quantization induced noise due to a lack of feedbacks. Sampling rates Use samples 'in between' audio samples, 44.1 KS/s, each filter stage introduces a new intermediate sample stage. In other words the sampling rate is effectively increased with each added filter delay stage. Notation i[n]: input samples o[n]: output samples a[j]: filter coeficients, forward path b[j]: idem, backward path s[j]: storage elements Integrator Simple integrator: o[n+1] = s[0] s[0] = s[0] + a[0] * i[n] In other words the next output sample is computed from the current input ad the stored state by 'differentially' updating the state variable, and taking the output solemny from the integated value. Accuracy Assuming a CD quality input signal, the effective resolution of the filter may not subsede 16 bit enywhere in the filter signal path. Considering that 20 Hz wil be the lowest frequency that is to pass through the filter, and that an integrator has a 6dB/Oct roll off for all frequencies, a 20 Hz signal input a full resolution (0dB) will cause the largest signal at the state (and output) variables, and may thus serve as a worst case example. The numerical value of the integrated signal of a 20Hz square wave (one may argue that another signal composed of all harmonics cold also act as a test case, such as a saw-tooth, or white noise), reaches its peak at the second zero crossing of the input signal, and equals: 44100/20 * (integral(a[o]*i[n]*square(n),n,0,pi) / pi) = 2205*a[0]* 0.5 * Max_toptop_amplitude(i[n]) = a[0] * 72,253,440 to fit this in a short number, i.e. 16 bit signed format, the 32 bit product of a[0] with i[n] needs to be scaled (down) by a factor of 1/(1102 * a[0]) to reach full 0dB amplitude for all signals with higher frequency than 20 Hz. A simulated 1 stage RC filter A standard first order RC filter with one resistor and one capacitor, and ideal coupling (Z=0 in, z= inf out) looks like: ------ Vin >--- R -------------> Vout ------ | V Ic | ----- C ----- | | ----- Standard network equations (Kirchhof and Ic=C(dUc/dt)) gouvern it behaviour: Vc = Vout = Int(Ic,t,0,tn)/C = Vc[tn-1] + Int(Ic,t,tn-1,tn) , Ic = (Vin - Vout) / R substitution ==> Vc = Vc[tn-1] + Int((Vin-Vout),t,tn-1,tn)/(RC) This integral equation can be approximated by for instance (forward) Euler integration, which is the equivalent of the above approximation of the digital filter, assuming the integration delta t interval is one sample long: Vout[n] = Vout[n-1] + int((Vin[n]-Vout[n-1]),t,t[n-1],t[n])/RC , Vout[n] = Vout[n-1] + dt * (Vin[n]-Vout[n-1]) / RC Alternatively, Vin and Vout could be Fourier transformed, to compute the frequency dependent behaviour by taking the norm of the resulting transfer function, which of course leads to a 6dB/oct low pass filter with a cuttoff frequency of F-3dB = 1/(2*pi*R*C) Hz, or RC = 1/(2*pi*Fcutoff) . Taking into consideration that the cutoff frequency will usually not lie under 20Hz, the worst case of the Vin-Vout signal fed to the integrator will never be a square, but an approximated charge curve, of which the integral is roughly no more than only half the above estimate, so the integrator has an output amplitude that is at most rougly a thousand times larger than the input signal. The digital filter can now be written as a function of the cutoff frequency as: Vout[n] = Vout[n-1] + (Vin[n]-Vout[n-1]) * (1/44100) * 2*pi*Fcutoff Vout[n] = Vout[n-1] + (Vin[n]-Vout[n-1]) * 142.48e-6 * Fcutoff Integration criteria Because of the simple forward Euler integration, the integral computing the charge on the capacitor is computed with a 0 order crudely linearized way, which yields an increasing error as the intergated values vary rapidly. This in turn makes the output samples noisy, irrespective of the sampling (bit) accuracy. A first order integral approximation would be: Vout[n] = Vout[n-1] + ((Vin[n]+Vin[n-1])/2-Vout[n-1]) * (1/44100) * 2*pi*Fcutoff Integration with prediction for the next Vc To improve the accuracy of the update integral for the voltage over the capacitor, its next value can be predicted, and the resulting integral can be corrected using the outcome. Complete Set of Design Considerations DC component compensation Headroom during all-pass, extreme low pass, and resonating mode over all frequencies. Cascading 4 filter stages, and adding 'resonance' Phase shift at the cutoff frequency is roughly 45 degrees per section, resulting in a 180 degree overall phase shift. To achieve feedforward, the output can be inverted and mixed back with the input signal, with a factor of up to -2 amplification (1 / ( 4 * 1/2 sqrt(2) ). *** check this ***: -4, not norm but real part of signal ?? To achieve a peak in the transfer characteristic up to oscilation.