Digital Music Programming 2: DC Blocking FilterThis lab demonstrates how to write a program which will filter out unwanted DC components in a soundfile caused by a cheap microphone input or by processing of a soundfile which adds a DC signal to the soundfile. The ProblemMany cheaper computer microphone inputs add a constant voltage offset to a recorded sound as demonstrated in the figure below:
When processing sound, it is more desirable to have the waveform centered about the zero point; otherwise the sound has a greater chance of clipping, especially if you add several sounds together. Besides, you cannot here 0 Hz, so you do not need to record it. Here is what we actually want, a signal (in this case a sinewave) with no DC component:
The SolutionTo get rid of 0 Hz frequencies in the soundfile, it must be filtered. It is possible to subtract a constant amount from every sample in the soundfile, but a more generalized solution which will work in more situations, and work automatically is to filter out the low frequencies.The simplest and most effect way of filtering out the low frequencies is with the following filter, shown as a flowgraph:
Below is a picture of a soundfile on the left which has a noticeable DC offset. The picture of the same sound on the right has been passed through the DCblocking filter given in the flowgraph above, and it is now centered around rather than above the zero line.
How to convert the flowgraph to an actual program implementation? The flowgraph describes graphically what happens to the input signal as it is filtered. There are three paths the input (and output) to the DC blocking filter make when passing through the filter. The three separate paths of the signal through the flowgraph are highlighted in the picture below:
After identifying the independent signal paths in the filter, it is easy to write down the difference equation: y[n] = x[n]  x[n1] + a * y[n1] Remember in class the steps to figure out how the frequencies are affected by the filter:
Now, with the last equation for the frequency response, the following picture can be generated from the absolute value (or magnitude) of the frequency response:
This picture shows how the frequencies are effected below 400 Hz in a sound sampled at 44.1 kHz. The different plots are related to the scale value a in the flowgraph. When a is close to 1.0, then the filter will only filter out very low frequencies. As a goes toward 0.0, more and more frequencies are noticeable affected by the filter. At a=0.95, the attenuation (lowering of volume) of the sound at 400 Hz would be noticeable since there is a drop of 3dB for sounds in that region of the spectrum. For musical purposes a is usually set to 0.995 because only frequencies below 30 Hz or so will be significantly reduced, while higher frequencies will remain mostly unaffected by the filter. A useful analysis of the filter can be done by examining the locations of the poles and zeros on the zplane. We haven't covered this in class yet, but you can contemplate what the following picture means for next week:
Exercises
