Namespaces

Variants
Actions

MSP Filter Tutorial 2: Variable Type Filters

From Cycling '74 Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "Click here to open the tutorial patch: 02fVariableTypeFilters.maxpat In the last tutorial we introduced some basic filters in MSP. This tutorial looks at two new filter o...")
 
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
Click here to open the tutorial patch: [[02fVariableTypeFilters.maxpat]]
+
Click here to open the tutorial patch: [[Media:02fVariableTypeFilters.maxpat]]
  
In the last tutorial we introduced some basic filters in MSP. This tutorial
+
In the first filter tutorial, we introduced some basic filters in MSP. This tutorial looks at two new filter objects: {{maxword|name=biquad~}}, which can create any kind of simple filter, and {{maxword|name=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.
looks at two new filter objects: {{maxword|name=biquad~}}, which can create any kind of
+
simple filter, and {{maxword|name=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.
+
  
 
===Biquadratic filters===
 
===Biquadratic filters===
  
* Look at the tutorial patcher. Just as in the last tutorial, area <code>1</code> consists
+
* Look at the tutorial patcher. Just as in the last tutorial, area <code>1</code> consists of a looping playback system that plays a {{maxword|name=buffer~}} using the {{maxword|name=groove~}} object. Turn on the audio, turn up the {{maxword|name=number}} box labeled 'Dry Volume', click on a note in the {{maxword|name=kslider}}, and make sure you can hear some sound.
of a looping playback system that plays a {{maxword|name=buffer~}} using the {{maxword|name=groove~}} object. Turn on the audio, turn up the {{maxword|name=number}} box labeled 'Dry Volume', click on a
+
note in the {{maxword|name=kslider}}, and make sure you can hear some sound.
+
  
* Take a look at area <code>2</code> of the tutorial. The sound from the {{maxword|name=groove~}}
+
* Take a look at area <code>2</code> of the tutorial. The sound from the {{maxword|name=groove~}} object feeds into an object called {{maxword|name=biquad~}}. Turn down the 'Dry Volume' and turn up the {{maxword|name=number}} box labeled 'Biquad Volume'. Click on the different circles in the {{maxword|name=preset}} object at the top of patcher aread <code>2</code>. Listen to the changes in the sound.
object feeds into an object called {{maxword|name=biquad~}}. Turn down the 'Dry Volume'
+
and turn up the {{maxword|name=number}} box labeled 'Biquad Volume'. Click on the different
+
circles in the {{maxword|name=preset}} object at the top of patcher aread <code>2</code>.
+
Listen to the changes in the sound.
+
  
 
In the last tutorial, we discussed how filters could be expressed as equations, e.g.
 
In the last tutorial, we discussed how filters could be expressed as equations, e.g.
Line 23: Line 13:
 
y<sub>n</sub> = 0.5x<sub>n</sub> + 0.5y<sub>n-1</sub>
 
y<sub>n</sub> = 0.5x<sub>n</sub> + 0.5y<sub>n-1</sub>
  
The <code>0.5</code> values in the equation above set the respective gains of the
+
The <code>0.5</code> values 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.:
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.:
+
  
 
y<sub>n</sub> = Ax<sub>n</sub> + By<sub>n-1</sub>
 
y<sub>n</sub> = Ax<sub>n</sub> + By<sub>n-1</sub>
  
By modifying the values of <code>A</code> and <code>B</code>, we could control the frequency
+
By modifying the values of <code>A</code> and <code>B</code>, 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 y<sub>n-1</sub> term), the smoother the output and the more the high frequencies are supressed.
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 y<sub>n-1</sub> 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
+
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:
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:
+
  
 
y<sub>n</sub> = Ax<sub>n</sub> + Bx<sub>n-1</sub> + Cx<sub>n-2</sub> - Dy<sub>n-1</sub> - Ey<sub>n-2</sub>
 
y<sub>n</sub> = Ax<sub>n</sub> + Bx<sub>n-1</sub> + Cx<sub>n-2</sub> - Dy<sub>n-1</sub> - Ey<sub>n-2</sub>
  
This equation uses the incoming sample, the ''last two'' incoming samples,
+
This equation uses the incoming sample, the ''last two'' incoming samples, and the last two ''outgoing'' samples 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 MSP {{maxword|name=biquad~}} object implements a biquadratic filter. Unfortunately, it takes as its input the input signal and the five coefficients that define the filter. What we really want to do, though, is specify our filter not by the equation, but by how we want it to sound.
and the last two ''outgoing'' samples 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 MSP {{maxword|name=biquad~}} object implements a biquadratic filter. Unfortunately,
+
it takes as its input the input signal and the five coefficients that define
+
the filter. What we really want to do, though, is specify our filter not by
+
the equation, but by how we want it to sound.
+
  
===The {{maxword|name=filtergraph~}} object===
+
===The filtergraph~ object===
  
The user-interface object connected to the {{maxword|name=biquad~}} object in the tutorial
+
The user-interface object connected to the {{maxword|name=biquad~}} object in the tutorial patcher is called a {{maxword|name=filtergraph~}}. It allows us to physically drag around within a box to set parameters of a filter. In addition, you can send messages to a {{maxword|name=filtergraph~}} object to set its parameters, as well as change what kind of filter it shows. Whenever you make a change to the {{maxword|name=filtergraph~}} object, it outputs a set of coefficients as a Max list which the {{maxword|name=biquad~}} object interprets to perform the equivalent filter equation. The {{maxword|name=message}} box below the {{maxword|name=filtergraph~}} in the patcher shows us these coefficients.
patcher is called a {{maxword|name=filtergraph~}}. It allows us to physically drag around
+
within a box to set parameters of a filter. In addition, you can send messages
+
to a {{maxword|name=filtergraph~}} object to set its parameters, as well as change what
+
kind of filter it shows. Whenever you make a change to the {{maxword|name=filtergraph~}}
+
object, it outputs a set of coefficients as a Max list which the {{maxword|name=biquad~}}
+
object interprets to perform the equivalent filter equation. The {{maxword|name=message}} box
+
below the {{maxword|name=filtergraph~}} in the patcher shows us these coefficients.
+
  
* Using the {{maxword|name=umenu}} object, select a <code>lowpass</code> filter from the
+
* Using the {{maxword|name=umenu}} object, select a <code>lowpass</code> filter from the {{maxword|name=filtergraph~}}. Using the mouse, click and drag in the pink region in the middle of the filter response. You can adjust the cutoff frequency of the filter as well as its overall gain. Click on the edges of the pink region and drag inward and outward. This allows you to set the resonance of the filter. The values you are creating (in terms of cutoff frequency, gain, and slope) can be seen in the <link type="refpage" name="number">number box</link> objects to the right of the object.
{{maxword|name=filtergraph~}}. Using the mouse, click and drag in the pink region
+
in the middle of the filter response. You can adjust the cutoff frequency
+
of the filter as well as its overall gain. Click on the edges of the pink
+
region and drag inward and outward. This allows you to set the resonance of
+
the filter. The values you are creating (in terms of cutoff frequency, gain,
+
and slope) can be seen in the <link type="refpage" name="number">number box</link> objects to the right of the object.
+
  
The {{maxword|name=filtergraph~}} object is capable of graphing and generating
+
The {{maxword|name=filtergraph~}} object is capable of graphing and generating coefficients for a wide variety of filter curves, including lowpass, highpass, bandpass, bandstop (or notch), ''peaknotch'' (a band filter that can either boost or cut a frequency band), ''lowshelf / highshelf'' (filters that can boost or cut frequencies lower or higher than a cutoff), ''resonant'' (a bandpass filter where its gain increasing with the Q), and ''allpass'' (a filter that changes the phase relationships of frequencies without altering their gains). All of these filters can be modeled by a {{maxword|name=biquad~}} object.
coefficients for a wide variety of filter curves, including lowpass,
+
highpass, bandpass, bandstop (or notch), ''peaknotch'' (a band filter
+
that can either boost or cut a frequency band), ''lowshelf / highshelf''
+
(filters that can boost or cut frequencies lower or higher than a cutoff),
+
''resonant'' (a bandpass filter where its gain increasing with the Q),
+
and ''allpass'' (a filter that changes the phase relationships of frequencies
+
without altering their gains). All of these filters can be modeled by
+
a {{maxword|name=biquad~}} object.
+
  
* Acclimatize yourself to the user interface of the {{maxword|name=filtergraph~}}
+
* Acclimatize yourself to the user interface of the {{maxword|name=filtergraph~}} object by selecting different filter types from the {{maxword|name=umenu}} and dragging around to create different filters. Note that some filters have inherently more potential gain than others.
object by selecting different filter types from the {{maxword|name=umenu}} and
+
dragging around to create different filters. Note that some filters
+
have inherently more potential gain than others.
+
  
===Filters in series: {{maxword|name=cascade~}}===
+
===Filters in series: cascade~===
  
Filtering plays a huge role in audio-related creative work, whether we're
+
Filtering plays a huge role in audio-related creative work, whether we're discussing contemporary music production techniques or avant-garde sound art. It's often the case that a simple filter that only affects one range of frequencies isn't enough to perform the task we want. You can easily chain {{maxword|name=biquad~}} objects (or other filters) by hand in an MSP patcher to create filters operating in series. If you have an idea of how many filters you want to operate in this manner, you can instead use a single object that creates and manages up to 24 different filters arranged in series: {{maxword|name=cascade~}}.
discussing contemporary music production techniques or avant-garde sound art.
+
It's often the case that a simple filter that only affects one range of frequencies
+
isn't enough to perform the task we want. You can easily chain {{maxword|name=biquad~}} objects
+
(or other filters) by hand in an MSP patcher to create filters operating in series.
+
If you have an idea of how many filters you want to operate in this manner, you
+
can instead use a single object that creates and manages up to 24 different filters
+
arranged in series: {{maxword|name=cascade~}}.
+
  
* Turn down the 'Biquad Volume' and turn your attention to area <code>3</code> of the
+
* Turn down the 'Biquad Volume' and turn your attention to area <code>3</code> of the tutorial patcher. Turn up the 'Cascade Volume' {{maxword|name=number}} box and click on the different selections in the {{maxword|name=preset}} object. Notice how the sound changes. Using the {{maxword|name=number}} box labeled 'Select a filter', send the message <code>selectfilt 0</code> to the {{maxword|name=filtergraph~}} in this part of the patcher. Change the {{maxword|name=number}} box to <code>1</code>, <code>2</code>, <code>3</code>, and <code>4</code>, and see how different component filters within the {{maxword|name=filtergraph~}} highlight themselves. The settings for each of these filters also comes out of the object, setting the <link type="refpage" name="number">number box</link> objects to the right.
tutorial patcher. Turn up the 'Cascade Volume' {{maxword|name=number}} box and click on the
+
different selections in the {{maxword|name=preset}} object. Notice how the sound changes.
+
Using the {{maxword|name=number}} box labeled 'Select a filter', send the message
+
<code>selectfilt 0</code> to the {{maxword|name=filtergraph~}} in this part of the patcher.
+
Change the {{maxword|name=number}} box to <code>1</code>, <code>2</code>, <code>3</code>, and <code>4</code>,
+
and see how different component filters within the {{maxword|name=filtergraph~}} highlight
+
themselves. The settings for each of these filters also comes out of the object,
+
setting the <link type="refpage" name="number">number box</link> objects to the right.
+
  
As we can see, the {{maxword|name=filtergraph~}} object is capable of maintaining the
+
As we can see, the {{maxword|name=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 {{maxword|name=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.
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 {{maxword|name=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.
+
  
* Pick a {{maxword|name=preset}} setting you like for the {{maxword|name=cascade~}} object.
+
* Pick a {{maxword|name=preset}} setting you like for the {{maxword|name=cascade~}} object. Select a filter to edit with the <code>selectfilt</code> message, and drag your mouse in the {{maxword|name=filtergraph~}} to edit the filter. Notice how the filters interact with one another. For example, a lowpass filter set at the same frequency as a highpass filter will cancel one another out. Similarly, a bandpass filter can sit at the 'slope' of a lowpass filter to simulate a resonation point.
Select a filter to edit with the <code>selectfilt</code> message, and drag your
+
mouse in the {{maxword|name=filtergraph~}} to edit the filter. Notice how the filters
+
interact with one another. For example, a lowpass filter set at the same
+
frequency as a highpass filter will cancel one another out. Similarly,
+
a bandpass filter can sit at the 'slope' of a lowpass filter to simulate
+
a resonation point.
+
  
If we unlock the patcher and open the
+
If we unlock the patcher and open the Inspector for the {{maxword|name=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 {{maxword|name=filtercoeff~}} takes the same settings as the {{maxword|name=filtergraph~}} object without a graphical component, allowing you to feed coefficients to a {{maxword|name=biquad~}} or {{maxword|name=cascade~}} object without having to graph the filter yourself.
<link type="vignette" module="core" name="inspector">Inspector</link>
+
for the {{maxword|name=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 {{maxword|name=filtercoeff~}} takes the same settings
+
as the {{maxword|name=filtergraph~}} object without a graphical component, allowing
+
you to feed coefficients to a {{maxword|name=biquad~}} or {{maxword|name=cascade~}} object
+
without having to graph the filter yourself.
+
  
 
===Summary===
 
===Summary===
  
The {{maxword|name=biquad~}} object implements a generic filter equation that can
+
The {{maxword|name=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 {{maxword|name=filtergraph~}} object is a user-interface object that lets you visually construct simple and complex filters of many types; the {{maxword|name=filtercoeff~}} object will accomplish the same thing, without the user interface. The {{maxword|name=cascade~}} object acts as a group of {{maxword|name=biquad~}} objects arranged in ''series'', and allows you to easily construct compound filter curves in your patcher.
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 {{maxword|name=filtergraph~}}
+
object is a user-interface object that lets you visually construct simple
+
and complex filters of many types; the {{maxword|name=filtercoeff~}} object will
+
accomplish the same thing, without the user interface. The {{maxword|name=cascade~}}
+
object acts as a group of {{maxword|name=biquad~}} objects arranged in ''series'',
+
and allows you to easily construct compound filter curves in your patcher.
+
  
 
===See Also===
 
===See Also===

Latest revision as of 15:31, 28 June 2012

Click here to open the tutorial patch: Media:02fVariableTypeFilters.maxpat

In the first filter 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.

Contents

[edit] Biquadratic filters

  • Look at the tutorial patcher. Just as in the last tutorial, area 1 consists of a looping playback system that plays a buffer~ using the groove~ object. Turn on the audio, turn up the number box labeled 'Dry Volume', click on a note in the kslider, and make sure you can hear some sound.
  • Take a look at area 2 of the tutorial. The sound from the groove~ object feeds into an object called biquad~. Turn down the 'Dry Volume' and turn up the number box labeled 'Biquad Volume'. Click on the different circles in the preset object at the top of patcher aread 2. Listen to the changes in the sound.

In the last tutorial, we discussed how filters could be expressed as equations, e.g.

yn = 0.5xn + 0.5yn-1

The 0.5 values 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 of A and B, 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, the last two incoming samples, and the last two outgoing samples 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 MSP biquad~ object implements a biquadratic filter. Unfortunately, it takes as its input the input signal and the five coefficients that define the filter. What we really want to do, though, is specify our filter not by the equation, but by how we want it to sound.

[edit] The filtergraph~ object

The user-interface object connected to the biquad~ object in the tutorial patcher is called a filtergraph~. It allows us to physically drag around within a box to set parameters of a filter. 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.

  • Using the umenu object, select a lowpass filter from the filtergraph~. Using the mouse, click and drag in the pink region in the middle of the filter response. You can adjust the cutoff frequency of the filter as well as its overall gain. Click on the edges of the pink region and drag inward and outward. This allows you to set the resonance of the filter. The values you are creating (in terms of cutoff frequency, gain, and slope) can be seen in the <link type="refpage" name="number">number box</link> objects to the right of the object.

The filtergraph~ object is capable of graphing and generating coefficients for a wide variety of filter curves, including lowpass, highpass, bandpass, bandstop (or notch), peaknotch (a band filter that can either boost or cut a frequency band), lowshelf / highshelf (filters that can boost or cut frequencies lower or higher than a cutoff), resonant (a bandpass filter where its gain increasing with the Q), and allpass (a filter that changes the phase relationships of frequencies without altering their gains). All of these filters can be modeled by a biquad~ object.

  • Acclimatize yourself to the user interface of the filtergraph~ object by selecting different filter types from the umenu and dragging around to create different filters. Note that some filters have inherently more potential gain than others.

[edit] Filters in series: cascade~

Filtering plays a huge role in audio-related creative work, whether we're discussing contemporary music production techniques or avant-garde sound art. It's often the case that a simple filter that only affects one range of frequencies isn't enough to perform the task we want. You can easily chain biquad~ objects (or other filters) by hand in an MSP patcher to create filters operating in series. If you have an idea of how many filters you want to operate in this manner, you can instead use a single object that creates and manages up to 24 different filters arranged in series: cascade~.

  • Turn down the 'Biquad Volume' and turn your attention to area 3 of the tutorial patcher. Turn up the 'Cascade Volume' number box and click on the different selections in the preset object. Notice how the sound changes. Using the number box labeled 'Select a filter', send the message selectfilt 0 to the filtergraph~ in this part of the patcher. Change the number box to 1, 2, 3, and 4, and see how different component filters within the filtergraph~ highlight themselves. The settings for each of these filters also comes out of the object, setting the <link type="refpage" name="number">number box</link> objects to the right.

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.

  • Pick a preset setting you like for the cascade~ object. Select a filter to edit with the selectfilt message, and drag your mouse in the filtergraph~ to edit the filter. Notice how the filters interact with one another. For example, a lowpass filter set at the same frequency as a highpass filter will cancel one another out. Similarly, a bandpass filter can sit at the 'slope' of a lowpass filter to simulate a resonation point.

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.

[edit] Summary

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.

[edit] See Also

biquad~ - Two-pole, two-zero filter

filtergraph~ - Graphical filter editor

cascade~ - Cascaded series of biquad filters

filtercoeff~ - Signal-rate filter coefficient generator