22.09.2015 Views

of Microprocessors

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

Musical-Applications-of-Microprocessors-2ed-Chamberlin-H-1987

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DIGITAL FILTERING 485<br />

the input wave by 90°. This behavior is just what would be expected <strong>of</strong> a real<br />

analog integrator. Even the de <strong>of</strong>fset at the output would be expected, since<br />

the input was suddenly applied at zero-crossing time. Although not apparent<br />

in the figure, the integrator does not contribute any noise or distortion to the<br />

signals passing through but may alter the signal-to-noise ratio due to its<br />

filtering effect.<br />

Digital R-C Low-Pass Filter<br />

Returning to the leaky integrator equivalent <strong>of</strong> an R-C low-pass filter,<br />

let us see how the same effect can be accomplished digitally. It should be<br />

obvious that the magnitude <strong>of</strong> the leakage current is proportional to the<br />

voltage across the capacitor and the direction is such that the capacitor is<br />

discharged. Since the capacitor voltage is the same as the output voltage (the<br />

capacitor lead connected to the op-amp's inverting input is at virtual<br />

ground), the leakage current is proportional to the instantaneous output<br />

voltage. This same discharging effect can be simulated by subtracting a constant<br />

proportion <strong>of</strong> the accumulator's content from the accumulator every sample<br />

period. In fact, the percentage <strong>of</strong> accumulator "charge" that should be<br />

subtracted is exactly equal to the percentage that would have leaked through<br />

the leakage resistor during one sample period in the analog filter.<br />

It is well known that the capacitor voltage during discharge follows an<br />

inverse exponential curve: E=Eoexp(-T/RC), where E is the voltage after<br />

time T, Eo is the initial voltage, and Rand C are the component values in<br />

ohms and farads. Since the cut<strong>of</strong>f frequency is l/2nRC, a substitution can be<br />

made in the equations, and it is found that E =Eoexp(21TFcT), where Fe is the<br />

cut<strong>of</strong>ffrequency <strong>of</strong> the filter. Converting the sample period, T, to the sample<br />

rate, Fs, makes the final result: E=Eoexp(-21TFc!Fs). Thus, the proper<br />

percentage to subtract from the accumulator each sample period is:<br />

l-exp(- 21TFc!Fs) which can be designated K. A BASIC statement for implementing<br />

the digital filter then would be:<br />

1000 LET A=A-K*A+I<br />

where A is the accumulator content, K is the leakage constant, and I is the<br />

input sample. This statement is executed for each input sample and successive<br />

values <strong>of</strong> A are the output samples.<br />

One could also simply multiply the accumulator contents by l-K,<br />

which can be called L, and put the product back into the accumulator with<br />

the input added in. In BASIC, the result would be:<br />

1000 LET A=A*L+l<br />

which is about as simple as one can get. Note that L can never be greater than<br />

1.0. If it were, the filter would be unstable and eventually overflow evenfloating-point<br />

arithmetic. (Imagine, a universe full <strong>of</strong> energy circulating in<br />

this little filter!)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!