Phil Lucht Math & Physics Archive
Home / Math and Physics Files / Math / Spectral Theory Book / Edits done 2003 re L3

excel filter 6

DOCX · 23.1 KB
Open DOCX file

Personal working notes dated 6.23.91, written by Phil as an exercise in making a digital filter in Excel with weights -1,0,3,4,3,0,-1 approximating a sinc function. They cover the Z transform, the reflection rule, why |H| is symmetric, why symmetric coefficients give linear phase, group delay and impulse response. An appendix lists practical tips and problems with Excel charting.

AI-written summary; may contain errors.

Extracted text (machine-read; may contain errors)
Excel Digital Filter Exercise 6.23.91 1. Today I made my first digital filter using Excel. I tried several sets of weights, ended up with the set -1, 0,3,4,3,0,-1 to try and approximate a sinc(x) thing. Remember that the "weights" are really sample points on your kernel function x(t). 2. The Z transform thing is then written H(z) = -1 + 0z + 3 z2 + 4 z3 + 3 z4 + 0 z5 - 1 z 6 = 3. Reflection Rule. Important points now. First, since coefficients are real, that is like saying our famous x(t) is real. We know that implies the reflection rule, X(-w) = X(w)*. When you convert that to Z tranform, it just says that H(z-1) = H(z)* , because z-1 is how you do -w. Any series like the above with real coefficients satisfies this reflection rule. 4. Computation. Excel does not know complex math, so you have to think of zn = e inw∆t = cos(nw∆t) + i sin(nw∆t) You can then write Re[ H(z)] = Im[ H(z)] = Remember that all Excel knows how to do is lay down an x-axis column, which in this case is n∆t. So at the top of a ReH and ImH column, you have to enter the entire formula as shown. (I dont know if there is a way to get that formula from another spreadsheet in Reduce fashion where the columns are coeffs, and you have a "variable" . I don't think Excel knows about variables. You can assign a "name" to a box, or to a set of boxes. They do have something called "array function", but takes too long to learn how it all works. ) The next step is to say mag(H) = sqrt( Re2 + Im2) phase = ATAN2( Re, Im) This last part is easy. The painful part is entering that formula twice. So to summarize, you tell Excel how to compute the magnitude and phase of your filter. Then you plot things out. 5. Problems I had. First was I had a big error, I kept writing down cos(w*dt)^n instead of cos(nwdt). That was just a good, and it kept making the mag(H) thing not be symmetric in w which kept amazing me. See next box. 6. Why is mag(H) symmetric in w ? From the reflection rule, you know that |H(-w)| = |H(w)|, because the * does not count here. So it is always symmetric, just as I drew it in my Chapter 3. This has nothing to do with the nature of the coefficients, as long as they are real. 7. What about the phase, is it linear? This was another major confusion I had that is now resolved. I once thought that a FIR filter had to have linear phase since there is a "constant delay" through the filter. This is a junk statement that has no meaning. The flip flops are just your time samples of the time continuum. It is true that the incoming signal does "keep its shape" as it steps through maybe 100 flipflops that make up the filter, since there is no feedback. However, this says nothing about the overall group delay of the filter. This is a question of when the output starts building up, etc, and that depends on the coefficients. So a priori, there is no reason why a FIR filter should be linear phase. Now think back about x(t) again. We are going here to make a very elegant and clean argument. Suppose you take as your x(t) a pulse which is symmetric about t=0. This means that in the Fourier transform to get X(w), you can reflect the negative time axis and convert the expos into cosines. Since a smooth integral, you don't worry much about what happens at t=0. Thus, X(w) for a symmetric about t=0 selection for x(t) is 100% real! We have seen this in our box pulse, for example. Thus, X(w) for a symmetric x(t) has zero phase at any w! That is pretty linear phase! Now suppose instead you select x(t) to be the above pulse, but time shift it M ∆t time units to the right (time is still continuous here...). We well know that the new X(w) will have phase exp(-iw∆tN/2), this is just the usual time translation phase. Thus, you get f(t) = - w [ ∆t M], so you get a linear phase, which means a constant group delay. Now this is the basic idea. In the digital filter, you approximate x(t) by a set of N coefficients numbered 0 to N-1. Suppose N = 3, and you center a filter at t=0. Then if you start coeffs instead with constant, you are shifting filter exactly 1 box to the right, which is (N-1)/2. Suppose N = 4. Then ideal filter is still centered at t=0, but when you build it, you have to shift it 1.5 units to the right, so again, correct formula is (N-1)/2 = 3/2. It is just the picket fence problem. So, it is no surprise now that this is true: " If coefficients are symmetric, filter has a linear phase which is given exactly by f(t) = -w [ ∆t (N-1)/2 ]. History note: I was totally confused by this issue. I plotted phase for the above filter in Excel and it was coming out linear. I internally still thought all FIR filters were linear phase. But I was unable to prove this with general coefficients! Then I happened very late to see the note in Lam way way back on page 564 which proves this in the digital case. The proof is hard to follow, but it is exactly what I have described above. No doubt about it! So my Excel filter phase was linear because I happened to choose a symmetric set of coefficients. Summary: an FIR filter is just a convolution with some sampled x(t). We know that symmtric coefficients for x(t) cause X(w) of the filter to have linear phase as shown above. The reason is that the spectrum of a symmetric pulse is real. For IIR filter, I have no conclusions at all, but I do know that this argument does not work. 8. Comments on the plots. (a) First one is for -1,3,4,3,-1. Second one is -1,0,3,4,3,0,-1. (b) You see the characteristic symmetry left and right. Not much difference in these two filters. (c) phase is on second one only, is very linear! (d) come kind of computation problem exists at the first node. This makes the mag and phase both wrong for about 10 samples, don't know why yet, will investigate. // I did. See next item (e) Each integer step on the chart lower label is only one computational step, not 10 as I was thinking earlier. Thus, in the area of our problem, there is only one step. Each point is computed accurately of course by FP math. The chart is then drawn by linking little 1/8th inch segments, since this is the step size. We missed the zero of the function, so the 1/8th inch thing makes a horizontal bridge across the gap, and that is what we see. The phase is computed on this same bad info as well. If you were to add more mesh points, the phase return would be steeper as well, now it is the best it can do with large steps. In retrospect, it is amazing to me mag curve is as smooth as it shows. 9. Group Delay. Transmission lines have group velocity and phase velocity, because there is a distance coordinate involved, normally z. A filter has no distance, so these terms have no meaning! however, filter does have a dimensionless phase f(t), and you can interpret df/dw = t as the "group delay" of the filter, the time for a pulse to get through. And this can vary versus w, so filter can disperse things. 10. Impulse Response. Think of your convolution digital filter with its little set of coefficients. It is presumably acting on a digital signal of maybe a byte per sample, perhaps it is 2's complement. Perhaps it is a floating point system instead with 32 bit numbers. In any event, what happens if you shoot into this thing a "unit impulse", which means a single sample of value 1 ( in whatever system you have), in a sea of samples that are all 0? This sample marches down the flipflop chain. At each point, what you see on the output is the coefficient for that stage! Thus, such a pulse maps out for you the shape of the filter. But we already knew this. The impulse response of a filter H(z) is exaclty H(z)! And this thing in the time domain is x(t) = xn, the sequence of the filter coefficients. It's just good to keep the physical picture connected to the theory. Appendix: here are relevant some comments about using Excel. (z) I was unable to put general Draw type graphics on the chart. You get lots of grid lines, and you can put arrows. I don't know how to to general text either. But I did a title text. (a) you should perhaps leave space at the top of the worksheet for putting random things. Then you have your headings starting maybe in row 9, and actual data in row 10. Thus, in the left column you might put just row()-10 as your equation. Then in first column in row 10 you will have the number 0, and then 1 and 2 and 3. When you build the graph, you are asked if you want this column to serve as the x axis, and you say yes. (b) When you select region for graph, do not select area above the headings. This causes garbage on the left of the graph, as you might expect. Just select the headings and the data and nothing else. (c) To get to the bottom of the graph, right now I take the slider bar to the bottom. It seems to know that I just want to go down to the bottom entry. You cannot select entire columns because then you get the stuff at the top. Also, you never want to do a "fill down" with a whole column selected, or you will be waiting for 10 minutes while 16000 items are computed. (d) in the second column, I might have a scaled down version of the left column. This will then serve as the real argument of whatever function we are doing. At least in this case it was convenient. If you then plot the second column as a graph, you get a check that your graph origin is correct. (e) graph comes up as some kind of boxes thing. I always change it to line graph soon. After doing this, you have to go fiddle with "scale". Again, I often set spacing at 10 units for labels, so you might see numbers 0 10 20 30 ... along the bottom. These are the left column of the worksheet! Since first data is in row 10, and since number there is 0, your graph will start properly at 0. (f) In order to get full control over the chart, I have to do "new chart". This makes a chart frame and also plots the columns you selected. If you change the worksheet numbers, the chart changes. I think it uses the worksheet to build the chart every time you expose it. I do not know if you can make the worksheet longer without doing up a new chart. (g) you can add and delete curves from the chart easily. To delete a graph, just point to it and delte, I think. Else you do "edit series" and delete it in there. To add a graph, you just "copy" a column of the worksheet and then normal paste it onto the graph. Maybe special paste? If you are fiddling with one curve and changing an equation, it will update automatically each time you see the chart. So, there is no need to do "new chart" more than once for a given framework. (h) you can "copy" the chart and paste it right onto the worksheet. However, if you start with a simple worksheet chart using the button, I don't know yet how to get over to "chart control" world. Maybe there is no way, it is just a fast temp chart. Perhaps you could copy this chart and paste it into "new chart", should try that. (i) I do not know how to cause the equations from selected boxes to appear on the printout. With the "display" item you can make them all display, but since they are often long, you cannot see them in their little tiny box areas. This needs work. I was unable to copy the text of an equation into a "note". (j) the help menu is OK, but not a clear system yet. Maybe I should print the whole file out? Lets go try that right now. Result failure. If you do the usual stuff and then try to read into Word, it reads as text ans you see that file is in some fancy format that is not worth printing. What format might it be? Certainly not word. Or did they just leave off a header? Why would they use some other format? They wrote Word. Could be a speed issue, special help file format. What does Word do if you store out a word file in text format. Go do it. You lose all things like font size and style. As soon as you store, it changes to default font on the screen. Aso, just the characters are stored, fine. What happens if you store in RTF? Similar to the above, comes back in as RTF with lots of extra stuff. So the rule is this: if you store out in any format other than Word, it comes back in as text and you see the "stuff" of that format. Thus, word cannot read files in other formats! Wrong. When you read this RTF back in, it asks whether or not you want it to interpret it! So it looks at the little header at the start and figures out that it is RTF. OK, I give up on printing out this help, just as MS intended for me to do.