*** MUS171 #18 03 03 Miller: @0000 So I'm going to use as my jumping off point the wonderful recirculating comb filter thing and start @0015 with one detail about Pd that you might want to know about. So here's the sound. This is the Karplus-Strong instrument. Well, @0030 not exactly the Karplus-Strong -- This is noise going into a recirculating comb filter. Now the thing that I want to do with this -- we've had enough delays now. But what I want to do is use delays as a way of @0045 motivating filters. Because indeed this is a filter you're hearing - There's white noise going in and there's this stuff coming out. And that's by virtue of the fact that from @0060 one point of view, at least, the delay network that we are putting the white noise through is filtering it. It has a different gain for different frequencies. It doesn't have a flat frequency response. It has a comb-shaped filter frequency response if you like, which is why we call @0075 this particular thing a comb filter. The comb filter is the one filter that you can explain easily without having to say anything mathematical, or excessively mathematical. @0090 The basic deal is that if you just put a single sample in here -- If you made a signal that was 0 except that it had one impulse of sample at one point, then you can imagine what would happen: The impulse would come out and then the delay later would come out a little smaller, @0105 then the delay later again would come out of the smaller and is one, and you would have a sequence of impulses at a fixed length from each other and you would hear a pitch. Or you could say what were the frequencies present in that sequence of pulses, @0120 and you would see that certain frequencies were present much, much more heavily than others were. Or you can do what I'm doing here and just throw white noise at it, and notice that something quite different from when white noise comes out. And two things that you can vary are the selectivity of the filter, @0135 that is to say there's no selectivity at all. and here's total selectivity, and here's something in between, and also the delay time is now controlling the frequencies that the filter likes. @0150 The trouble with this as a the thing is that it really only does that one thing -- that no matter what frequency you ask for it will let through that frequency and all of its multiples, thereby deserving the name comb filter. @0165 But that's not everything that you can possible want a filter to do. A very standard thing that you would like a filter to be able to do is simply attenuate higher frequencies but let lower frequencies through, or vice versa. @0180 And this not a thing that you can use in any direct way to do that kind of thing. So before I go on about how to use this way of thinking to design filters more in general, @0195 let me pop up one level and say I'm going to tell you a little about filter design but not the whole story. If you look at the textbook, the longest chapter is about filter design because there are dozens @0210 of different kinds of filter designs -- or dozens of kinds of different filters that have different design methodologies. And you would be studying for years if you want to study all of them and even just making a decent cross-section of this is a lot of work -- and @022b asically 5more stuff than we could possibly crowd in the three days of classes that remain. Even if we didn't want to mess with GEM and a couple of other things too next week, which is going to take precedence. So, I'm not going to do the whole filter design yoga. @0240 I'm just going to tell you how you think about it and also show you how to just use filters in case you don't want to get involved with the filter design yourself -- which might be most of you anyway. So, there will be theory but @0255 there's also just going to be hand-waving, "here's how we do stuff" kinds of stuff that's less honest but more useful somehow. So in preparation for that, first thing that I want to tell you is a little bit about Pd lore, which is @0270 the following thing. I mentioned a week ago that as it turns out there's a maximum pitch you can possibly get out of this thing, which corresponds to the smallest delay -- @0285 the smallest recirculating delay -- that you can possibly get, which is 64 samples, which at 44.1 kilohertz is about 1.45 milliseconds, which corresponds to the 700 and something Hertz. So the @0300 frequency -- the resonant frequency -- of this particular filter is one over the delay time. The shorter the delay time, the higher the frequency, and 1.45 milliseconds corresponds to 700 cycles per second. So that is an @0315 artificial constraint that is brought about by the fact that there's blocking. In other words, this is a thing that's easy to say and parrot and it takes a little bit of thinking to understand it. If everything is crunching samples in blocks, @0330 then this thing creates the read which has to happen before the write It doesn't look that way but this thing is reading delays before this thing is writing them because there are dark @0345 lines from here through there, but there are no dark line from here to there. So the real order of operation is delay read, multiply, add an output, delay write. The fact that you have to read a whole block @0360 of 64 samples, which by the way is only for run-time efficiency sake, dictates that if you're going to now read a bunch of stuff and then write it, you have to write it 64 samples into the future. In other words, think of a block of 64 samples now @0375 we're going to compute some other stuff we have to compute. We can't compute anything earlier than the next 64 samples than the one you just had computed when you read those. And so you're going to have the minimum, a delay of 64 samples and if you want to @0390 scoop into your own past, which is what this network wants you to do. Usually that's fine but in situations like this, sometimes you don't want that to be true. And if you don't like this @0405 and you want to fix it, then you can do the following thing, which I hope to demonstrate right now and talk for some time: You can maintain local control of block sizes by making sub-windows of patches and using a special object which is called block~ @0420 to set the block size of the sub-window. So here, what we would do is we would say "object please." Let's get ... I'm going to call it @0435 "small block." This is now a sub patch and what I'm going to do is dump some of this stuff into this sub patch. Let's do it this way. Let's dump ... @0450 Let's just grab all this stuff. Here's a receive, so I could put that in there. But this should be an inlet. We're going to make a sub patch here so let's do this. @0465 And not good. ... Cut ... Paste. @0480 So here now is the recirculating part of the delay network. I'm not sure if this is a good idea. But now, to be clearer, I'm going to put it in the order that really will be sorted in, which is to say it has to read first, @0495 and then do its stuff, and then write. The delay write is the object which formally at least doesn't have any output because its output is to write the thing into the delay line. Like DAC~, the same kind of deal. Now, we're going to want to hear the result @0510 so what I'll do is make there be an outlet – a signal-style outlet which we'll use to hear the output of whatever this thing is. @0525 And that by the way is going to create this outlet here on the containing object, and so now we're @0540 going to listen to this like this: (And meanwhile there are two inputs that we need: The recirculation gain. No, the delay time we had controlled out there, so the recirculation gain will be an inlet of the message type. @0555 And that, right here, and then meanwhile we'll have a signal to add to it, @0570 which we already had, which will be an inlet~ which we're going to add to it like that. It's better to do this. @0585 So what I did was I put the inlets in order so the signal inlet is first and then the control inlet and I did that so that you would see a clear signal chain. @0600 And then this control is going to go there. @0615 Now, let's check if we actually have the same thing as we had before, maybe. We still have the same problem; you can't get @0630 anywhere above whatever pitch that is. And now, I'll go in here: This is the sub patch, and say ... (This is why I put this all in a sub patch.) So I'll say block~. And in fact, @0645 I'm going to be extreme today and say let's have a block size of 1. If you care, which you might not yet but you will someday, @0660 this a rule of thumb: A typical amount of overhead for getting into and out of tilde objects in Pd or in other kind of block things is about 20 samples worth of crunch. That depends on the objects. So that's not a hard and fast rule. @0675 A 64-sample block size means that you are paying for about 80 samples worth of computation per 64, and one sample block size means you're paying for maybe 20-ish samples instead of one. @0690 So this thing only has about 120th of the compute efficiency of the surrounding patch. This could be a good reason not to do this just for no reason at all. But of course, if you want to do something like what I'm doing here, read something out of the delay line and then @0705 do something to it right back in, that might be something you want to do at a lower block size so that you can have a smaller delay in the loop. And now, we can check whether that actually happened. @0720 Student: So block's basically dictating how much power is going into that? Or how much computing time? Miller: Sort of. So what it really is doing is, it's saying, every time Pd wants you to compute 64 samples -- or every time your parent window @0735 wants you to compute 64 samples to be totally accurate -- instead of computing all 64 samples in one block, you will compute 64 blocks of one sample each. So what happens normally @0750 inside Pd is when you ask it to do something like this, then this, then this, it does 64 samples of this, followed by 64 samples of this, followed by 64 samples of that. And you can see this using the print~ object. Print~ will print out however many samples it does @0765 in one block's worth of computation. That's where the 64 samples come from the print~ prints out for you. If you say "block~ 1" , instead of doing 64 samples of this and 64 of that, and 64 of that, @0780 and so on, it will do one – 1 – 1 – 1 and it will go around the loop 64 times, which is a lot more work. About 20 times as much work, but is nonetheless what you have to do if you wanted to make a very short recirculating delay line. @0795 The shortest possible recirculating delay line you can have in digital land is 1 sample. In other words, there's no possible way when you're reading this thing that you can read the current sample because it hasn't been written yet. But you can read theoretically the very @0810 previous sample that got written here if the block size is as small as one. Now having done that, we're going to close this. @0825 Now that we've done that, then we get the ability to have hugely high pitches. In fact, the highest pitch @0840 you can ask for, I think, is the sample rate. Let's see if that's really true. Well, the pitch is 1 over the delay. And if the delay is one sample and the pitch is the sample rate. @0855 What does it mean for the pitch to be at the sample rate? It does not mean that there's a pitch in the sample rate because that frequency doesn't exist. There aren't any frequencies above the Nyquist. So if you like this is a nice comb filter and the comb filter has peaks @0870 at all multiples of the fixed frequency that you choose. But if you make that frequency be the sample rate, then one tooth of the comb reaches all the way from 0 to Nyquist and the next tooth of the comb reaches from Nyquist up past @0885 the sample rate and doesn't exist. So what we've done is we've taken a comb filter and turned it into a one lobe comb filter, or a one-tooth comb filter, if you like, because there's only one room for one tooth, @0900 whose center frequency, by the way, or frequencies DC, zero. So the frequencies that a comb filter allows through are zero and then the resonant frequency, which is one over the delay time, @0915 and then twice the resonant frequency, and so on. And all those frequencies there are above the Nyquist except for DC -- zero. So now what we've created is not what I just told you. @0930 So let's do it, let's turn this on and make the thing be as high as I can get it. Before I do that, let's make this thing fatter so we can look at it. So let's @0945 have an 8, a wide one. Now say just go on up to the sample rate. Actually, if it's higher than the sample rate, I know that there can't be a delay of less than one sample. So it's going to be a one-sample delay we'll have so the resonant frequency will be the @0960 sample rate which doesn't exist. Or isn't a proper frequency. So now we have noise, but here's the original noise, and here's the comb-filtered noise. @0975 OK? So I told you the frequency where the good gain is at zero. What that means is that we've designed ourselves @0990 a low-pass filter. So, a low-pass filter in some sense is a special case, a weird- special case of a comb filter where you set the frequency of the comb filter to be the sample rate. @1005 Actually 100 is not a good number to use because that's unstable. Let's go down to 99 or so. That's good. Now, @1020 at this point, we could actually graph this but I don't want to be too pedantic about things. But you could now analyze what would happen @1035 if we did something like put an impulse into this filter. So an impulse would be a signal which has one sample that's non-zero followed by a bunch of zeros and preceded by a bunch of zeros, too. So it's quiet for all time, except that @1050 some time there's maybe a unit sample, whose value is 1 with values in one of them, then silent again for all time. This is a signal which you use just for a thought experiment to see what this filter does. And what it does it very simple: @1065 So here's the design again: Each sample, we take what was there @1080 in the previous sample, ... thinking about the first sample when the impulse comes in, out here is zero because the filter is sitting at zero, it's at rest. In comes an impulse, that's to say there's one sample. @1095 So there's one sample whose value is 1. So out goes 1, and by the way 1 gets written to the delay line. 1 then comes out of here and it gets multiplied by 0.99 – what the thing is set to now. @1110 So that says 0.99 so out goes 0.99, and it gets added to 0 because the impulse is over now. So it's 1, .99, and then 0.99^2, and 0.99^3, and so on like that. So it's a falling exponential. @1125 Now that raises an interesting question. First off, I haven't told you this but an impulse is @1140 not the same thing as white noise. But an impulse, if you think about it in terms of frequency content has all frequencies present. Why? Because from one point of view, what's a frequency it doesn't have >... or from another point of view it doesn't have any time duration so it can't have any one frequency @1155 louder than any other because it doesn't know what time is. -- That's a hand-waving argument. But it actually works if we you make it rigorous. What comes out is this thing, which is sort of a lump, which has a duration which is longer or shorter, depending on @1170 how you set the coefficient of the filter. In other words, if I set this to 0.99, it will take something like a hundred samples to drop off by a factor of e and if I set it to 0.98, by the way I'm using numbers close to one so that you see a nice @1185 good exponential. So I say 0.98, then it takes 50 samples to drop off by a factor of e and so on like that. A falling exponential always has the same shape, if you like, except that it's getting squashed or stretched out in frequency, depending on the coefficient. @1200 And furthermore, if you think about that, the slower you play that exponential, that's to say, the closer you get the coefficient to 1, or the longer that so-called impulse response lasted, the more low frequencies you would have compared to high frequencies. @1215 Because the slower you'd be playing the thing, the more lows you have -- Slow something down you get more lows. (That also is a hand-waving argument.) So, in some sense, you shouldn't be surprised at the fact just from that description of what the impulse response is ... @1230 You shouldn't be surprised at the idea that as you push the gain toward one, the thing gradually loses its high frequencies or picks up low frequencies compared to @1245 high frequencies. You could ask for a better one @1260 or you can also ask for other stuff. But to talk about that, I have to talk about how we talk about filters a little bit. So the trajectory so far has been I started with this recirculating comb filter and I showed you the block~ object @1275 that allows it to have one that's just 1 sample. And then I showed you that hey presto what we really have is a low-pass filter. @1290 So let me now go to silly picture land and show you how I'm talking about these things. Student: Can I ask a question? Miller: Yeah Student: So I think it's now easy for me in my experiences with filters, @1305 they always seem to be things that add or subtract to the signal, like to any one sample in place. I don't know quite how to describe it, but what @1320 you're showing is takes what happens in one sample and then seems to add information to the subsequent samples because it's got a delay. Is that the way that all filters work? Miller: It is. Student: @1335 So it's actually ... when you filter something, you can low pass filter something you're actually ... Miller: You're making it last longer. Yep. In some sense. In other words, if you had a very, very short sound or utterance, and put it through @1350 a filter almost of any sort, you end up with something longer than you started with. An extreme example is if you've messed around with an analog synth -- Try putting something impulsive into a band pass filter and set the Q way up. @1365 (I'll tell you guys about what that stuff is later.) And then you can hear it ring, so you can put in just an impulse, and out comes Ping! Like that, and you can make it last longer, depending on how high you set the Q. The thing resonates -- rings. And filters in general @1380 are things that ring or sit there, whatever you call it. Usually, for most reasonable settings of the filter, what it does –- the impulse response of the filter is short enough and time it that it @1395 doesn't become a factor. But you can set yourself up in situations where it indeed is a factor. I can show you an example of that maybe later on. With luck. So here's @1410 just how one talks about filters. And this is just terminology. I haven't shown you actually how to make it into stuff except for that low-pass filter, but I haven't even really analyzed that in depth, yet. @1425 But these are just sort of qualitative terms that sometimes have units on them. But here's what a low-pass filter is, as you describe it to an audio engineer. Usually what you say is there is a particular ... @1440 So go to the store and buy a filter ... They'll say, "What cut-off frequency do you want?" That is an oversimplification of what a filter really is because no physical filter ever will allow some frequencies through, and then @1455 completely block out other frequencies, and just basically have just one frequency, which is a cut-off frequency. But there really is, in most people's way of describing it, a range over which a filter gets from its pass band to its stop band. So the bands are just @1470 ranges of frequencies. That is old fashioned radio talk. And so a low-pass filter is the one that has a pass-band and a stop-band, and then there's a transition band, which is where you don't know what the filter is doing. It is somewhere between the two. @1485 And then you can talk about the quality of the filter in terms of ... "Give me a filter and I want the transition band to be real skinny," or ... "I want the" ... other terms ... "ripple" ..." You want the thing to ideally have an absolutely flat frequency response in the pass-band,@1500 but it doesn't ever really in practice. It always goes up and down. Anything that goes up and down, if you're an economist or an engineer looking at a function and it has maxima and a minima, you call it "ripple." Or sometimes you call it cycles, even if it's not. @1515 So engineers will call this "ripple." It's just the fact that in any real filter, the frequency response will go up and down slightly, at least slightly, before it starts heading out in the transition band. And then in the stop band you can say "What is the @1530 stop band attenuation?" That is to say this isn't ripple anymore, this is just stuff that still gets through in the stop-band; it isn't called "ripple." You don't care about there being a flat frequency response there; you just care for it to be gone. And so all you care about is what's the maximum value @1545 here compared to the value here, whatever you call that. So there's a stop band attenuation. And these things are all trading off against each other and off the complexity of the filter. You don't want to have arbitrarily @1560 complex filters, partly because they will ring forever. The amount of time the filter rings very roughly speaking is 1 over the transition bandwidth. So if you want a very clean transition band to have a very @1575 ringy filter. So you will typically trade, you will care more about this and less about that. Or maybe you will care a whole lot about this like if you're designing a low-pass filter for a digital to analog converter, @1590 you will care about having a nice flat frequency response there. Or you might care about having this thing very low. Or not, depending on what you need. So you make those things part of the specification of your filter and some poor engineer runs off and ... well, actually @1605 cranks up some piece of code that designs a nice filter that does this for you. And hopefully it's a decently simple filter and not a complicated one. Not so much because you care about the computation time, but because you care about things like numerical accuracy, which @1620 tends to be more difficult to control as the filter gets more complicated. So there's language -- which one uses to talk about low-pass, and in fact high-pass filters. A high-pass filter is the same thing as this, except that the pass band @1635 is up here and the stop band is down there. And other stuff: Next. How to talk about band-pass filters: Here's a @1650 picture of what you might think of as a band-pass filter specification. So there you have two different stop-bands. You want it to stop stuff below and above the region you're interested in. There's, of course, because @1665 in reality we have transition band – which we don't know about – That's where the filters get in from the stop to the pass-band. And then there's ripple again. So a band-pass filter is like a low or high-pass filter, except that the pass-band has both a low and a high frequency @1680 cut-off. And it's correspondingly harder to design. And a stop-band is the same as the pass band, except that there is a stop-band in the middle and there are pass-bands on the outside. And then you call it a "stop band," or sometimes a "notch filter." @1695 Student: So essentially graphic equalizers and the bunch of band-pass? Miller: It's worse. Graphic equalizers, you want them to be absolutely flat when you have all @1710 the sliders in the middle. You will never be able to design these so that you can add them up and get exactly flat, and say end up designing a completely different class of filters to use in an equalizer, which I will show you @1725 in a second. So that's terminology for that. And now, the stupid terminology for band-pass, this is if you buy an analog synthesizer, you don't talk about the @1740 pass-band any more. What you talk about is the "center frequency," which is the middle of the pass-band and the pass-band itself is kind of ugly. I mean you could describe this filter in terms of two transition regions and all the rest of it, but you don't. @1755 What you really describe a simple band-pass filter as is as having a center frequency and a bandwidth. So the band is just the part of it where you think the thing is allowing the signal through, @1770 and the band width, in this kind of a filter, typically is measured by saying, "Find the peak and then choose some arbitrary number, which is usually three." Then you say, "go to the right until the thing drops three decibels. " "Now go to the left" @1785 ... sorry, whatever the left or right are ... "Then go the other way until it drops three decibels." And then you will see a region of the thing which is characterized by the fact that it's within three decibels of its peak. And that's a way of just talking about bandwidth @1800 of a filter, if no one has specified a ripple value or what-not. And so then, basically, for describing a filter like that, it's adequate to describe just the center frequency and bandwidth. And sometimes @1815 people call this the "3 dB bandwidth" to say that we chose that arbitrary number 3 to talk about it. There's another @1830 knob that you get on a synth, which is called a Q – which stands for "Quality." And the Q of a filter is a thing which is designed so that as you increase the value of Q, the filter itself gets sharper. @1845 I can't tell you in any very simple way why that would be a measured, the quality of the filter, so don't worry about that. The quality is then defined @1860 so it should go up as the bandwidth goes down and the textbook definition of the Q of the filter is it's the center frequency divided by the bandwidth. And that's a good unit to use @1875 because if you're designing -- for instance for analog synthesizer or another kind of application like that -- if you're designing a filter, that you would want to change the center of frequency of, @1890 it might actually be a good thing for the bandwidth to be maintained as a fraction of the center frequency, instead of being maintained as a constant. You could imagine them both, you could imagine a filter that sweeps the bandwidth, stays the same. @1905 But then if you think about it, that filter would sound more selective if you tuned it up into high frequencies than in the low. If the bandwidth is 50 Hertz, and if you say that the center frequency of a 100, that's a very fat filter but if the bandwidth is 50 @1920 and you say the center frequency is going to be a thousand, then 50/1000 is a very small variation, and then you hear it is a very sharp pitch. To put that another way, if you wanted a filter whose bandwidth was one @1935 half-tone ... That would be a reasonable thing to ask for if that would be a filter that was sharp enough that you would hear as a pitch basically, to a pair of Western ears. So if you want the filter to sound like middle C, you'd like its 3 dB points to be @1950 halfway from C to C-sharp, and halfway from C down to B. That would be a C filter. That turns out to be a Q of 17. That's to say a half-tone is a 6% @1965 increase in frequency or change in frequency. And 1/6% is about 17. So middle C over whatever middle C has to change by when you get to the next one over is about 17. And that's true @1980 if you chose middle C or any other pitch on the piano. It's always going to be true that proportionally to one part in 17 gets you to the cracks between you and the next two keys. So Q = 17 is a @1995 one half-tone wide filter. So if you make the controls on your filter be center frequency Q just what the synth manufacturers typically do, then it's good you can set the thing to a higher or lower center frequency that has the @2010 same perceived width, which is the width as a percentage of the center frequency. Another example of a useful value of Q is what if you set the filter to be about a critical band's width, @2025 or a critical band wide? "Critical bands" are these psychoacoustic things, which are typified roughly ... They're things you learned about @2040 in Music 170 that I don't want to try to explain because then you'd be talking psychoacoustics and then you'd get into arguments because no one can really make measurements about psychoacoustics. ... But a critical band is roughly a third of an octave. And the reason @2055 you see all these third-octave filter banks and, by the way, if you go buy an equalizer, then it will be third-octave, right? That third-octave is the critical band. A third of an octave is, again, a number of half-tones, @2070 four half-tones. And so that corresponds to a Q of something like four-ish. So a Q of four is about a third of an octave -- Still, no matter the center frequency you choose. So those @2085 are reasonable values of Q. Having told you all that, that's all I want to, tell you about taxonomy of filters. I'm going to tell you one other thing, which is to answer your question better about @2100 equalizers: There are other filters running aroud besides low-pass and bandpass, which are filters where you specify not that it be 1 in the good part and 0 in the bad part, but that it simply have a higher @2115 gain in one frequency range than in another. The simplest of these is called a "shelving filter." For a shelving filter, you say, "what's going to be the frequency at which it transits the transitions?" It's "transition @2130 frequency." And then you say, "What do you want the gain to be at low frequencies? What do you want the gain to be at higher frequencies? And roughly what frequency does it make its transition between the two?" And if you have one of those, then you've got something you can use to boost or cut @2145 the bass or to boost or cut the treble, depending on where you set the transition frequency. So those are things like the treble and bass controls on old fashioned stereo amplifiers -- maybe they still make those. Or the low and high shelving @2160 filters on your equalizers. -- whether the equalizer, by the way, is a parametric one or a graphic one. Then you need all the filters in between. To do that, you have an @2175 out of band gain and an in band gain. So that if you set the in band and out of band gains both to be 1, then the filter will be nothing for you. But then you ask i6 "Make the out of band always be 1," which is an appropriate thing to do, but "Make the in band gain @2190 be +5 decibels" or "-5 decibels" -- which would mean push or attenuate this particular frequency band. And there the things you would specify would be "where's the center frequency>" and "what's the bandwidth?" which is to say "over what range of frequencies @2205 are we going to push it up or down?" And those are things that you've all seen because they're on any parametric equalizer. That's not the same thing as the band-pass filter on your synthesizer. So for some reasons, synthesizer @2220 manufacturers love the band-pass filters whereas mixer manufacturers love the shelving and peaking filters. This is called a "peaking filter" because it makes you a peak. They call them "peaking" filters, that's the word. @2235 The typical mixer thing is you've got a shelving filter for the highs and shelving filter for the lows and two usually peaking filters for pushing or pulling away from some frequency range in the middle. -- So that's how people @2250 talk about filters. Student: Do these also work with delays? Miller: Yeah. So all of these things are things that in digital land -- @2265 in analog there's a whole different way of thinking about them -- but in digital land these are things that are made with delay networks, in which the delay time is always one sample. And as a result, they're horribly inefficient to make as patches because you have to set the block size down to 1. @2280 So the only time that you make one of these in a patch is if you needed some special weird nonlinear filter thing that you couldn't build out of the building blocks that you already have that someone else coded up in C for you – Which you can do, and which I have done ... I had @2295 to do just last Fall one time. But usually, you can get by with the filters that pre-exist. And usually, of course, the reason that people code of these filters up is because it's horribly inefficient @2310 to make patches that make these filters -- because of the block size. Now the next reason you don't do these things themselves is because the math gets genuinely complicated to make these things. The basic deal about making low-pass, high-pass, @2325 and band-pass, and peaking and shelving filters is not so bad. And Chapter 8, goes a certain distance into that. But then when you start getting into" make it just so" kinds of things, then pages and pages @2340 of math or huge software packages to do the design. So I want to give you some idea of the theoretical framework in which that is done, but not really go down that even as far as Chapter 8 does, for the lack of adequate time. @2355 What I'm going to do is I'm going to haul out some existing filters from Pd to show you what they do and then I'll try to go back and explain what's happening on the inside. So what we'll do is @2370 we'll trace our steps backwards because what I did to start today off was I started with the comb filter and showed you how to make the simplest possible low-pass filter out of it. Now what I want to do is just grab some filters and start seeing what they do, and then try to justify how you would build them by how @2385 they act. And then I will show you some actual math in the complex plane, and then you will all fall asleep, and then I will see you again next Tuesday. Let's see if we can do this. Filters: ... @2400 So we're now going to say patch #4. <> @2415 So I'll just get some filters out. And maybe it's just as well to have .. this is just an all-purpose input @2430 generator thing; we'll leave that and we'll just start messing with filters and see what they do. (I have to get rid of this, and I'm going to get rid of @2445 "pd small-block" ... And I'm just going to start hauling some of these out. So there's nice low-pass filter. Let's get ourselves something just to hear the original sound, in case I will need to A/B it. @2460 We got that going; so we've got white noise; good. So the low-pass filter... you can get an argument which is the cut-off @2475 frequency in Hertz. Or, what's maybe better here is ... we'll get one of these things. Let's get this thing. So to prevent confusion now, I'm going to get rid of this. @2490 And now we just have low-pass filter. And while we're at it, let's get two more of these. @2505 How's that? @2520 So then we'll get a nice simple high-pass filter and a nice band-pass filter. Band-pass filter, @2535 as I mentioned, has two things that you might want to control, which is the center frequency and a Q. "Q" for quality. And so what I'm going to do is get a nice thing that I will constrain to be positive ... @2550 and have that be the quality. There's that: [white noise] Low-pass: This is what I showed you before. @2565 There's noise. And now we turn the cut-off frequency down and you hear a drop off in the highs. This is not exactly @2580 the filter I built you before because it's normalized differently. This one is normalized so that it has unit gain at zero frequency, or DC. Whereas the thing that I showed you before, the recirculating comb filter, it might @2595 have a very nice high gain at DC (Imagine feeding that thing all 1's, but if it has 0.99 feedback, what's going to come out is much larger than one. I think it will be a 100.) So you could divide by that number that it would put out. And then you would get @2610 something that puts out the same amount of DC as you put in. But of course it puts out less of everything else, because it's a low-pass filter. So then you get that effect. [sound of white noise through low-pass filter] A thing about this @2625 which I will go into a little bit more later maybe, is that this is a control, that's to say a message, input. And so I wouldn't be able to take a nice line~ until kind of envelope generator @2640 and throw it in there and get the right output. To do that, you'd have to go somewhere else, get a different filter. But these are optimized to be computationally very inexpensive and simple. @2655 This one is the high-pass filter whose job is to do the opposite. So the higher you push this, @2670 the less low frequency stuff you have. It's not general true but in this @2685 particular case it is true that the high-pass is exactly what you would get if you subtracted the low-pass from the original signal. Actually, there's a numerical accuracy issue that I'm @2700 covering up. -- You wouldn't actually be implement that way for numerical reasons but in fact conceptually this is just input minus that. That is no longer true when you get to any more interesting filter than just this very @2715 simplest one. Band-pass filter: This is the one that you buy on your synthesizer. You decide a value of Q. So the number 17 came up ... so I'll say "Set your Q to 17 please and @2730 the center frequency of 69." And then we hear A. I hope that's A. Anyway, if I push this up or down, you just get pitches out. @2745 So a Q of 17 is half-step wide. A nice sharp filter might be a Q of a hundred. That's asking right now the ... let's see ... go back to 69, @2760 which is A so if the center frequency is 440 and the Q is 100, that's to say that the bandwidth is 4.4 Hertz. The bandwidth being 4.4 Hertz you can also think of as the fact that @2775 there is a ... (You can hear that the thing's changing; it's not a sinusoid. It's tumbling or fluctuating. The speed of fluctuation of this amplitude is roughly @2790 4.4 Hertz. That's to say it's roughly the bandwidth of the filter.) So if you don't want the thing to sound like it's fluctuating, you would send this Q up to something much higher. But, of course, @2805 the less stuff you let through, the less power you will hear if you put white noise or something like that in. So now, why don't we just take this and multiply it by @2820 791 so that you will pick back up the gain that we lost? Watch yourself when you're doing this, but let's turn this down first. Now let me show you how to normalize this @2835 nicely for white noise. Actually, there are several ways you could think of to do this. What I'm going to do is, I'm going to take this number, and add one to it, and then multiply that by the filtered sound. @2850 Let's start with a Q of 1 so that @2865 nothing silly happens. Right: Q of 1. It's basically an octave wide. @2880 So in other words, if the center of frequency is 440, so is the bandwidth, and so it reaches from 220 to maybe maybe 660. I told you a quarter-octave @2895 here is about a critical band's worth of noise. Now we're kind of in kind of Frank Zappa "Nanook of the North" land ... Here's the half-tone filter: -- @2910 And here's the very sharp filter: -- This is super sharp: And now we're making pitches out of noise. @2925 While we're here ... notice that this filter rings ... In fact, I have told you how to make an impulse, have I? @2940 What's a good way to make an impulse? Audience: Couldn't you just use tabread~ and an array? Miller: Oh! -- That's probably better than what I was going to do. Let's do that. Let's make ourselves a nice impulse. @2955 So we're going to make ourselves a nice table.... I'm going to @2970 save some time and say "table" and give it a name and a size. I don't know... << table foo 10 >> And then I'm going to say a message: "semicolon foo start at @2985 location 0 and we're going to be 1 and then all 0's". There's an impulse: It doesn't look like an impulse because it's drawn using segments instead of @3000 lines; but the first number is 1 and the rest of the numbers are 0. And then we can say "tabplay~" -- This is the simplest, stupidest possible way to play a table back. @3015 This one you just bang it and out comes the table. And then you have an impulse generator. Cool. Now let's stick this in my little adder so that we can see what it does to these various filters. @3030 Here it is: So now the center frequency of the filter is @3045 just the frequency that we hear. And furthermore, this Q or "quality" of the filter ... (Oh, that was a thousand... Sorry -- you can't see that.) I'll make it a hundred now. [sound] @3060 Or I'll make it 17, which is the half-tone filter.[sound] This controls directly the length of ringing of the filter. In fact, @3075 you can quantify that: In another way of thinking, the Q describes the number of times the filter @3090 rings before it drops down to a factor of the e in amplitude. Why e? Just because life's that way. So that means, by the way, that the higher the frequency I give the filter, the @3105 shorter the ringing will be, because it rings a certain number of cycles. It will ring now a thousand cycles as opposed to a thousand milliseconds or something. So the higher one -- a the thousand cycles up there doesn't last as long as the thousand cycles down here say. @3120 So Q is the length of ringing of the filters in cycles. Or Q is the frequency divided by the bandwidth ... @3135 Frequency divided by bandwidth, which is the sharpness. Student: @3150 So Q is also like the width of the peak? Miller: Yeah. So the higher the Q is the narrow the peak is. Q is the "narrowness" of the peak. @3165 But it's the narrowness of the peak compared to the center of frequency. So if you push the center of frequency out, the peak will get fatter, too, for a fixed Q. ... @3180 And now that I've told you this, you know almost exactly how to build this band-pass filter: Because all you would have to do is arrange to make some kind of a delay network that rings sinusoidally -- @3195 when you hit it with an impulse. And then you have a band-pass filter because you have what I have here, which is a band-pass filter. That's not very good mathematics. ... Another way of thinking about filters: @3210 filters are resonant bodies. They're masses on springs. If you like, they're bodies of air inside resonating bodies, which have resonant frequencies like Helmholtz resonators do, or whatever you might wish to make resonate. @3225 You can think of them as masses on springs. So to make a mass on a spring, you would make something that when you hit it, acts like a sinusoid that's damped. And now I can tell you why they call it "quality." If you @3240 think of it as a mass on a spring ... as I've told you, the lower the Q is the faster the thing is damped; or the higher the Q is, the longer it vibrates. The quality is in fact the percentage @3255 of the energy of the filter it maintains all over a cycle, or is related to that -- It's not equal to that but it goes up with that. In other words, the leakier the filter is, the more resistance you have in the thing and the more damped it is: The lower the "quality" that it circulates @3270 in some sense. That's why it's Q. So how do you build this? Well, remember I was telling you about complex numbers last time. You were hoping I wouldn't get into that... @3285 How would you make something act like a sinusoid? I told you that sinusoid is nothing but something that's getting multiplied by a constant. But because the constant is a complex number that's on the unit circle, say, the thing is going around a circle, @3300 instead of dropping towards zero. The low-pass filter that I showed you that was the comb filter that had a delay of 1, the trick was you took whatever the previous sample was and multiplied it by 0.99 say, and put it back in. @3315 And that gives you a very nice low-pass filter; it gives you a thing which when you give it an impulse, give you an exponentially dying response. If instead of multiplying it by a real number, like 0.99, you multiplied it by a complex number, @3330 that had a modulus or an amplitude or absolute values slightly less than 1, but also had an angle to it so that it wasn't real, then every time you multiplied it in, it would continue to @3345 spiral around the origin. And in fact would spiral into it, assuming that you made the gain, that's to say the absolute value of complex number, less than 1 -- Which you really ought to do; otherwise it would be unstable. So if you wanted the filter to ring forever, @3360 that's the easy thing to design: You just choose any complex number on the unit circle and just multiply the previous sample by that, and by gum, they will just go around the unit circle forever. In fact, that's so good that you can use that for an oscillator. And @3375 Max Matthews spent a year building oscillators out of this concept ... it was really cool. So here's how you do it: (So this is the menagerie. Let's lose that, and @3390 I'll open the previous patch again, and I'll save it as number five, delay circulating complex. <> @3405 [...] @3420 [...](I have to do it again, I'm sorry.@3435 [...] ... Did I lose everything? So let's close this. What I'll do is I'll make a nice subpatch; then I will put the delay recirculating hoohah into this subpatch like this. And then I'll clean it up like this. We're being sloppy and unfortunate here ...) @3450 [...] [...] @3465 [...]And then I had a nice @3480 inlet~ ... And that was going to get added to it ... that changes now. And then we have an outlet that allowed us @3495 to listen to it.[...] @3510 Here we're going to put this stuff in here. And then we're going to listen to the output, like this. @3525 [...]There it is; there, roughly speaking, is what we had before. Now what we're going to do is we're going to take this @3540 thing and, instead of multiplying it by real number, we'll multiply this by a complex number. (This is Algebra 2 or maybe pre-Calculus.) So complex numbers have a @3555 real part and an imaginary part. So let's say "delay-real". [...] @3570 I'm going to tell it to write a delay time of zero. ... the delread~ should say something, I'll say half a millisecond. @3585 But I didn't give it anything to the delread~ -- There's no input there, which means "Read the shortest possible delay that you can read, which is one sample." Oh! That's assuming I remember to do this: @3600 "block~1" Now, we'll do the same thing for the imaginary part. We'll have a nice delay for it. @3615 So what that means is we'll do another delread~ and another delwrite~. It will fill the whole screen very soon here... And this will be the imaginary part. @3630 Same thing with the delwrite~ ... And I'll say, "You have a millisecond too, but we'll only use one sample's worth." So we'll eventually take the inlet and add it to this. @3645 But the multiplication step is going to be interesting: So to multiply complex numbers ... So first off, we do an inlet to have the complex number come in. And that inlet @3660 is going to have two components. So let's just say inlet here and inlet there. (Those could be signals or they could be @3675 control values. I'll just say control for right now.) And now, to do a complex multiply, you multiply the real part by the real part. And you multiply the imaginary part by the imaginary part. @3690 And what do you do to these two numbers? Does anyone remember? -- @3705 You add them backwards: You subtract them. The reason you subtract them is because i X i should be -1 -- because that's what it is, -1. So you @3720 take the real times the real minus the imaginary times the imaginary -- and that's the real part of the product. The imaginary part of the product -- ... (See I've done this a few times, I know what I'm going to have to do ...) is you take the real part of one of them, @3735 and the imaginary part of the other -- that's imaginary. And you also take the imaginary part of one and the real part of the other -- and that's imaginary. And by the way, if I didn't do this exactly right, @3750 this is going to go unstable and blow up. So don't make a mistake when you're doing this. Actually I should say it differently: "Turn the volume down when you make networks like this -- until you really believe they work." We're going to say "save." ... And, since @3765 Cooper was kind enough to introduce the expr object, I'm going to use an expression to compute what the complex number is going to be. @3780 What I want to do is specify an angle and a magnitude. So, just for talking, I'll call the magnitude "R" and the angle "theta." So the real part of the complex numbers is going to be @3795 R cosine theta. So "f1" the first one will be R, and the second one will be theta. @3810 And then the imaginary part of this complex number will be R sin theta. And what's R going to be? R can be anything that you want, except that it sure better be less than 1. So I'm going to do one of @3825 these things, and I'm going to restrict this to only go up to 100 -- We'll allow ourselves to actually have the thing right on the unit circle. @3840 That's R. Now theta should be the frequency ... So how do you figure out what theta is, the angle of the thing? A simple way of thinking is: the sample rate means go all @3855 the way around the circle every sample, so that you stay in one place. So you take the frequency that you want, and if the frequency were the sample rate you would want 2 pi, which is all the way around. So you take the frequency and multiply by (2 pi @3870 divided by the sample rate.) And I will just do that without saying much about it. I'm too lazy to compute 2 pi to more than 4 places in my head. ... @3885 Then we'll divide by 44,100 which is our sample rate. And that will now be theta. (By the way it would be good to see this just to make sure we're doing it right.) And furthermore, it would be nice if we change this @3900 that we recompute both the expr's so we should use a trigger to tell the expr's to recompute when they get these. And furthermore, it would be really good now to look at those numbers. @3915 There's the real part. And here's the imaginary part. So what I've done in very simple terms is ... Let's turn this off, choose a gain of @3930 1/2 to start with ... -- I've made something that does ... nothing ?! What did I do wrong? Audience: You're sending that trigger output instead of the expr ... Miller: Thank you. Hoo-hoo, boy! @3945 Dig! There are people who are not asleep yet. [laughter] Miller: And is it working? It sort of looks like it's ... Right -- this is good. So now, if I tell it: "Your frequency's close to 0," basically the real part is the 1/2. @3960 I've made the magnitude 1/2 so that it wouldn't blow up for now. And I'm just seeing if we go around the unit circle decently well. So for frequency 0, we should see a real part of 1/2 and an imaginary part of nothing. If I tell it "Nyquist" it should go halfway around the circle and be -.50 . @3975 Oh where's Nyquist? -- Nyquist is go down here and say 22050. And a half of Nyquist is pure imaginary. (That's a small number which @3990 isn't 0. So it said "+" because it couldn't write it out in exponential notation. That's kind of bad ...) ... So, anyway, basically as I start increasing the frequency, it starts @4005 wending its way around the circle with radius 1/2. And now if we listen to that: Let's put noise through it -- @4020 Less than convincing, huh? But of course this is a high value of Q ... So push it close to the unit circle now -- and we've got a band-pass filter! Now that was a @4035 hand-wavy kind of band-pass filter design job. But the punch line is: The center frequency of the band-pass filter is nothing but the angle, or "argument", of a complex number that you use to @4050 multiply inside the looping comb filter. As a result of which, if I gave this an impulse ... Where did I put my impulse? That was in that previous window ... Let's "save as". ... @4065 So let me go back and grab the impulse generator. ... @4080 I'm too lazy to make that again ... @4095 If I put an impulse into this you would hear the thing ring -- You would have to because in fact I designed it to be something that rings when you send an impulse into it. I designed this band-pass filter basically by imitating the behavior of the band-pass filter that we observed @4110 when we just put an impulse in it. -- And that behavior was that it rang. So here's a thing that rings and when we put noise in then ... This recirculation gain controls how long it rings; And @4125 furthermore, let's turn this off for a second... Let's send the recirculating gain all the way up to 1. Careful now ... I'll just put in a little noise and then stop it -- And tada! We now you now have a @4140 nice oscillator -- which is ringing 40 Hertz but I could change that now if I wanted to. It hates me for some reason ... And throwing white noise in changes @4155 how loud it gets ... Something's wrong. Something's not working real-time. I'm abusing it in some way here, probably with the recirculation. So there is a @4170 recirculating gain that's flat on. That's to say the Q of infinity. Or if I want to make the recirculating gain less than one ... maybe .99 ... @4185 That's not close enough to 1 to let you hear it ring, is it? .. But if made it real close to one – @4200 Let's make it 99.99 – Now I've got this: It's a nice, very high Q, (It's a Q of 10,000, I think. ) -- a high Q resonating band-pass filter, @4215 also known as an oscillator. Of sorts. That's the basic yoga of designing filters. @4230 ... What questions do you have about this just right now? I should show you the internals again ... Audience: If you make the delay @4245 too small will the system crash? Miller: It will make it the smallest delay it can pull off, which is 1 sample. Or actually it's 1 block @4260 and since I've set the block size to 1 sample, in this case it's 1 sample. @4275 ... Well, it's 1 sample so it's 22 microseconds. That's one way to think of it. You wouldn't be able to get the computer's audio latency down that low at all. A typical computer audio latency might be 10 milliseconds or something. @4290 ... It just wouldn't be able to do it -- I mean, where's @4305 it going to get its number; there's no place to look. So either it does nothing, or else it does something arbitrary -- which could be crash, I don't know. Miller: The typical design style @4320 of Pd is if you ask it for something out of bounds, it just gives you the thing within bounds which is closest to what you asked for. @4335 So what's happening here is we have a complex number, which we're representing as the real and imaginary part -- as separate real numbers. So we're using two delay lines to manage that @4350 pair of numbers which are the two axes or two "coordinates" of a complex number if you like. And each time through the delay -- every sample -- what we do is of course we add the inlet~ in and we add it as if it were a real number -- which is to say we add it only to the real part. @4365 And meanwhile, we take the previous sample and multiply it by a complex number, which is coming in these two inlets. So this is a complex multiplication here. And that number that's coming in, we wanted to specify in @4380 polar co-ordinates -- that is to say specify as an absolute value and an "argument" or angle. Audience: Why is the outlet only connected to the real part? Miller: @4395 In other words, why are we only listening to the real part? That's a real good question. We can listen to that, or the imaginary part. A trouble with this whole @4410 discussion is that I've been pretending that you can listen to complex valued signals – which, of course, there's no way you can do -- because air pressure is a real number. But you could, if you wanted to, @4425 just listen to the imaginary part of it as if it were a real number. And you would get, as it turns out, you would get a slightly different filter, for technical reasons. It's not hugely different. ... So instead of getting this; @4440 let's make some reasonable number ... So there is the real part and here is the imaginary part: It turns out that the real part @4455 has all the highs in it and the imaginary part doesn't. To put it another way, this is a band-pass filter and this is a low-pass filter, but they're both resonant. So you actually have most of what the old Moog VCF gave you. Audience: @4470 Can we hear what the low-pass filter sounds like on the complex side? Miller: ... Yeah. Now let's see. So here's this ... @4485 not really different ... yeah, kind of different. So that's the true band-pass there, I think. I'm sorry, this is low-pass, this is true band-pass. Audience:@4500 Can we hear it sweep? Miller: The frequency? Oh, this thing, right? @4515 As opposed to this. That's interesting. @4530 The high frequencies are getting masked up there. Sounds like they're losing energy. But I don't think they are really. Audience: Can we hear them both together? Yeah ... @4545 I don't know what that would give you but ... Of course maybe it's a little louder ... it's just something in between. @4560 So I'll grab the picture of the complex plane next time and show you what this looks like in the complex plane @4575 in slightly more detail. And then we'll just get off into applications of filters. ... So that's it for today.