This might have all sounded a little bit dry so far, so let's become much more concrete. So before delving into the mathematics of signal processing, we are going to construct a simple motivating example. So a way to do this, is we are going to look at simple operators, like sums and multiplications, and the elements that we're going to build together to build, for example, a moving average or a recursive filter. So recursive filter, it turns out, is exactly what happens into your bank account as you only need to have some money left. After we have these simple operators, we are going to build a music synthesizer based on the corpus strong algorithm and actually going to listen to some computer music. Before delving into the mathematics of signal processing, let us do a simple and motivational exam. We will see that there are simple primitives that can be used to build interesting signal processing devices. After building up the basic blocks, based on usual notions like averages, moving average, and bank account returns, yes indeed we shall construct a simple music synthesizer know as the Karplus-Strong Algorithm, and then listen to it. The menu is therefore the following. First, we look at digital signal processing as Lego blocks. So we'll see fundamental building blocks and how to put them together. From there we go to moving averages, which is an extension of the usual averages that we all know. Then we shall look at recursion, and the best way to learn about it, is to revisit your bank account and how it wells goes up and down depending on returns. With this example in hand, we can build a simple recursive synthesizer. Once built, we can actually listen to actual sounds. Okay. So, let's think as digital signal processing as a Lego set. So we have blocks, various colors, various shapes, but they all fit together as seen on the left side. On the right side, you see a block diagram of a basic signal processing device. This will turn out to be a filter, but this you'll see later. You can see there are blocks, there are arrows, there are adders, there are multipliers, and so on. And in input x[n], a sequence of numbers gets transformed in to y[n], another sequence of numbers. So, what is a basic building block like an adder? It takes two signals, two sequences, x and y absent together x + y. In the diagrammatic forms, we see two signals at the bottom left, added together they add to a constant, because one goes down linearly, the other one grows linearly. How about the multiplier? It is denoted simply by variable, in this case alpha, that is put next to an arrow. So X gets transformed into alpha times X. Again, an example. We have the same descending signal multiplied by one half. It has the same shape but it is scaled by one half. So delay is denoted by Z minus 1. We will see why is this notation shows up later but for now simply think that a sequence XN is shifted in time. Shifted to the right, therefore it is denoted as X of N minus 1. Again, we take our usual signal, the descending linear signal, and shift it by one. Sure enough, instead of starting at the origin, it will start at time instant number one. If we know how to delay by one, we can certainly also delay by N. This is denoted by x[n] becoming x[n- N]. Let us look at our usual signal and delayed by an integer N is equal to 4. Now, instead of starting at the origin, it will start at the integer N is equal to 4. No that we have building blocks let's create some operators. So, first operator that we shall look at is the average. Or is a simple average that everybody is familiar with. For example in Switzerland, the average number of children per woman is 1.42. You probably have to worry about the famous infamous GPA, Grade point average. Here we are concerned about moving averages. That these we compute the local average of a sequence as we go along the simple case is 2 point moving average denoted by XN plus Xn minus one divided my two so we take two neighboring samples of the sequence and we take their average which now will changed over time as it depends on end. We can build this using the Lego blocks from earlier. So on the left we have the input Xn. It is delayed by Z minus one. It is added and then multiplied by one half to result in the moving average Y N is equal to X N plus X N minus one Is the sum divided by two. Let's look at this. For a very simple signal, this is the delta sequence, which is equal to one. That's the origin. Zero everywhere else. So moving average will be zero everywhere except at the origin and at location one, where it is equal to one half. Another typical signal is the step sequence, which is zero for negative time, equal to 1 for n is equal to zero to infinity, denoted by un. What will the moving average look like? For negative indices, it will be zero. For 0 it will be one-half, because it's the average of 0 and 1. For 1 it is the average of 0 and 1, so it is equal to 1. And ever after it is equal to the constant 1. If we take a more complex signal, like a cosine function, cosine omega of n, where omega is picked here as pi over 10. Then, you can see the signal on the left, and its average on the right. It doesn't seem to have changed very much. If you look carefully, you will see that the 0 crossing at n is equal to 5 has disappeared, because of the moving average. But, the basic frequency, as we shall discover, is actually still present. It is pi over ten. Now, if we take a very high frequency, omega is equal to pi. So, cosine of omega times n or cosine of pi times n. The sequence is alternating between plus one and minus one as you can see on the left side. If we take the average, nothing comes out. Because every time you take an average, it's the average between plus and minus one, which is zero. Therefore, here we have a very different behavior from the previous cause line, thinks an input that is different from zero is resulting in an output that is exactly equal to zero. Now, a natural question will be what if we reverse the loop of the moving average? So, let's look at the block diagram again, and turn around the arrow instead of going forward, going backwards still is a factor alpha and an other. This turns out to be a very different object. At first, it looks very similar, but it will be obvious that a single input different from zero will in generate an infinite output. Which is certainly not the case of a moving average. To study this, we will go back to something we are all very familiar with. It's a simple equation that will describe the value present in your bank account. Let's assume the following things. You have a constant interest rate of 5% per year. Assume you put or take money only once a year on January 1st. Interest for a positive balance or charges for a negative balance are calculated on December 31st. They are added January 1st of the following year. So call x[n] as input, adding or subtracting from the bank account no January 1 of year n. Call y[n] the content of your account on December 31st of year n. Then it is not hard to see that y[n] is equal to 1.05y[n-1]. That is, so 5% is your borrowing rate or interest rate on the content of your bank account the previous year plus xn which is what you put in at the first of January of the year. This recursive equation can be depicted in a block diagram as shown now. So xn enters. It is added to 1.05. The previous content which is y of n minus 1. This is a feedback loop which is a delay element z minus 1. This added together indeed gives the output yn. So to make clear, y n is equal to 1.05 y of n minus 1 plus x n. Let's look at a few examples. Let's take a one time investment. So x n is equal to 100 times 0 and 0 everywhere else. So we can calculate this by hand just to get the feeling. Y[0] will be equal to 100, because that is what is put into the account. y[1] will be 105. y[2] will be 110.25. That's 1.05 square times 100. y[3] is something of the order of 115 and so on. If we depict this, then we see that your wealth is slowly increasing. Actually not that slowly because it turn out that it's actually an exponential. So in general, y[n] is equal to 1.05 at the power of N times 100. Let's look at the second example. Let's take a saver. So the saver puts 100 every year after the origin of time that is 0. The solution to this difference equation is not obvious. We will be able to write it down after we have learned some basic tools about difference equations. But we can calculate a few points. So Y over Z for example is a hundred. Y of one is 205, Y of 2 is 315.25, Y of 3 is of the order of 430 etcetera. So we can plot this. And now we see that it something that goes faster than the linear growth. Why? Because there is compound interest. The result of the different equation is YN is equal to 2000(1.05) to the power of (n+1)-1. Let's look at the third example, the independently wealthy person. So x[n] is obtained the following way, you put 100 times 0 and then you take the interest out every year. So the interest is 5%, so 5% of 100 is 5. And we have 0.5 times u[n-1] that comes up. The interesting thing is that now y, the output, keeps constant. It's 100 times zero, this we know, that's what we put in. And then when we thought it went up to 105, we take out five, and so it stays at 100. And so the output is perfectly constant from zero to infinity. We can now generalize this a little bit. We put a delay by capital M, and we put the factor alpha. So y[n] is equal to alpha time y[n- M] plus the input x[n]. We are engineers so we like to choose alpha smaller or equal to one. This is quite different from economists. We had just seen the previous examples where alpha was 1.05. Let's make an example. Let's take M is equal 3, alpha is equal to 0.7 and as an input, our usual signal, which is equal to 1 at the origin, 0 everywhere else. We can calculate easily what's going to happen. For the first instance, y(0) is equal to 1, then it is zero for two instances, then it's equal to 0.7, etcetera. If we plot this, we see something that is almost periodic. Namely of period three, except that the decay is slowly, as power of 0.7. If we put more interesting signals, that's a little ramp here, which starts equal to one at zero, equal to two at two, equal to three at instant two and we put it as an input, then we truly see the repetition. So, alpha here was chosen equal to one. So there is no decay in the signal. It simply repeats one period, this period from zero to two. Therefore, we have seen that the M-tap delay essentially generates an M-sample periodicity. If we want to play music with this, we need to associate a time period, T, to sample intervals. The periodic signal of frequency, f, will be in hertz, a frequency 1/MT, so for example, if T = 22.7 microseconds, M = 100, then the frequencies that these generate will be of the order of 440Hz. Let us look at this. So for example, if you want to play a sine wave, M = 100 Alpha is equal to one. X n is equal to one period of a sine wave. Sine of two pi times N over a hundred. And then this will be nicely repeated by our recursive loop and generate a sine wave that is indeed equal to a 440 hertz sine wave. Let us now listen to a sine wave of frequency 440 hertz. [SOUND] So we have seen that M controls the frequency, or what's called in music, the pitch. To imitate the violin, we need to go beyond the single sine wave. A crude approximation is a triangular wave. We can change the pitch by changing M. We can simulate the decay by choosing alpha smaller than one. Let's look at an example. M is equal to 100 again. Alpha is equal 0.95. Xn is one period or a 0 mean triangular wave. Sure enough, if we put this into our recursive loop, it will generate a sequence of triangular waves that slowly decay with 0.95 to the power of the number of periods. Let us now listen to the sawtooth wave the decay given by 0.95 to the power of the number of periods. [SOUND] We are now at the Karplus-Strong Algorithm. This is an algorithm that was invented in the 80s to simulate guitar sounds and what is very particular is that it's not initialized with a sine wave, or a triangle wave, but with a sequence of random numbers. So we see an example here, where M again is 100, alpha is 0.9, that gives a relatively slow decay. And xn 1 period is actually a set of random numbers. We can change the pitch again by changing M and the decay depends on the factor alpha, as usual. We see now what signal is generated, and we are going to listen to exactly this signal. With various pitches, and you will see that this is a crude imitation of a guitar sound. Let us listen to the output of the Karplus-Strong Algorithm so it is initialized with random numbers, 100 of them. And then there is a decay of 0.9 and we can listen to this, it should sound like a plucked string. Of course it's a coarse approximation, but now we can listen to it. [SOUND] Let us wrap up this example of building a synthesizer. We have seen basic elements, adders, multipliers, delays. We have seen two systems moving averages as well as recursive systems. We were able to build simple systems with interesting properties and now, we want to understand these in more details. To understand this, we will need a mathematical framework, which is a topic of the next lecture.