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 , 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 a frequency response. To talk about filters, we look at the frequency response.
- The frequency region that is unaffected by a filter is the .
- A filter affects signals lower than a specified frequency.
- A 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 , which is specified in dB per octave.
- The frequency at which a filter becomes effective is called the . It is actually the frequency at which the signal is reduced by 3dB. (A just noticeable difference in level.)
- A filter affects signals above and below a specified .
- Obviously, a bandpass filter has two cutoff frequencies. The difference between these is the .
- The ratio of center frequency to bandwidth of a bandpass filter is known as the or 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 called , 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 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 . 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~
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, 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:
Bandpass filters: the reson~ object
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.
The state-variable filter: svf~
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:
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 , contains a sine wave at 50 Hz. The bottom waveform (in the 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 ofin a sea of '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.
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.
|Sound Processing Techniques||Sound Processing Techniques|
|lores~||Resonant lowpass filter|
|reson~||Resonant bandpass filter|
|svf~||State-variable filter with simultaneous outputs|