66 DISCRETE-SIGNAL ANALYSIS AND DESIGN the 0 to N −1 region. Some additional programming steps can accom- plish this, but for this example, because of the two almost zero-valued end regions, we assign the value 0.0, which is very nearly correct. Math- cad assigns 0 to unused locations, for example at i =−1andi =N .If necessary, the two guardbands can be lengthened a little. We see also that the sequence can be a modiÞed time sequence, in which case the smoothing is Þltering certain regions of the time domain, or it can be a modiÞed frequency sequence, in which case certain frequency ranges can be modiÞed. For example, the sharp edges of a band Þlter are softened and rounded to obtain beneÞts such as improved group delay near the band edges. This method is also known as transition sampling [Oppenheim and Schafer, 1975, pp. 250–254]. In this case the IDFT is the time domain of the modiÞed frequency response that can be used to improve an analog Þlter or digital Þlter. Analog mechanical and crystal Þlters often use the transitional design, which is the Bessel response to the −6-dB level for improved phase linearity, and Chebyshev beyond that, for a good shape factor. All-pass networks further improve group delay variations, at the cost of additional time delay. When networks with too much time delay are used inside an automatic gain control (AGC) loop, transient response and stability become much more difÞcult. We almost always avoid putting these types of Þlters within a fast-responding gain-control feedback loop. The smoothing should focus on undesired rapid changes without degrad- ing excessively the desired slower-changing signal. A good way to imple- ment this is to use many closely spaced samples and use the three-point method no more times than necessary for adequate results. A further consideration is the rounding off at the corners, where smoothing has reduced the 3-dB width of the time or frequency response. This can often be compensated by modifying the time and frequency scaling factors described in Chapter 1 in a way that retains the low-amplitude guardbands at the edges of the time or frequency range. Finally, Fig. 4-2b shows the spectrum (the DFT) of the pulse of Fig. 4-1b before and after eight three-point smoothing operations. The lowpass Þltering that the smoothing performs is apparent. The smoothing algorithm is therefore a valuable addition to the toolbox. We have emphasized that if the signal pattern is too close to the edges it can alias into adjacent time or frequency regions. To prevent this and SMOOTHING AND WINDOWING 67 retain a causal (n and k from 0 to N −1) result, we must delay and terminate the sequence and use smoothing and windowing sufÞciently that aliasing overßows are small. A positive-only time or positive-only frequency display would show the aliasing reßecting off of the zero or maximum boundary, just as in the aliasing considered in Chapter 3. Other types of very useful windows will be studied in this chapter. As a Þnal example, Fig. 4-2c shows a triangular time-domain signal. Its spectrum is also shown, to which a window with 100-dB attenuation from 0 to 1 and from 15 to 16 has been added. A single 3-point smoothing is then performed on the spectrum. The spreading created by the smoothing is visible from 0 to 1 and from 15 to 16. The end zones of the smoothed response have large drop-offs at 0 and 16. Aliasing below 0 and above 16 is extremely small. This type of operation can be useful where response variations need to be smoothed out by operating directly on the spectrum. Scaling methods can establish the correct time and frequency parameters. The modiÞed time-domain response can be found from the IDFT applied to the smoothed spectrum. SMOOTHING REFERENCES Jenkins, G.M., and D.G. Watts, 1968, Spectral Analysis and Its Applications, Holden-Day, San Francisco, CA. Oppenheim, A.V., and R.W. Schafer, 1975, Digital Signal Processing, McGraw-Hill, New York. WINDOWING A window is a function that multiplies a time or frequency sequence, thereby modifying certain properties of the sequence. An example was shown in Fig. 4-1, where a rectangular two-sided time window with unity amplitude provided zero-amplitude guardbands at beginning and end seg- ments of the sequence. The general form for a window operation w(n)on a time sequence x (n) of length N is y(n) = w(n)x(n) 0 ≤ n ≤ N −1 (4-2) 68 DISCRETE-SIGNAL ANALYSIS AND DESIGN Note that the sequences y(n), w (n), and x (n) are positive-time in the Þrst half and negative-time in the second half, in agreement with our previously established protocol. There are a large number of window functions that accomplish vari- ous goals. We will look at three time-domain windows that are widely used and quite useful: the rectangular window, the Hamming window, and the Hanning (also called the Hann) window. These windows, their 0204060 0 1 2 n 0 5 10 15 20 25 30 −100 −50 0 k (a) dB x1(n) := 1 Rectangular X1(k) := 1 N 1·exp −j·2·p· n N . ·k ∑ N−1 n = 0 Figure 4-3 Three types of window: (a) rectangular; (b) Hanning; (c) Hamming. SMOOTHING AND WINDOWING 69 spectral magnitudes in dB and their equations for a sequence of N posi- tions are shown in Fig. 4-3. The spectrum magnitudes are shown for the positive-frequency halves. The negative-frequency magnitudes are mirror images of the positive-frequency magnitudes. Comparing the spectra of the three, we see that the rectangular window has the sharpest selectivity at zero frequency, with a very deep notch at k =1. This window is ideal when time x(n) and frequency X (k) values can be kept very close to exact integer values of (n) and (k), as we 0 5 10 15 (b) 20 25 30 −100 −50 0 k dB X2 (k) := 1 N 1 2 ·exp1– cos 2·π· n N–1 −j·2·π· n N ·k ∑ N−1 n = 0 0102030405060 0 0.5 1 n x2 (n) := 1 2 1– cos 2·π· n N–1 . Hanning Figure 4-3 (continued ) 70 DISCRETE-SIGNAL ANALYSIS AND DESIGN 0 5 10 15 (c) 20 25 30 −100 −50 0 k dB X3 (k) := 1 N ·exp.54 – .46·cos 2·π· n N–1 . −j·2·π· n N ·k ∑ N−1 n = 0 010 2030405060 0 0.5 1 n 0.54 – 0.46·cos 2π· n N–1 x3 (n) := Hamming Figure 4-3 (continued ) discussed in connection with Fig. 3-1. In mathematical constructions we can often manage this, using scaling procedures. But if not, we see that this window has side lobe peaks that attenuate very slowly. In many practical situations, especially in digital processing of actual signal sequences with imprecise alignment or with noise contamination, this slow attenuation cannot be tolerated. We now look at the other two windows and see that the selectivity is widened in the k =0 region, and the Þrst notch is at k =2. This widening is a fundamental property of all non-rectangular windows and is the “cost” . frequency regions. To prevent this and SMOOTHING AND WINDOWING 67 retain a causal (n and k from 0 to N −1) result, we must delay and terminate the sequence and use smoothing and windowing sufÞciently that. sharp edges of a band Þlter are softened and rounded to obtain beneÞts such as improved group delay near the band edges. This method is also known as transition sampling [Oppenheim and Schafer, 1975,. w(n)x(n) 0 ≤ n ≤ N −1 (4-2) 68 DISCRETE-SIGNAL ANALYSIS AND DESIGN Note that the sequences y(n), w (n), and x (n) are positive-time in the Þrst half and negative-time in the second half, in agreement