Filter Tutorial 1: Simple Filters
This group of tutorials look at different ways to use filters in MSP. This includes the basic uses of filters for the equalization and shaping of a sound and using filters to create timbres in subtractive synthesis. Along the way, we'll look at some of the theory behind filters and how they work.
So what is a filter, anyway?
A filter is a circuit or software routine that can change the spectral shape of a signal; that is, it will change the amplitude of some frequency regions and leave others alone. The simplest example is the bass control found on most audio systems—it will increase the low end of the music, or if that's not your style, turn it down. Similarly, the treble control will afect the high end. Both leave the middle as it is. There are many kinds of filter available; some are named by what they do, others are named by the technique used to implement them. When we talk about filters, we will make use of the following terms:
-
Any audio system can be described by its
frequency response
, which is a graph of the amplitude change across the audio spectrum (20-20,000 Hz). in an ideal system, the graph is a straight line, indicating aflat
frequency response. To talk about filters, we look at the frequency response. -
The frequency region that is unaffected by a filter is the
passband
. -
A
highpass
filter affects signals lower than a specified frequency. -
A
lowpass
filter affects signals higher than a specified frequency. -
Most filters have a gradual transition from the passband to the rejected region. The shape of this transition is called the
slope
, which is specified in dB per octave. -
The frequency at which a filter becomes effective is called the
cutoff frequency
. It is actually the frequency at which the signal is reduced by 3dB. (A just noticeable difference in level.) -
A
bandpass
filter affects signals above and below a specifiedcenter frequency
. -
Obviously, a bandpass filter has two cutoff frequencies. The difference between these is the
bandwidth
. -
The ratio of center frequency to bandwidth of a bandpass filter is known as the
quality factor
orQ
of the filter. A filter with high Q will have a narrow passband. A filter with a high Q will also, depending on design, tend to resonate. This has led to an association of Q and a feature calledresonance
, at least in synthesis circles. Strictly speaking, resonance is a feature of some low and high pass designs, but some authors (and manufacturers) use the terms interchangeably. -
The opposite of a bandpass filter is a
notch
filter, which rejects a band in the middle of the spectrum. -
In addition to modifying amplitude of each frequency, filters also modify phase. A plot of phase change vs. frequency is the
phase response
. An ideal phase response would also be a flat line.
Filters have many uses from clearifying the vocals in a thrash mix to creating the sound of a Hungarian horntail. Often, filters are combined into complex devices like equalizers and vocoders. MSP has filters of all types, and new ones are added with each release (not to mention hundreds of third party externals).
Our first filter: lores~
Take a look at the tutorial patcher. Patcher area 1
contains a simple sampler, playing the sacre.aiff sound (loaded into a buffer~ named chords
) using the groove~ object. The circuit shown in this patch allows us to "play" the sample at any pitch with the kslider.
-
Turn on the audio in the patcher with the toggle box. Adjust the number box labeled 'Dry volume' and play some of the notes on the kslider. You should hear the sample play at different notes.
-
Turn down the 'Dry volume' and turn up the next number box, labeled 'Lowpass volume'. Notice the change in sound. Turn the dial object at the top of patcher region
2
. As you move the dial to a higher value, more of the high frequencies from the sample are audible.
The lores~ object implements a lowpass filter on an incoming audio signal (in our case, the output of the groove~ object. A lowpass filter, as we saw in the tutorial introduction, passes the low frequencies and attenuates the high frequencies of the incoming signal. The two parameters that the filter takes are the cutoff frequency (specified in the middle inlet or as the first argument to the object) and the resonance (specified in the right inlet or as the second argument).
The cutoff frequency of a lowpass filter determines the frequency at which the audio is attenuated 3 dB. The resonance amount, when greater than 0.
, controls a peak of resonation (boosted frequencies) immediately below the cutoff. If we plot the response of the filter on a graph with the X axis representing frequency and the Y axis representing gain, it would look like this:
- With the sound going, adjust the number box labeled 'Resonance' in patcher area
2
. Notice how as the resonation approaches1
the ringing at the resonance frequency becomes very loud. Adjust the cutoff frequency with the resonance set to a high number. Notice how you can now audibly "sweep" the filter based on hearing the resonation.
Bandpass filters: the reson~ object
- Turn down the volume of the lowpass filter, and look at section
3
in the tutorial. Turn up the number box labeled 'Bandpass volume'. Sweep the dial labeled 'Center frequency' and listen to the result.
Just as a lowpass filter passes low frequency, a bandpass filter passes a band of frequencies, attenuating anything lower or higher than a center frequency. The MSP reson~ object implements a bandpass filter with three parameters (controllable as inlets or arguments): the filter's gain, the center frequency, and Q.
- With the dial controlling the center frequency at 12 o'clock, click in the number box labeled 'Q' in patcher area
3
. Type the number3
and hit return. Listen to the results. Try other positive numbers, such as6
,10
, or0.5
. Notice that the higher the number is, the less frequencies make it through the filter. If necessary, adjust the 'Gain' with the number box to the left.
A bandpass filter with Q values of 0.5
, 1.0
, 3.0
, and 30.0
, respectively.
The state-variable filter: svf~
- Turn down the 'Bandpass volume' and look at patcher area
4
. Turn up the number box labeled 'Lowpass', adjust the 'Cutoff/Center Freq.' dial, and set the 'Resonance' number box to something that sounds good to you. Now, turn down the 'Lowpass' control and raise the 'Highpass'. Notice the difference. Do the same with thenumber boxobjects labeled 'Bandpass' and 'Notch'. Play with different combinations of volumes and settings.
The MSP svf~ object simulates an analogue state-variable filter. Because of the way in which filters are wired using electronic components, the difference between one type of filter and another is often simply a matter of how you wire (or where you 'tap') the circuit. A state-variable filter is a filter that allows you to tap energy from several places in the filter, getting four simultaneous filters for the price of one. The svf~ object gives you four filtered sounds: a lowpass output , a highpass output , a bandpass output , and a notch output. The notch output should mirror the response of the equivalent bandpass filter. Notch filters are often called bandstop or bandreject filters. A plot of these possibilities shows their frequency responses:
The outputs of a state-variable filter: lowpass, highpass, bandpass, notch.
- Play with different combinations of the filters in the tutorial, mixing them in different ways with different settings. In the next tutorial, we'll look at building more complex filter arrangements.
How is all of this done digitally?
Filters, put simply, are algorithms that alter the frequency spectrum of a sound. When working with digital audio in the time domain (i.e. as a stream of samples representing the amplitude of a wave), filters are implemented as equations that use short delays to shape an incoming waveform.
As an example, let's say we wanted to roll off the treble on an audio signal. If we plot a waveform, we can intuit the visual difference between low frequency and high frequency content:
As we can see, the top waveform (stored in the buffer~ named lowfrequency
, contains a sine wave at 50 Hz. The bottom waveform (in the highfrequency
buffer~) contains a complex FM tone with lots of high frequencies. If we wanted to roll off the treble on the bottom waveform, we could think of how it looks: high frequencies look like sharper angles when plotted in time. In order to cut high frequencies, we could smooth this waveform. One way to smooth a signal is to average it over time.
Let's say that we take a much simpler signal, that of a single sample of 1
in a sea of 0
's. This is called an impulse :
An impulse has a frequency response equivalent to pure noise... hypothetically, all frequencies are present at equal volume (think of a 'click' in a digital audio signal or any other short burst of sound). So it contains plenty of high frequencies. If we wanted to smooth this signal, we could average each sample with the previous sample in this signal:
This has the result of smearing the energy of the impulse across two samples. As a result, its frequency response will contain much less high-frequency energy; in fact, it's almost as if we've lowered the sampling rate: a click that lasts one sample at 44,100 Hz contains energy all the way up to 22,050 Hz; by derivation, a click that lasts two samples at that sampling rate is the same as a one-sample click at half that rate, i.e. it only has energy up to 11,025 Hz.
Some filter definitions
If we were to generalize what we just did to our impusle when we smoothed it, we could say this:
yn = 0.5xn + 0.5xn-1
where x represents incoming samples, y represents outgoing samples, and n represents the current time on the sample clock (i.e. now). This equation defines the filter: we're averaging (multiplying by 0.5) the current and previous incoming samples to generate the outgoing samples.
To put a name on this filter, we could call it a first-order non-recursive lowpass filter. The order of a filter refers to how many samples of delay it contains: because we're only looking at one previous input, it's a first-order filter. Because the filter only uses incoming samples in its equation, it's non-recursive. As for what it does, it passes low frequencies (and cuts high ones): hence the term lowpass.
Now consider this equation:
yn = 0.5xn + 0.5yn-1
This filter uses the previous outgoing sample from the filter as part of the filter itself; by implementing feedback in the filter, we get a much stronger effect:
This equation defines a recursive filter; as a result, the effect of the filter is dissipated beyond the order of the filter. While our first equation spread the energy of our one-sample click over two samples, this new equation spreads the energy over many, because of the averaging. Consider how the click interacts with the equation:
(xn + yn-1) / 2 =yn (1.0 + 0.0) / 2 = 0.5 (0.0 + 0.5) / 2 = 0.25 (0.0 + 0.25) / 2 = 0.125 (0.0 + 0.125) / 2 = 0.075 and so on...
In the filter described above, the energy of the click, hypothetically, will never fully dissipate. Another term for this kind of filter is an IIR, or infinite impulse response, filter; our first filter, which only uses incoming samples in its terms, has a finite impulse response (an FIR filter).
In a later tutorial, we'll revisit some more filter theory. For now, it's simply important to understand that filters are made by manipulating very short (often single sample) delays (either with or without feedback) and mixing them with the current sample.
Summary
Filters are devices or software that modify the frequency response of systems. Common filter types include lowpass, highpass, bandpass, and notch. Lowpass filters can be created with the lores~ object, bandpass filters with the reson~ object, and all four with the svf~ object. Filters commonly have controls for their center or cutoff frequency and their Q or resonance.
In digital signal processing, filters refer to equations which modify the frequency response of a signal. Filters are constructed by mixing small amounts of delayed signal with the original, smoothing or sharpening the waveform to accentuate or attenuate different frequencies.