In the last tutorial we introduced some basic filters in MSP. This tutorial looks at two new filter objects: biquad~, which can create any kind of simple filter, and cascade~, which can create and manage multiple independent filters in a single object. We'll also look at a user interface object that helps us edit these filters in an intuitive way.
Take a look at area groove~ object feeds into an object called biquad~. This is a general purpose filter that can be set up for proactically any configuration just by adjusting a set of parameters called coefficients. (Details below.) Turn down the 'Dry Volume' and turn up the number box labeled 'Biquad Volume'. Click on the different buttons in the preset object at the top of patcher area and listen to the changes in the sound. The filter type and Critical parameters are shown just below the preset object along with a graphic display of the frequency response.of the tutorial. The sound from the
- The setting removes the highs from the percussion and takes the brightness from the brass. The bass line is now the loudest part of the sound.
- The setting removes the bass entirely and leaves only a ghost of the brass. The high partials of the bass and percussion wind up sounding like maracas.
- The setting is mostly brass and middle strings.
- The (notch) setting leaves a hole in the middle. (It's tuned to G in the treble clef.)
- The setting boosts material right at 500 Hz (treble clef C), bringing out the fundamantals of the brass and high strings. Since it does not remove anything, this is more of an equalization than a filter setting. We will see the notch feature in the next section.
- The setting is another type of equalization. Instead of rejecting the lowest frequencies entirely, as the highpass does, the range below the cutoff frequency can be either boosted or reduced, and everything in the active range is affected the same amount (with an octave or so of transition). The setting here is a typical hi-fi bass boost.
- Not surprisingly, the is the complement to the lowshelf. Both are key parts of standard equalizers.
- The setting is a tight bandpass filter. Graphic equalizers are made of a dozen or more resonant filters, each assigned to cover an octave or less of the spectrum.
- The setting sounds deceptively normal. The frequency response is flat, but the phase is changed, which becomes audible when you mix the allpass and dry signals. The phase change is 90° at the center frequency.
The filtergraph~ object
The object that shows the frequency response of the biquad~ object patcher is called a filtergraph~. It allows us to graphically set the parameters of a biquad~ filter with the mouse. Left-right motion sets the frequency or bandwidth of the filter and up-down motion sets the gain. In addition, you can send messages to a filtergraph~ object to set its parameters, as well as change what kind of filter it shows. Whenever you make a change to the filtergraph~ object, it outputs a set of coefficients as a Max list which the biquad~ object interprets to perform the equivalent filter equation. The message box below the filtergraph~ in the patcher shows us these coefficients.
Note that the filtergraph~ is connected to the second inlet of biquad~. If we unlock the patcher and open the Inspector for the filtergraph~ object, we can edit the specific types of filters that it generates coefficients for; in addition, we could change how many filters are maintained and some features of the user interface. By the opposite token, if you'd rather work with filters without a user interface, the MSP object filtercoeff~ takes the same settings as the filtergraph~ object without a graphical component, allowing you to feed coefficients to a biquad~ object without having to graph the filter yourself.
Filters in series: cascade~
A biquad~ filter is extremely versatile, but it is ultimately limited in one respect—how much filtering you get. If you look at the filtergraph~ display you will see that the ultimate slope (out of the box area) is fairly gentle: 12 dB per octave for low and high pass and only 6 dB per octave on the bandpass. If we want more intense filtering, we need to run the signal through through more filters. In addition, we often want a more complex response, with independent control at several frequencies. You can easily chain biquad~ objects (or other filters) by hand, or you can use a single object that creates and manages up to 24 different filters arranged in series: cascade~.
As we can see, the filtergraph~ object is capable of maintaining the state of more than one filter and showing us what the frequency response of these filters would be if they were connected in series. The cascade~ object takes a signal in its left inlet and a set of coefficients in its right, interpreting each incoming list as sets of 5 values, one set for each filter.
If we unlock the patcher and open the Inspector for the filtergraph~ object, we can edit the specific types of filters that it generates coefficients for; in addition, we could change how many filters are maintained and some features of the user interface. By the opposite token, if you'd rather work with filters without a user interface, the MSP object filtercoeff~ takes the same settings as the filtergraph~ object without a graphical component, allowing you to feed coefficients to a biquad~ or cascade~ object without having to graph the filter yourself.
Under the hood of biquad~
In the last tutorial, we discussed how filters could be expressed as equations, e.g.
yn = 0.5xn + 0.5yn-1
Thevalues in the equation above set the respective gains of the different samples used in the filter. If we wanted a more flexible filter, we could generalize this filter so that those numbers are variable, e.g.:
yn = Axn + Byn-1
By modifying the values ofand , we could control the frequency response of this filter. While the math behind this operation is beyond the scope of this tutorial, it's generally true that the more energy given to the delayed output sample (the yn-1 term), the smoother the output and the more the high frequencies are supressed.
A fairly standard tactic in digital filter design is to create a filter equation that can perform any kind of standard filtering operation (lowpass, bandpass, etc.) on an input signal. The most common implementation of this is called the biquadratic filter equation (or biquad). It consists of the following equation:
yn = Axn + Bxn-1 + Cxn-2 - Dyn-1 - Eyn-2
This equation uses the incoming sample (x), the last two incoming samples, and the last two outgoing samples (y) to generate its filter. (Another term for a biquadratic filter is a two-pole, two-zero filter, because it has four delay coefficients to affect its behavior.) By adjusting the five coefficients (A, B, C, D, E), you can generate all manner of filters.
The biquad~ object implements a generic filter equation that can model most types of simple filters. Because it expects coefficients for the filter equation, its often useful to use it in conjunction with another object that will compute these numbers. The filtergraph~ object is a user-interface object that lets you visually construct simple and complex filters of many types; the filtercoeff~ object will accomplish the same thing, without the user interface. The cascade~ object acts as a group of biquad~ objects arranged in series, and allows you to easily construct compound filter curves in your patcher.
|biquad~||Two-pole, two-zero filter|
|cascade~||Cascaded series of biquad filters|
|filtercoeff~||Signal-rate filter coefficient generator|