Int. J. Engng Ed. Vol. 20, No. 5, pp. 867±871, 2004 Printed in Great Britain. 0949-149X/91 $3.00+0.00 # 2004 TEMPUS Publications. The Use of Spreadsheets to Calculate the Convolution Sum of Two Finite Sequences* ALI EL-HAJJ, KARIM Y. KABALAN Electrical and Computer Engineering Department, American University of Beirut, P.O. Box 11-0236, Beirut, Lebanon. Email: kabalan@aub.edu.lb SHAHWAN KHOURY Faculty of Engineering, Notre Dame University, Jounieh, Lebanon This paper presents an educational spreadsheet programs for calculating the convolution sum of two finite sequences. This convolution sum is accomplished using three different methods. After each method is presented, the procedure for computing the convolution sum is outlined, and the results are obtained for each of these cases. These explicit methods of calculation are proven to be well suited for an educational environment as characterized by their flexibility and simplicity. Moreover, when such software is used, they could make engineering studies more appealing to the students. constructing these tables and for providing an invaluable insight into the nature of the problem. As a presentation of the sensitivity concept of the addressed problem, this paper illustrates the three different methods used to construct these sum tables and thus the convolution sums. The first two methods [11] represent a classical approach to construct the convolution tables where the third method introduced in [12] uses a table similar to the one constructed for the multiplication of two decimal numbers. This spreadsheet approach presents a comprehensive procedure and an attractive educational tool. This ideal process has the following characteristics: INTRODUCTION SPREADSHEETS are widely used for solving engineering problems and are a well-recognized engineering education tool providing the practical ground for presenting theoretical concepts that form the foundation of a subject. In this respect, methods were developed to simulate logic networks [1±2], the operation of an analog computer [3], and the function of microprocessor systems [4]. Moreover, spreadsheets were also used to analyze linear, nonlinear, and sampled data control systems [5±6], and to study the stability of linear and discrete control systems [7±8]. Furthermore, some signal analysis exercises using spreadsheets were considered in [9] which include the calculation of the convolution integral of two functions. In this paper, the use of modern spreadsheet programs [10] for calculating the convolution sum of two finite sequences is considered. This discrete convolution is parallel to that used for continuous functions considered in [9]. It has applications in many engineering areas such as discrete signal analysis, discrete filtering, and communications. The problem faced by beginner students in learning discrete convolution is covered in [11] where the calculations require a number of iterations that need effort and time to perform. To develop a coherent knowledge of the subject, some useful approaches for uninitiated students are presented in [11±12], where structured tables of values of the sequences were constructed. In this paper, it is shown that spreadsheets are suitable tools for 1. It is of low cost since spreadsheets are widely available. 2. It is possible to study the influence of changing a value in any of the sequences on the resulting convolution sum. 3. In Excel, the zooming option allows viewing a large table on one screen and making the most efficient use of the screen. FIRST METHOD This method uses the approach presented in Example 6.3.4 of reference [11] to construct a table. In this method, the basic definition of the convolution of two finite causal sequences (the sequence has zero value for negative values of n) is used with the fact that the convolution of an M-point sequence x[n] and an N-point sequence h[n] is an (M N ÿ 1)-point sequence y[n]. In a * Accepted 21 January 2004. 867 868 A. El-Hajj et al. mathematical form: yn NMÿ1 X hkxn ÿ k 1 k0 In this example, h[n] is a five-point causal sequence and x[n] is a four-point causal sequence. Thus, y[n] is an eight-point sequence defined from n 0 to n 7. It can be easily deduced from Equation (1), that (n ÿ k) takes all values from ÿ k to 7 ÿ k as n takes values from 0 to 7. As a result, y[n] can be considered as the product of the vector h[k] and the vector x[n ÿ k] which is obtained from x[k] using an appropriate transformation. This transformation is constructed in the worksheet of Fig. 1 with the following steps: 1. The first row of the table, row 5, is filled with all values of k used in evaluating the vectors x[n ÿ k]. The smallest value is ÿ 3 used in x[ÿ k] and the largest is 7 used in x[7 ÿ k]. 2. The second and the third rows of the table are used to input the given values of the sequences h[n] and x[n]. 3. The entries of the remaining rows of the table are obtained by first reflecting x[k] about the origin to form x[ÿ k], and then shifting the resulting sequence to the right one step at a time to form the remaining vectors. 4. The M column of the table, labeled n, indicates the values of n for which y[n] will be calculated. In this example, and as mentioned earlier, n takes the values from 0 to 7. 5. The N column of the table, labeled y[n], is used to store the results of the multiplication of the entries in the rows corresponding to h[k] (range B6:L6) and x[n ÿ k]. To perform the product of these two vectors, the transpose ht[k] of h[k] is calculated at range P6:P16 (using the spreadsheet command Paste Special), then y[0] is obtained by writing at cell N8 the matrix multiplication formula: MMULT B8:L8; $P$6:$P$16 2 The transpose of the sequence h[n] is obtained due to the restriction in matrix manipulation in Excel. Formula (1) is then copied to range N9:N15 to obtain the required values of the sequence y[n]. SECOND METHOD This method uses the approach discussed in Example 6.3.5 of reference [11] to construct the convolution table. In this method the convolution sum y[n] of the two finite sequences h[n] and x[n] is given by the formula: yn h0xn h1xn ÿ 1 : : : hkxn ÿ k : : : hmxn ÿ m 3 In Formula (3), m is the highest index for which h[m] is different than zero. To present this procedure, the same example taken before is restated in this section. In this example, y[n] takes values from n 0 to n 7. Consequently, the values of the sequences x[n], x[n ÿ 1], x[n ÿ 2], x[n ÿ 3], and x[n ÿ 4] only are needed to compute y[n]. The procedure along with the computation directions are conferred in Fig. 2 using the following steps: 1. A header row, row 5, is filled with all needed values of n. This row also contains headers to indicate that k and h[k] will be stored in the corresponding columns to facilitate the multiplication procedure as will be explained later. Fig. 1. Convolution table using the first method. The Use of Spreadsheets to Calculate the Convolution Sum of Two Finite Sequences 869 Fig. 2. Convolution table using the second method. 2. The vectors x[n], x[n ÿ 1], . . . x[n ÿ m] are stored in the next rows. First, the values of the sequence x[n] are inputted in row 6. The other rows, rows 7±10, are obtained by simple shifting of the range containing x[n] . This one place to the right shifting is done when copying to the next row. 3. The next rows, rows 11±15, contain the terms constituting the sum in Formula (3). The first row contains the terms h[0]x[n], the second contains h[1]x[n ÿ 1], and so on. To facilitate obtaining these terms, each h[k] value is stored at the same row as the corresponding x[n ÿ k] as indicated earlier. The formula at cell B11 is given by: B6*$K6. 4. The use of mixed addressing (relative and absolute addressing) allows obtaining the other h[k]x[n ÿ k] terms by simply copying this formula to the range B11:I15. 5. The convolution sum is next obtained by writing at cell B16 the formula: SUM(B11:B15) This formula is copied to the range C16:I16. As an alternative of writing these formulas, it is possible to make use of the AutoSum Button found on the Standard Toolbar and apply it to the range B11:I15. Figure 2 shows similar results as in the previous method and as expected. THIRD METHOD This method uses the approach discussed in [12] to construct the table of Fig. 3. This procedure is similar to the multiplication of two decimal numbers which makes this method attractive, easy to learn, and simple to implement. To obtain this table, the following steps are done: Fig. 3. Convolution table using the third method. 870 A. El-Hajj et al. 1. The two sequences are placed in two consecutive rows. In this case, a number of columns equal to the number of elements of the sequence x[n] should be skipped in order to accommodate the results of the multiplication. Figure 3 shows the placement of the two given sequences right aligned at rows 6 and 7 after skipping 4 columns (columns A to D). To outline the approach, a line is drawn under x[n] to graphically demonstrate the multiplication procedure. 2. The rightmost x[n] value is multiplied by the vector h[n]. The result of the multiplication is stored in the next row, row 8, as described in the procedure. This is done by writing at cell I8 the formula: $I$7*I6. This formula is copied to the range H8:E8. 3. Similarly, the next x[n] value (from the right) is multiplied by the vector h[n]. The result of this operation is stored in the next row. The procedure is continued for all elements of x[n] in a fashion similar to a pencil and paper multiplication calculation, except carries are not performed out of a column [12]. Shifting one place to the left is done each time a next row is calculated. A line is finally drawn under the last calculated row to indicate the end of the procedure. 4. To obtain the convolution sum y[n], the vectors h[n]x[3], h[n]x[2], h[n]x[1], and h[n]x[0] are added together. The result is computed and stored in row 12. This is done by writing in cell B12 the formula: SUM(B8:B11). This formula is copied to the range C12:I12. As an alternative of writing these formulas, it is possible to make use of the AutoSum Button that is found on the Standard Toolbar and apply it to the range B8:I11. Finally, the corresponding values of n are filled in in row 13. Similar results are obtained as in the previous methods. CONCLUSION The use of modern spreadsheet programs for calculating the convolution sum of two finite causal sequences was considered. Three different methods were presented and examples of evaluation procedures are given. They are based on using formulas to construct a table showing different steps in calculating the convolution sum. These methods facilitate a simple, flexible, and userfriendly tool suitable for educational environments and spreadsheet users. It is possible to study the influence of changing a value in any of the sequences on the resulting convolution sum by changing this value on the worksheet which causes the worksheet to recalculate providing the new y[n] values. It requires less time/effort to study and implement than manual calculations and/or conventional programming. The same methods, which are presented for two causal systems, can be extended to treat non-causal systems. REFERENCES 1. A. El-Hajj and K. Y. Kabalan, A spreadsheet simulation of logic networks, IEEE Trans. Educ., E-34, 1991, pp. 43±46. 2. A. El-Hajj, K. Y. Kabalan and M. Yehia, Simulation of a class of integrated circuits using spreadsheets, IEE Proceedings-G, 139(5) 1992, pp. 607±610. 3. K. Y. Kabalan, A. El-Hajj, H. Diab and Souheir Fakhreddine, Analog computer simulation using spreadsheets, Simulation Journal of the Society for Computer Simulation, 68(2) February 1997, pp. 101±106. 4. A. El-Hajj, K. Y. Kabalan and H. Diab A spreadsheet educational tool for microprocessor systems, J. Computer Applications in Engineering Education, 3(3), 1995, pp. 205±211. 5. A. El-Hajj and K. Y. Kabalan, Time domain analysis of linear control systems using spreadsheets, IEEE Trans. Educ., 38(4) 1995, pp. 317±320. 6. K. Y. Kabalan A. El-Hajj and W. Smari, Nonlinear and sampled data control systems analysis using spreadsheets, IEE Proceedings A, 143(1) 1996, pp. 52±56. 7. A. El Hajj and K. Y. Kabalan, The use of spreadsheets to study the stability of linear control systems, Int. J. Appl. Engng. Educ., 6(4) 1990, pp. 437±442. 8. K. Y. Kabalan, H. Diab, A. El-Hajj and H. Tabbarah, Stability analysis and minimum phase testing of casual systems using spreadsheets, Int. J. Eng. Educ., 12(5) 1996, pp. 382±388. 9. B. J. Stanton, M. J. Drozdowski and T. S. Ducan, Using spreadsheets in student exercises for signal and linear system analysis, IEEE Trans. Educ., 36(1) 1993, pp. 62±67. 10. Microsoft Excel User's Guide, Version 5.0, Microsoft Corporation (1994). 11. S. S. Soliman, and M. D. Srinath, Continuous and Discrete Signals and Systems, Prentice-Hall (1990). 12. J. W. Pierre, A novel method for calculating the convolution sum of two finite length sequences, IEEE Trans. Educ., 39(1) 1996, pp. 77±80. Ali El-Hajj was born in Aramta, Lebanon. He received the Lisense degree in Physics from the Lebanese University, Lebanon in 1979, the degree of `Ingenieur' from L'Ecole Superieure d'Electricite, France in 1981, and the `Docteur Ingenieur' degree from the University of Rennes I, France in 1983. From 1983 to 1987, he was with the Electrical Engineering Department at the Lebanese University. In 1987, he joined the American University of The Use of Spreadsheets to Calculate the Convolution Sum of Two Finite Sequences Beirut where he is currently Professor of Electrical and Computer Engineering. His research interests are numerical solution of electromagnetic field problems and engineering education. Karim Y. Kabalan was born in Jbeil, Lebanon. He received the BS degree in Physics from the Lebanese University in 1979, and the MS and Ph.D. degrees in Electrical and Computer Engineering from Syracuse University, in 1983 and 1985, respectively. During the 1986 Fall semester, he was a visiting assistant professor of Electrical and Computer Engineering at Syracuse University. Currently, he is a Professor of Electrical and Computer Engineering with the Electrical and Computer Engineering Department, Faculty of Engineering and Architecture, American University of Beirut. His research interests are numerical solution of electromagnetic field problems and software development. Shahwan V. Khoury: was born in Ghalboun, Lebanon. He received his BE. degree in Electrical Engineering from Youngstown State University in 1960. He also received his MS and Ph.D. degrees in Electrical Engineering from Carnegie Institute of Technology in 1961, and 1964, respectively. He was a member of the Technical Staff (AT&T), Technical Director at Projects Studies and Implementation Co. (PSAI), Geneva and San Francisco, Manager of Electrical and Mechanical Works Contracts Division of Engineering and General Contracting, Ets. F.A. Kettaneh, Beirut, Lebanon, General Manager, Debbas Enterprise Beirut, Lebanon, and Consultant, SDI, London. Currently, he is the Dean and Professor of Engineering, Faculty of Engineering, Notre Dame University, Jounieh, Lebanon. His research interests are in numerical solution of electromagnetic field problems and software development. 871