https://cycling74.com/wiki/index.php?title=MSP_Filter_Tutorial_1:_Simple_Filters&feed=atom&action=historyMSP Filter Tutorial 1: Simple Filters - Revision history2016-12-09T15:33:45ZRevision history for this page on the wikiMediaWiki 1.19.1https://cycling74.com/wiki/index.php?title=MSP_Filter_Tutorial_1:_Simple_Filters&diff=824&oldid=prevGtaylor@rtqe.net at 15:30, 28 June 20122012-06-28T15:30:44Z<p></p>
<table class='diff diff-contentalign-left'>
<col class='diff-marker' />
<col class='diff-content' />
<col class='diff-marker' />
<col class='diff-content' />
<tr valign='top'>
<td colspan='2' style="background-color: white; color:black;">← Older revision</td>
<td colspan='2' style="background-color: white; color:black;">Revision as of 15:30, 28 June 2012</td>
</tr><tr><td colspan="2" class="diff-lineno">Line 1:</td>
<td colspan="2" class="diff-lineno">Line 1:</td></tr>
<tr><td class='diff-marker'>−</td><td style="background: #ffa; color:black; font-size: smaller;"><div>Click here to open the tutorial patch: [[01fSimpleFilters.maxpat]]</div></td><td class='diff-marker'>+</td><td style="background: #cfc; color:black; font-size: smaller;"><div>Click here to open the tutorial patch: [[<ins class="diffchange diffchange-inline">Media:</ins>01fSimpleFilters.maxpat]]</div></td></tr>
<tr><td class='diff-marker'>&#160;</td><td style="background: #eee; color:black; font-size: smaller;"></td><td class='diff-marker'>&#160;</td><td style="background: #eee; color:black; font-size: smaller;"></td></tr>
<tr><td class='diff-marker'>&#160;</td><td style="background: #eee; color:black; font-size: smaller;"><div>===Introduction===</div></td><td class='diff-marker'>&#160;</td><td style="background: #eee; color:black; font-size: smaller;"><div>===Introduction===</div></td></tr>
</table>Gtaylor@rtqe.nethttps://cycling74.com/wiki/index.php?title=MSP_Filter_Tutorial_1:_Simple_Filters&diff=772&oldid=prevAdmin at 21:14, 25 June 20122012-06-25T21:14:13Z<p></p>
<a href="https://cycling74.com/wiki/index.php?title=MSP_Filter_Tutorial_1:_Simple_Filters&amp;diff=772&amp;oldid=720">Show changes</a>Adminhttps://cycling74.com/wiki/index.php?title=MSP_Filter_Tutorial_1:_Simple_Filters&diff=720&oldid=prevAdmin: Created page with "Click here to open the tutorial patch: 01fSimpleFilters.maxpat ===Introduction=== This group of tutorials look at different ways to use ''filters'' in MSP. This includes..."2012-06-22T21:19:09Z<p>Created page with &quot;Click here to open the tutorial patch: <a href="/wiki/index.php?title=01fSimpleFilters.maxpat&amp;action=edit&amp;redlink=1" class="new" title="01fSimpleFilters.maxpat (page does not exist)">01fSimpleFilters.maxpat</a> ===Introduction=== This group of tutorials look at different ways to use &#039;&#039;filters&#039;&#039; in MSP. This includes...&quot;</p>
<p><b>New page</b></p><div>Click here to open the tutorial patch: [[01fSimpleFilters.maxpat]]<br />
<br />
===Introduction===<br />
<br />
This group of tutorials look at different ways to use ''filters'' in MSP.<br />
This includes the basic uses of filters for the equalization and shaping of a<br />
sound and using filters to create timbres in subtractive synthesis. Along the<br />
way, we'll look at some of the theory behind filters and how they work.<br />
<br />
===So what is a filter, anyway?===<br />
<br />
Filters are just algorithms that alter the frequency spectrum of<br />
a sound. When working with digital audio in the time domain (i.e. as a<br />
stream of samples representing the amplitude of a wave), filters are<br />
implemented as equations that use short ''delays'' to shape an<br />
incoming waveform.<br />
<br />
As an example, let's say we wanted to roll off the treble on an audio<br />
signal. If we plot a waveform, we can intuit the visual difference between<br />
low frequency and high frequency content:<br />
<br />
[[Image:Filterchapter01a.png|border]]<br />
''Two waveforms, one with a low frequency, one with lots of high frequencies''<br />
<br />
As we can see, the top waveform (stored in the {{maxword|name=buffer~}}<br />
named &lt;code&gt;lowfrequency&lt;/code&gt;, contains a sine wave at 50 Hz. The bottom<br />
waveform (in the &lt;code&gt;highfrequency&lt;/code&gt; {{maxword|name=buffer~}}) contains a<br />
complex FM tone with lots of high frequencies. If we wanted to roll<br />
off the treble on the bottom waveform, we could think of how it looks:<br />
high frequencies look like sharper angles when plotted in time. In<br />
order to cut high frequencies, we could ''smooth'' this waveform.<br />
One way to smooth a signal is to ''average'' it over time.<br />
<br />
Let's say that we take a much simpler signal, that of a single sample<br />
of &lt;code&gt;1&lt;/code&gt; in a sea of &lt;code&gt;0&lt;/code&gt;'s. This is called an ''impulse'':<br />
<br />
[[Image:Filterchapter01b.png|border]]<br />
''An impulse in an audio signal''<br />
<br />
An impulse has a frequency response equivalent to pure noise...<br />
hypothetically, all frequencies are present at equal volume (think of<br />
a 'click' in a digital audio signal or any other short burst of sound).<br />
So it contains plenty of high frequencies. If we wanted to smooth this<br />
signal, we could average each sample with the previous sample in this signal:<br />
<br />
[[Image:Filterchapter01c.png|border]]<br />
''Our impulse, smoothed over one sample''<br />
<br />
This has the result of smearing the energy of the impulse<br />
across two samples. As a result, its frequency response will<br />
contain much less high-frequency energy; in fact, it's almost<br />
as if we've lowered the sampling rate: a click that lasts one sample<br />
at 44,100 Hz contains energy all the way up to 22,050 Hz; by derivation,<br />
a click that lasts ''two'' samples at that sampling rate is the same<br />
as a one-sample click at half that rate, i.e. it only has energy up<br />
to 11,025 Hz.<br />
<br />
===Some filter definitions===<br />
<br />
If we were to generalize what we just did to our impusle<br />
when we smoothed it, we could say this:<br />
<br />
y&lt;sub&gt;n&lt;/sub&gt; = 0.5x&lt;sub&gt;n&lt;/sub&gt; + 0.5x&lt;sub&gt;n-1&lt;/sub&gt;<br />
<br />
where '''x''' represents ''incoming'' samples, '''y''' represents<br />
outgoing samples, and '''n''' represents the current ''time'' on<br />
the sample clock (i.e. ''now''). This equation defines the filter:<br />
we're averaging (multiplying by 0.5) the current and previous incoming<br />
samples to generate the outgoing samples.<br />
<br />
To put a name on this filter, we could call it a first-order non-recursive<br />
lowpass filter. The ''order'' of a filter refers to how many samples of<br />
delay it contains: because we're only looking at one previous input, it's a<br />
first-order filter. Because the filter only uses incoming samples in its<br />
equation, it's non-recursive. As for what it does, it ''passes'' low<br />
frequencies (and cuts high ones): hence the term ''lowpass''.<br />
<br />
Now consider this equation:<br />
<br />
y&lt;sub&gt;n&lt;/sub&gt; = 0.5x&lt;sub&gt;n&lt;/sub&gt; + 0.5y&lt;sub&gt;n-1&lt;/sub&gt;<br />
<br />
This filter uses the previous ''outgoing'' sample from the filter<br />
as part of the filter itself; by implementing feedback in the filter,<br />
we get a much stronger effect:<br />
<br />
[[Image:Filterchapter01d.png|border]]<br />
''Our impulse, averaged with the previous output sample''<br />
<br />
This equation defines a ''recursive'' filter; as a result, the effect<br />
of the filter is dissipated beyond the order of the filter. While our<br />
first equation spread the energy of our one-sample click over two samples,<br />
this new equation spreads the energy over many, because of the averaging.<br />
Consider how the click interacts with the equation:<br />
<br />
(x&lt;sub&gt;n&lt;/sub&gt; + y&lt;sub&gt;n-1&lt;/sub&gt;) / 2 = y&lt;sub&gt;n&lt;/sub&gt;<br />
<br />
(1.0 + 0.0) / 2 = 0.5<br />
<br />
(0.0 + 0.5) / 2 = 0.25<br />
<br />
(0.0 + 0.25) / 2 = 0.125<br />
<br />
(0.0 + 0.125) / 2 = 0.075<br />
<br />
and so on...<br />
<br />
In the filter described above, the energy of the click, hypothetically,<br />
will ''never'' fully dissipate. Another term for this kind of filter<br />
is an ''IIR'', or infinite impulse response, filter; our first filter,<br />
which only uses incoming samples in its terms, has a finite impulse<br />
response (an ''FIR'' filter).<br />
<br />
In a later tutorial, we'll revisit some more filter theory. For now, it's<br />
simply important to understand that filters are made by manipulating very<br />
short (often single sample) delays (either with or without feedback) and<br />
mixing them with the current sample.<br />
<br />
===Our first filter: {{maxword|name=lores~}}===<br />
<br />
Take a look at the tutorial patcher. Patcher area &lt;code&gt;1&lt;/code&gt; contains<br />
a simple sampler, playing the ''sacre.aiff'' sound (loaded into<br />
a {{maxword|name=buffer~}} named &lt;code&gt;chords&lt;/code&gt;) using the {{maxword|name=groove~}} object.<br />
The circuit shown in this patch allows us to &quot;play&quot; the sample at any<br />
pitch with the {{maxword|name=kslider}}.<br />
<br />
* Turn on the audio in the patcher by clicking on the {{maxword|name=ezdac~}} object. Adjust the {{maxword|name=number}} box<br />
labeled 'Dry volume' and play some of the notes on the {{maxword|name=kslider}}. You should<br />
hear the sample play at different notes.<br />
<br />
* Turn down the 'Dry volume' and turn up the next {{maxword|name=number}} box,<br />
labeled 'Lowpass volume'. Notice the change in sound. Turn the {{maxword|name=dial}} object<br />
at the top of patcher region &lt;code&gt;2&lt;/code&gt;. As you move the {{maxword|name=dial}} to a higher<br />
value, more of the high frequencies from the sample are audible.<br />
<br />
The {{maxword|name=lores~}} object implements a ''lowpass'' filter on an incoming audio<br />
signal (in our case, the output of the {{maxword|name=groove~}} object. A lowpass filter,<br />
as we saw in the tutorial introduction, passes the low frequencies and attenuates<br />
the high frequencies of the incoming signal. The two parameters that the filter<br />
takes are the ''cutoff frequency'' (specified in the middle inlet or as the<br />
first argument to the object) and the ''resonance'' (specified in the right<br />
inlet or as the second argument).<br />
<br />
The cutoff frequency of a lowpass filter determines the frequency at which the<br />
audio is attenuated 6 dB. The resonance amount, when greater than &lt;code&gt;0.&lt;/code&gt;,<br />
controls a peak of resonation (boosted frequencies) immediately below the cutoff.<br />
If we plot the response of the filter on a graph with the ''X'' axis<br />
representing frequency and the ''Y'' axis representing gain, it would look<br />
like this:<br />
<br />
[[Image:Filterchapter01e.png|border]]<br />
''A lowpass filter with and without resonance: '''A''' and '''B''' are the<br />
cutoff frequencies; '''C''' shows the resonance peak''<br />
<br />
* With the sound going, adjust the {{maxword|name=number}} box labeled 'Resonance' in patcher<br />
area &lt;code&gt;2&lt;/code&gt;. Notice how as the resonation approaches &lt;code&gt;1&lt;/code&gt; the ringing at the<br />
resonance frequency becomes very loud. Adjust the cutoff frequency with the<br />
resonance set to a high number. Notice how you can now audibly &quot;sweep&quot; the filter<br />
based on hearing the resonation.<br />
<br />
===Bandpass filters: the {{maxword|name=reson~}} object===<br />
<br />
* Turn down the volume of the lowpass filter, and look at section &lt;code&gt;3&lt;/code&gt; in the<br />
tutorial. Turn up the {{maxword|name=number}} box labeled 'Bandpass volume'. Sweep<br />
the {{maxword|name=dial}} labeled 'Center frequency' and listen to the result.<br />
<br />
Just as a lowpass filter passes low frequency, a ''bandpass'' filter passes<br />
a '''band''' of frequencies, attenuating anything lower or higher than a center<br />
frequency. The MSP {{maxword|name=reson~}} object implements a bandpass filter with three<br />
parameters (controllable as inlets or arguments): the filter's gain, the center<br />
frequency, and something called the ''Q''.<br />
<br />
* With the {{maxword|name=dial}} controlling the center frequency at 12 o'clock, click in<br />
the {{maxword|name=number}} box labeled 'Q' in patcher area &lt;code&gt;3&lt;/code&gt;. Type the number &lt;code&gt;3&lt;/code&gt;<br />
and hit return. Listen to the results. Try other positive numbers, such as &lt;code&gt;6&lt;/code&gt;,<br />
&lt;code&gt;10&lt;/code&gt;, or &lt;code&gt;0.5&lt;/code&gt;. Notice that the higher the number is, the less<br />
frequencies make it through the filter. If necessary, adjust the 'Gain' with<br />
the {{maxword|name=number}} box to the left.<br />
<br />
Q is a measure of the ''width'' of a bandpass filter, and is expressed as the<br />
ratio of the center frequency divided by the ''bandwidth'' of the filter, i.e.<br />
the distance (in Hz) between the lower and higher -6 dB points around the center<br />
frequency. Higher Q values mean narrower filters (less bandwidth relative to the<br />
center frequency):<br />
<br />
[[Image:Filterchapter01f.png|border]]<br />
A bandpass filter with Q values of &lt;code&gt;0.5&lt;/code&gt;, &lt;code&gt;1.0&lt;/code&gt;, &lt;code&gt;3.0&lt;/code&gt;, and &lt;code&gt;30.0&lt;/code&gt;, respectively.<br />
<br />
===The state-variable filter: {{maxword|name=svf~}}===<br />
<br />
* Turn down the 'Bandpass volume' and look at patcher area &lt;code&gt;4&lt;/code&gt;. Turn up<br />
the {{maxword|name=number}} box labeled 'Lowpass', adjust the 'Cutoff/Center Freq.' {{maxword|name=dial}},<br />
and set the 'Resonance' {{maxword|name=number}} box to something that sounds good to you.<br />
Now, turn down the 'Lowpass' control and raise the 'Highpass'. Notice the<br />
difference. Do the same with the &lt;link type=&quot;refpage&quot; name=&quot;number&quot;&gt;number box&lt;/link&gt;<br />
objects labeled 'Bandpass' and 'Notch'. Play with different combinations of volumes and settings.<br />
<br />
The MSP {{maxword|name=svf~}} object simulates an analogue ''state-variable'' filter.<br />
Because of the way in which filters are wired using electronic components,<br />
the difference between one type of filter and another is often simply a<br />
matter of how you wire (or where you 'tap') the circuit. A state-variable<br />
filter is a filter that allows you to 'tap' energy from several places in<br />
the filter, getting four simultaneous filters for the price of one.<br />
The {{maxword|name=svf~}} object gives you four filtered sounds: a lowpass output<br />
(which cuts frequencies above the cutoff frequency), a ''highpass'' output<br />
(which cuts frequencies ''below'' the cutoff), a bandpass output<br />
(cutting frequencies ''around'' the center frequency), and a ''notch'' output.<br />
The notch output cuts the area directly around the center frequency and should<br />
mirror the response of the equivalent bandpass filter. Notch filters are often<br />
called ''bandstop'' or ''bandreject'' filters. A plot of these possibilities<br />
shows their frequency responses:<br />
<br />
[[Image:Filterchapter01g.png|border]]<br />
The outputs of a state-variable filter: lowpass, highpass, bandpass, notch.<br />
<br />
* Play with different combinations of the filters in the tutorial, mixing<br />
them in different ways with different settings. In the next tutorial, we'll<br />
look at building more complex filter arrangements.<br />
<br />
===Summary===<br />
<br />
In digital signal processing, ''filters'' refer to equations which<br />
modify the frequency response of a signal. Filters are constructed by<br />
mixing small amounts of delayed signal with the original, smoothing or<br />
sharpening the waveform to accentuate or attenuate different frequencies.<br />
Common filter types include lowpass, highpass, bandpass, and notch. Lowpass<br />
filters can be created with the {{maxword|name=lores~}} object, bandpass filters with<br />
the {{maxword|name=reson~}} object, and all four with the {{maxword|name=svf~}} object. Filters<br />
commonly have controls for their center or cutoff frequency and their Q or<br />
resonance.<br />
<br />
===See Also===<br />
<br />
{{maxword|name=lores~}} - Resonant lowpass filter<br />
<br />
{{maxword|name=reson~}} - Resonant bandpass filter<br />
<br />
{{maxword|name=svf~}} - State-variable filter with simultaneous outputs<br />
<br />
[[Category:Teaching Material]]</div>Admin