 Welcome to the 27th lecture on the subject of digital signal processing in its applications. We have in the previous lecture completed the design of infinite impulse response filters using the bilinear transformation approach and frequency transformations. There are of course other ways to design infinite impulse response filters that is not the only way. Just to mention a couple there is what is called the impulse invariant method. In the impulse invariant method what one does is to keep the impulse response the same at chosen points of sampling that is why it is called impulse invariant and build the impulse response of the discrete time filter around that principle. In another approach one can use optimization methods. One can use methods to optimize the coefficients with respect to a desired frequency response. We are not going to discuss those approaches in this course for want of time. Instead we would now proceed to the design of finite impulse response filters and that shall be the theme of the lecture today. We are going to talk about finite impulse response filter design and specifically we are going to talk about designing finite impulse response filters with what is called the windowing approach. There are various approaches. We shall look at a few of them based on the time that we have. But this is one of the most commonly used approaches and therefore we shall look at this approach in some depth. Now as the name suggests a finite impulse response filter is one whose impulse response is finite in length and obviously the whole aim of that impulse response is again to approximate the desired frequency response with as close an approximation to the ideal as one can get. Now the design of finite impulse response filters can be likened in many ways to approximating numbers except that this is one level higher. This is an approximation of a function and there we are trying to approximate just one number. For example suppose you wish to approximate the number square root of 2. Now you know the approximation of numbers and the approximation of functions in many ways have parallels. In fact one can take inspiration from the way one approximates irrational numbers. Now remember it is irrational numbers that really require approximation. What I mean by approximation is approximation with a rational representative. When one carries out calculations on a calculator which involves irrational numbers one does not really use the irrational number at all in the calculation. One uses a representative which stands in for that irrational number and the representative has to be rational. It has no choice. That is because you have only a finite number of bits in which you can represent any number. Forget about irrational any number in the computer and if your representation in the binary form exceeds that length you are of course going to incur some error. But what you are looking for is the best approximate the best representative. It is like saying that you know I have a function to perform I have a task to do and since I cannot myself go and perform the task I send somebody else who can do the task almost as well as I can if not as well. That is what I mean by a representative. And something similar happens in the context of a finite impulse response filter. Anyway let us look at how we would approximate numbers. The irrational numbers because we already seen that the ideal impulse response that we are going to deal with is irrational. By rational I mean you can never realize it using a rational system function we have shown why. So what we are trying to realize is irrational but what we are going to use is rational. So we have this conflict right in the beginning. Now in the IR case we resolve the conflict by allowing both zeros and poles. Now we will not allow a denominator at all the denominator would be trivial. And it is only the numerator polynomial which will play a role. And therefore in a way the design of FIR filters or approximating an irrational response by using FIR filters is a polynomial approximation problem. It is a problem in which you are trying to approximate an irrational response by a polynomial. A polynomial in Z or Z inverse as you like it to be thought. Anyway coming back how would you write the number square root of 2 if you were asked to do it in decimal. Well of course many of us are familiar with what we call the square rooting algorithm but let us assume that the first few digits have been calculated. So maybe you know you would have something like 1.4142 and something beyond that. Approximate square root of 2. And of course you can convert this to binary. So you see what we do when we write this number on a computer is to truncate. That is one way to do it. You can truncate the representation up to a certain number of digits. Not at all difficult to understand. Something better that we can do is to round. By rounding we mean we look at the next digit and then we decide whether we should add one or not add one to the last digit that we have. Rounding is in some sense better than truncation because in rounding you are incurring only say potentially half the error that you might in truncation. In rounding you would not incur you know you are at most 0.5 away. You cannot really do much better than that. And the spirit behind rounding is that even after you have truncated you are trying to see if you can to some extent put some band aid on the wounds that you have created. You see by truncating you have actually cut off some vital part of that number. The number is not the truncated number. The number is much more than that. So you have cut off something vital in that number. And that cut off or that process of severing those digits from the number is going to leave scars on the value of the number. What you are doing in rounding in a certain sense is to try and apply ointment on those scars in the best possible way and you cannot do much better in the context of number than rounding. So in the case of FIR filters one is doing something similar but at a slightly higher level. Let us take the example of a low pass filter. So if you have an ideal low pass filter with the following frequency response, we know what its ideal impulse response would be. The ideal impulse response would be sin omega Cn by pi n for n not equal to 0 and omega C by pi for n equal to 0. We have seen this more than once before. Of course we are familiar with the fact that this is an irrational filter. So it is also infinite in length in both directions. We have seen what precludes this from ever being realized. Let us just repeat. For one it is infinitely non-causal, secondly it is unstable, thirdly it is irrational. And if you want a finite length filter or finite length impulse response to go as close to this as possible, one obvious thing to do is to simply truncate this response. So for example if you desire that you want an impulse response of not more than 11 samples in length. For the moment I am taking an odd number of samples and I will explain why. You see if you look at this impulse response, the ideal impulse response here let us call it H ideal of n. So if you look at H ideal of n, one very obvious thing about H ideal of n is that H ideal of minus n is equal to H ideal of n. Now you see if you look at the way you represent square root of 2, so here it is very clear that whatever you say on the positive side of n is mirrored on the negative side. Now if you look at the way you represent square root of 2 on a computer, you retain the most significant places. So suppose you want to calculate square root of 2 up to 20 decimal places and you are asked which of these decimal places should I retain. It does not require almost a no-brainer. You would obviously say keep the most important ones. Keep the integer part and keep the next few places as many as you can accommodate. It does not require too much of thinking to come to that conclusion. Now in the case of the impulse response here that is not so obvious. If I have the option of keeping 11 samples, which of them should I keep? It is not so obvious. Of course intuition tells me that I should keep the most important of them. I mean a certain sense that indeed serves the same purpose as keeping the most important digits does. And what do you mean by the most important samples? One way to identify the most important samples is to think of the samples with maximum magnitude. But then you see you cannot decide to keep some samples and throw away others in between. You know you are forced if you do wish to truncate an impulse response, you cannot keep the first and third sample and throw away the second. That would lead to something very very peculiar. So you are restricted to of course retaining or throwing away contiguous samples. And then the most obvious thing to do is to look for that part of the impulse response which has the most important samples. And in this case we can sketch how that impulse response looks. We know that this impulse response is a sampled version of the following envelope. So you can visualize this envelope. In fact you also know what this envelope means. Sine omega ct by pi t and of course at this point it is 0. And so what we have is sine omega ct by pi t sampled with rate 1 including t equal to 0. That is what you are doing. You have this ideal response, this ideal continuous function sine omega ct by pi t. You are sampling this at integer spacing and you are including t equal to 0. Now remember you might also have decided not to include t equal to 0 and we shall do that later. We also want to give an interpretation to this continuous function that we have drawn. This continuous function is the band limited function which you would get. If you restricted the discrete time Fourier transform to the range minus pi to pi. Now remember quite some time ago we had talked about the underlying band limited function corresponding to a certain discrete time Fourier transform. We said that the discrete time Fourier transform is periodic with period 2 pi. And if we choose we can always restrict that discrete time Fourier transform to minus pi to pi. What I mean by restricting is keep what is between minus pi and pi and throw out the rest. If you did that you automatically have a band limited function with a band width of pi and of course obviously pi on the normalized angular frequency axis. So of course Nyquist theorem tells us that we should sample at least an angular frequency of 2 pi and that is all that is really about the discrete time Fourier transform. So when you sample that then that means you know sampling in an angular frequency of 2 pi means a frequency of 1 and that means taking samples with an integer spacing. And of course then if you choose to sample it starting from t equal to 0 you get back the original sequence H ideal of n. And of course the Fourier transform that sample sequence is essentially the discrete time Fourier transform may be to within some constant. So we do not need this idea of the underlying band limited function here. In fact the underlying band limited function as we see it is symmetric in nature here as you see it is an even function of t and that is also reflected. Now you know it does depend on whether you have included t equal to 0 or not. If you have included t equal to 0 then if you sample at the integers the evenness is preserved. But if you choose to sample say starting from t equal to 1 by 3 onwards and that evenness is not preserved although the original underlying function is even. So one must be careful to see that evenness needs some effort to be preserved. There is another way to preserve evenness. Instead of sampling at t equal to 0 you could have also sampled beginning at t equal to minus half. You would get minus half plus half 3 by 2 5 by 2 and so on on the positive side and minus half minus 3 by 2 minus 5 by 2 and so on so forth on the negative side. Even then you would have symmetric preserved evenness preserved and you can see with some effort that these are the only 2 ways in which you can preserve the evenness. Any other process of sampling of this with integer rate will not preserve evenness. Either take 0 and then take samples symmetric around and then you know if you do wish to retain that evenness after you have truncated. So remember you have H ideal n which lasts forever on both sides. But if you wish to keep the evenness of H ideal n after truncation then you need to take an equal number of samples on the positive side of t equal to 0 as on the negative side and therefore we shall first begin with odd length finite impulse response filter design. So for example as I said suppose you wish to preserve exactly at not more than not say exactly not more than 11 samples in the impulse response then the most sensible thing to do as you can see from here is to retain 5 samples on the positive side 5 samples on the negative side and the sample in the middle at t equal to 0. Now on the other hand if you are asked to retain only 10 samples not more than 10 samples and you still want evenness to be preserved then you have to work a little harder. Clearly you need 5 samples on the positive side and 5 samples on the negative side. So then you have to resample this continuous function. You need to resample it starting from t equal to half. So let us look at this function. You know if you want an even number of samples then you have samples starting from t equal to half and then of course you would include half 3 by 2 5 by 2 and so on and half minus 3 by 2 minus 5 by 2 and so on. And then you can take 5 samples on this side 5 samples on this side and you would still have symmetry. So now it also tells us how to deal with the situation when you want an odd length FIR filter and when you want an even length FIR filter while preserving symmetry while preserving evenness. For the odd length there is no problem. Just retain as many samples. For example if you want an odd length filter of length not more than 11 just retain 11 samples keeping the center intact 5 on either side. If you want the length 21 keep the middle t equal to 0 and then take 10 on either side and so on. But if you want an even length then you have to work a little harder you must shift the point of sampling by half and then take an equal number of samples on the positive and negative side. So this should be observed right in the beginning right odd length or even length. So you see now we will keep on talking odd length even length every time. We will discuss the odd length case and for the even length case you need to make that little change and what is the effect of making that little change when you sample starting from half onwards all that you are doing is introducing a delay of half a sample an effective delay of half a sample. It does not affect the magnitude of the frequency response it only affects the phase response that too it introduces a constant time delay at all frequencies so it can be condoned. So even length FIR filter incurs even length FIR filter design by truncation incurs the additional penalty of introducing that delay which we can anyway we will see in a minute that you cannot do without a delay you know but you have to bring in that delay right in the beginning when you resample. We will discuss odd length FIR filter design and from for the even length you just have to make this little change you can keep that in mind right from the beginning. Anyway now the point is that the simplest thing to do as I said if you wish to retain a certain number of odd samples to n plus 1 so let us assume that you wish to design.