Anda di halaman 1dari 194

Scilab Code for Signals and Systems by Alan V. Oppenheim, Alan V. Willsky, S.

Hamid Nawab1
Created by Prof. R. Senthilkumar Institute of Road and Transport Technology rsenthil signalprocess@in.com Cross-Checked by Prof. Saravanan Vijayakumaran, IIT Bombay sarva@ee.iitb.ac.in 18 November 2010

by a grant from the National Mission on Education through ICT, http://spoken-tutorial.org/NMEICT-Intro.This text book companion and Scilab codes written in it can be downloaded from the website http://scilab.in

1 Funded

Book Details
Author: Alan V. Oppenheim, Alan V. Willsky, S.Hamid Nawab Title: Signals and Systems Publisher: Prentice-Hall India Edition: Second Year: 1992 Place: New Delhi ISBN: 978-81-203-1246-3

Contents
List of Scilab Code 1 Signals and Systems 1.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 Linear Time Invariant Systems 2.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Fourier Series Repreentation of Periodic Signals 3.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 The Continuous Time Fourier Transform 4.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 11 11 26 26 54 54 90 90

5 The Discreet Time Fourier Transform 117 5.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 6 Time and Frequency Characterization of Signals and Systems 138 6.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 7 Sampling 148 7.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 148 9 The Laplace Transform 155 9.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 10 The Z-Transform 171 10.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 2

11 Linear Feedback Systems 181 11.1 Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 181

List of Scilab Code


1.1 1.2 1.3 1.4 1.5 1.6 1.12 1.13 1.13b 1.14 1.15 1.16 1.17 1.18 1.20 2.1 2.3 2.4 2.5 2.6 2.7 2.8 3.2 3.3 3.4 3.5 3.6 3.7 Example1.1.sce . Example1.2.sce . Example1.3.sce . Example1.4.sce . Example1.5.sce . Example1.6.sce . Example1.12.sce . Example1.13.sce . Example1.13b.sce Example1.14.sce . Example1.15.sce . Example1.16.sce . Example1.17.sce . Example1.18.sce . Example1.20.sce . Example2.1.sce . Example2.3.sce . Example2.4.sce . Example2.5.sce . Example2.6.sce . Example2.7.sce . Example2.8.sce . Example3.2.sce . Example3.3.sce . Example3.4.sce . Example3.5.sce . Example3.6.sce . Example3.7.sce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 12 13 14 14 15 16 17 18 18 20 21 22 23 24 26 29 33 37 41 45 49 54 60 61 63 66 68

3.8 3.10 3.11 3.12 3.13 3.14 3.15 4.1 4.2 4.4 4.5 4.6 4.7 4.8 4.9 4.12 4.18 4.23 4.22 5.1 5.2 5.3 5.5 5.6 5.7 5.9 5.12 5.15 6.1 6.3 6.4 6.5 7.1 7.2 7.3 7.4 7.5 9.1

Example3.8.sce . . . . . . . . . Example3.10.sce . . . . . . . . . Example3.11.sce . . . . . . . . . Example3.12.sce . . . . . . . . . Example3.13.sce . . . . . . . . . Example3.14.sce . . . . . . . . . Example3.15.sce . . . . . . . . . Example4.1.sce . . . . . . . . . Example4.2.sce . . . . . . . . . Example4.4.sce . . . . . . . . . Example4.5.sce . . . . . . . . . Example4.6.sce . . . . . . . . . Example4.7.sce . . . . . . . . . Example4.8.sce . . . . . . . . . Example4.9.sce . . . . . . . . . Example4.12.sce . . . . . . . . . Example4.18.sce . . . . . . . . . Example4.23.sce . . . . . . . . . Impulse response of LTI system Example5.1.sce . . . . . . . . . Example5.2.sce . . . . . . . . . Example5.3.sce . . . . . . . . . Example5.5.sce . . . . . . . . . Example5.6.sce . . . . . . . . . Example5.7.sce . . . . . . . . . Example5.9.sce . . . . . . . . . Example5.12.sce . . . . . . . . . Example5.15.sce . . . . . . . . . Example6.1.sce . . . . . . . . . Example6.3.sce . . . . . . . . . Example6.4.sce . . . . . . . . . Example6.5.sce . . . . . . . . . Example7.1.sce . . . . . . . . . Example7.2.sce . . . . . . . . . Example7.3.sce . . . . . . . . . Example7.4.sce . . . . . . . . . Example7.5.sce . . . . . . . . . Example9.1.sce . . . . . . . . . 5

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

71 74 76 80 82 85 87 90 93 95 97 99 101 104 106 108 110 112 114 117 121 123 125 127 129 131 133 135 138 143 145 146 148 149 150 151 151 155

9.2 9.3 9.4 9.5 9.6 9.7 9.8 9.9 9.10 9.11 9.12 9.13 9.14 9.15 9.16 9.17 9.18 9.19 9.20 9.21 9.25 9.31 9.33 9.34 9.35 9.36 9.37 9.38 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.9 10.10 10.11

Example9.2.sce . Example9.3.sce . Example9.4.sce . Example9.5.sce . Example9.6.sce . Example9.7.sce . Example9.8.sce . Example9.9.sce . Example9.10.sce . Example9.11.sce . Example9.12.sce . Example9.13.sce . Example9.14.sce . Example9.15.sce . Example9.16.sce . Example9.17.sce . Example9.18.sce . Example9.19.sce . Example9.20.sce . Example9.21.sce . Example9.25.sce . Example9.31.sce . Example9.33.sce . Example9.34.sce . Example9.35.sce . Example9.36.sce . Example9.37.sce . Example9.38.sce . Example10.1.sce . Example10.2.sce . Example10.3.sce . Example10.4.sce . Example10.5.sce . Example10.6.sce . Example10.7.sce . Example10.9.sce . Example10.10.sce Example10.11.sce

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

155 155 156 156 156 157 157 158 159 159 159 160 163 164 164 165 165 165 166 166 166 167 168 168 168 169 169 169 171 171 172 172 172 173 173 173 174 175

10.12 Example10.12.sce . . . . . . 10.13 Example10.13.sce . . . . . . 10.18 Example10.18.sce . . . . . . 10.19 Example10.19.sce . . . . . . 10.23 Example10.23.sce . . . . . . 10.25 Example10.25.sce . . . . . . 10.33 Example10.33.sce . . . . . . 10.34 Example10.34.sce . . . . . . 10.36 Example10.36.sce . . . . . . 10.37 Example10.37.sce . . . . . . 11.1 Example11.1.sce . . . . . . . 11.2 Example11.2.sce . . . . . . . 11.3 Example11.3.sce . . . . . . . 11.5Bode Example11.5Bode.sce . . . . 11.5Nyquist Example11.5Nyquist.sce . . 11.6 Example11.6.sce . . . . . . . 11.7 Example11.7.sce . . . . . . . 11.8 Example11.8.sce . . . . . . . 11.9 Example11.9.sce . . . . . . . 11.9 Root locus analysis of Linear

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . feedback systems

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . .

175 175 176 176 177 177 178 178 179 180 181 182 183 184 185 187 188 188 189 192

List of Figures
1.1 1.2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 2.18 2.19 2.20 2.21 3.1 3.2 3.3 3.4 Results of Exa 1.5 . . . . . . . . . . . . . . . . . . . . . . . . Results of Exa 1.14 . . . . . . . . . . . . . . . . . . . . . . . Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results of of of of of of of of of of of of of of of of of of of of of of of of of Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa 2.1 . 2.1 . 2.1 . 2.3 . 2.3 . 2.3 . 2.4 . 2.4 . 2.4 . 2.5 . 2.5 . 2.5 . 2.6 . 2.6 . 2.6 . 2.7 . 2.7 . 2.7 . 2.8 . 2.8 . 2.8 . 3.2 . 3.2 . 3.2 . 3.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 20 27 28 29 31 32 33 35 36 37 39 40 41 43 44 45 47 48 49 51 52 53 57 58 59 60

3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 4.11 4.12 4.13 4.14 4.15 5.1 5.2 5.3 5.4 5.5 5.6 5.7

Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results Results

of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of of

Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa

3.4 . 3.5 . 3.5 . 3.6 . 3.7 . 3.7 . 3.8 . 3.10 3.11 3.11 3.12 3.13 3.14 3.15 4.1 . 4.1 . 4.2 . 4.4 . 4.5 . 4.6 . 4.7 . 4.7 . 4.8 . 4.9 . 4.12 4.18 4.23 4.22 4.22 5.1 . 5.1 . 5.2 . 5.3 . 5.5 . 5.6 . 5.7 .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

63 65 66 68 70 71 74 76 79 80 82 85 87 89 92 93 95 97 99 101 103 104 106 108 110 112 113 115 116 120 121 123 125 127 129 131

5.8 Results of Exa 5.9 . . . . . . . . . . . . . . . . . . . . . . . . 5.9 Results of Exa 5.12 . . . . . . . . . . . . . . . . . . . . . . . 5.10 Results of Exa 5.15 . . . . . . . . . . . . . . . . . . . . . . . 6.1 6.2 6.3 6.4 6.5 6.6 7.1 7.2 9.1 9.2 9.3 9.4 Results Results Results Results Results Results of of of of of of Exa Exa Exa Exa Exa Exa 6.1 . 6.1 . 6.1 . 6.3 . 6.4 . 6.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

133 135 137 141 142 143 145 146 147 149 154 158 161 162 163 182 183 184 185 186 187 189 191 192 193

Results of Exa 7.1 . . . . . . . . . . . . . . . . . . . . . . . . Results of Exa 7.5 . . . . . . . . . . . . . . . . . . . . . . . . Results Results Results Results of of of of of of of of of of of of of of Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa Exa 9.8 . 9.13 9.13 9.13 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

11.1 Results 11.2 Results 11.3 Results 11.4 Results 11.5 Results 11.6 Results 11.7 Results 11.8 Results 11.9 Results 11.10Results

11.1 . . . . 11.2 . . . . 11.3 . . . . 11.5Bode . 11.5Nyquist 11.6 . . . . 11.8 . . . . 11.9 . . . . 11.9 . . . . 11.9 . . . .

10

Chapter 1 Signals and Systems


1.1 Scilab Codes

Example 1.1 Time Shifting


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

// Example 1 . 1 : Time S h i f t i n g //SIGNALS & SYSTEMS , S e c o n d E d i t i o n //V . OPPENHEIM, S . WILLSKY , S . HAMID NAMWAB // PHI , 2 0 0 8 E d i t i o n // Page 10 clear all ; clc ; close ; t = 0:1/100:1; for i = 1: length ( t ) x(i) = 1 ; end for i = length ( t ) +1:2* length ( t ) x ( i ) = 1 - t (i - length ( t ) ) ; end t1 = 0:1/100:2; t2 = -1:1/100:1; // t 3 = 0 : 1 / 1 0 0 : 4 / 3 ; // t 4 = 0 : 1 / l e n g t h ( t 3 ) : 1 ; // Mid = c e i l ( l e n g t h ( t 3 ) / 2 ) ;

11

21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

// f o r i = 1 : Mid // x3 ( i ) = 1 ; // end // f o r i = Mid +1: l e n g t h ( t 3 ) // x3 ( i ) = 1 t 4 ( i Mid ) ; // end figure a = gca () ; plot2d ( t1 , x (1: $ -1) ) a . thickness =2; xtitle ( The s i g n a l x ( t ) ) figure a = gca () ; plot2d ( t2 , x (1: $ -1) ) a . thickness =2; a . y_location = m i d d l e ; xtitle ( The s i g n a l x ( t +1) ) figure a = gca () ; plot2d ( t2 , x ( $ : -1:2) ) a . thickness =2; a . y_location = m i d d l e ; xtitle ( The s i g n a l x( t +1) ) Example 1.2 Time Scaling

1 2 3 4 5 6 7 8 9 10 11 12

// Example 1 . 2 : Time S c a l i n g //SIGNALS & SYSTEMS , S e c o n d E d i t i o n //V . OPPENHEIM, S . WILLSKY , S . HAMID NAMWAB // PHI , 2 0 0 8 E d i t i o n // Page 11 clear all ; clc ; close ; t3 = 0:1/100:4/3; t4 = 0:1/ length ( t3 ) :1; Mid = ceil ( length ( t3 ) /2) ; for i = 1: Mid 12

13 14 15 16 17 18 19 20 21 22

x3 ( i ) = 1 ; end for i = Mid +1: length ( t3 ) x3 ( i ) = 1 - t4 (i - Mid ) ; end figure a = gca () ; plot2d ( t3 , x3 ) a . thickness =2; xtitle ( Time S c a l i n g x ( 3 t / 2 ) ) Example 1.3 Time Scaling and Time Shifting

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

// Example 1 . 3 : Time S c a l i n g and Time S h i f t i n g //SIGNALS & SYSTEMS , S e c o n d E d i t i o n //V . OPPENHEIM, S . WILLSKY , S . HAMID NAMWAB // PHI , 2 0 0 8 E d i t i o n // Page 11 clear all ; clc ; close ; t3 = 0:1/100:4/3; t4 = 0:1/ length ( t3 ) :1; Mid = ceil ( length ( t3 ) /2) ; for i = 1: Mid x3 ( i ) = 1 ; end for i = Mid +1: length ( t3 ) x3 ( i ) = 1 - t4 (i - Mid ) ; end t5 = -2/3:1/100:2/3; figure a = gca () ; plot2d ( t5 , x3 ) a . thickness =2; a . y_location = m i d d l e ; xtitle ( Time S c a l i n g and Time S h i f t i n g x ( ( 3 t / 2 ) +1) )

13

Example 1.4 Combinationation two periodic signals Aperiodic signal


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// Example 1 . 4 : C o m b i n a t i o n a t i o n two p e r i o d i c s i g n a l s // A p e r i o d i c s i g n a l // Page 12 clear all ; clc ; close ; F =1; // F r e q u e n c y = 1 Hz t1 = 0: -1/100: -2* %pi ; x1 = cos ( F * t1 ) ; t2 = 0:1/100:2* %pi ; x2 = sin ( F * t2 ) ; a = gca () ; plot ( t2 , x2 ) ; plot ( t1 , x1 ) ; a . y_location = m i d d l e ; a . x_location = m i d d l e ; xtitle ( The s i g n a l x ( t ) = c o s t f o r t < 0 and s i n t for t > 0: Aperiodic Signal ) Example 1.5 sum of two complex exponentials as a single sinusoid

1 2 3 4 5 6 7 8 9 10 11 12 13

// Example 1 . 5 : To e x p r e s s sum o f two c o m p l e x exponentials // a s a s i n g l e s i n u s o i d clear all ; clc ; close ; t =0:1/100:2* %pi ; x1 = exp ( sqrt ( -1) *2* t ) ; x2 = exp ( sqrt ( -1) *3* t ) ; x = x1 + x2 ; for i = 1: length ( x ) X ( i ) = sqrt (( real ( x ( i ) ) .^2) +( imag ( x ( i ) ) .^2) ) ; end plot (t , X ) ;

14

14

xtitle ( F u l l wave r e c t i f i e d s i n u s o i d , t i m e t , Magnitude ) ;

Figure 1.1: Results of Exa 1.5 Example 1.6 Determining the fundamental period of composite discrete time signal // Example 1 . 6 : D e t e r m i n e t h e f u n d a m e n t a l p e r i o d o f composite 2 // d i s c r e t e t i m e s i g n a l 3 // x [ n ] = exp ( j ( 2 %pi / 3 ) n )+exp ( j ( 3 %pi / 4 ) n ) 4 clear all ;
1

15

5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

clc ; close ; Omega1 = 2* %pi /3; // A n g u l a r f r e q u e n c y s i g n a l 1 Omega2 = 3* %pi /4; // A n g u l a r f r e q u e n c y s i g n a l 2 N1 = (2* %pi ) / Omega1 ; // P e i r o d o f s i g n a l 1 N2 = (2* %pi ) / Omega2 ; // P e r i o d o f s i g n a l 2 //To f i n d r a t i o n a l p e r i o d o f s i g n a l 1 for m1 = 1:100 period = N1 * m1 ; if ( modulo ( period ,1) ==0) period1 = period ; integer_value = m1 break ; end end //To f i n d r a t i o n a l p e r i o d o f s i g n a l 2 for m2 = 1:100 period = N2 * m2 ; if ( modulo ( period ,1) ==0) period2 = period ; integer_value = m2 break ; end end disp ( period1 ) disp ( period2 ) //To d e t e r m i n e t h e f u n d a m e n t a l p e r i o d N N = period1 * period2 Example 1.12 Classication of system:Causality property

1 2 3 4 5

// Example 1 . 1 2 : C l a s s i f i c a t i o n o f s y s t e m : C a u s a l i t y property // Page 47 //To c h e c k w h e t h e r t h e g i v e n d i s c r e t e s y s t e m i s a C a u s a l System ( o r ) Non C a u s a l System // Given d i s c r e t e s y s t e m y [ n ]= x[ n ] clear ; 16

6 clc ; 7 x = [2 ,4 ,6 ,8 ,10 ,0 ,0 ,0 ,1]; 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

// A s s i g n some v a l u e t o input n = - length ( x ) /2: length ( x ) /2; count = 0; mid = ceil ( length ( x ) /2) ; y = zeros (1 , length ( x ) ) ; y ( mid +1: $ ) = x ( $ : -1: mid +1) ; for n = -1: -1: - mid y ( n +1+ mid ) = x ( - n ) ; end for i = 1: length ( x ) if ( y ( i ) == x ( i ) ) count = count +1; end end if ( count == length ( x ) ) disp ( The g i v e n s y s t e m i s a c a u s a l s y s t e m ) else disp ( S i n c e i t d e p e n d s on f u t u r e i n p u t v a l u e ) disp ( The g i v e n s y s t e m i s a non c a u s a l s y s t e m ) end

Example 1.13 Determination of stablility of a given system


1 2 3 4 5 6 7 8 9 10 11 12

// Example 1 . 1 3 : D e t e r m i n a t i o n o f s t a b l i l i t y o f a given system // Page 49 // g i v e n s y s t e m y ( t ) = t . x ( t ) clear ; clc ; x = [1 ,2 ,3 ,4 ,0 ,2 ,1 ,3 ,5 ,8]; // A s s i g n some i n p u t Maximum_Limit = 10; S = 0; for t = 0: Maximum_Limit -1 S = S + t * x ( t +1) ; end if ( S > Maximum_Limit ) 17

13 14 15 16 17 18 19 20 21

disp ( Eventhough i n p u t i s bounded o u t p u t i s unbounded ) disp ( The g i v e n s y s t e m i s u n s t a b l e ) ; disp ( S = ) ; S else disp ( The g i v e n s y s t e m i s s t a b l e ) ; disp ( The v a l u e o f S = ) ; S end Example 1.13b Determination of stability of a given system

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

// Example 1 . 1 3 ( b ) : D e t e r m i n a t i o n o f s t a b i l i t y o f a given system // Page 50 // g i v e n s y s t e m y ( t ) = exp ( x ( t ) ) clear ; clc ; Maximum_Limit = 10; S = 0; for t = 0: Maximum_Limit -1 x ( t +1) = -2^ t ; // I n p u t some bounded v a l u e S = S + exp ( x ( t +1) ) ; end if ( S > Maximum_Limit ) disp ( Eventhough i n p u t i s bounded o u t p u t i s unbounded ) disp ( The g i v e n s y s t e m i s u n s t a b l e ) ; disp ( S = ) ; S else disp ( The g i v e n s y s t e m i s s t a b l e ) ; disp ( S ) ; end Example 1.14 Classication of a system:Time Invariance Property 18

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

// Example 1 . 1 4 : c l a s s i f i c a t i o n o f a s y s t e m : Time Invariance Property // Page 51 //To c h e c k w h e t h e r t h e g i v e n s y s t e m i s a Time v a r i a n t ( o r ) Time In v a r i a n t // The g i v e n d i s c r e t e s i g n a l i s y ( t ) = s i n ( x ( t ) ) clear ; clc ; to = 2; // Assume t h e amount o f t i m e s h i f t =2 T = 10; // Length o f g i v e n signal for t = 1: T x ( t ) = (2* %pi / T ) * t ; y ( t ) = sin ( x ( t ) ) ; end // F i r s t s h i f t t h e i n p u t s i g n a l o n l y Input_shift = sin ( x (T - to ) ) ; Output_shift = y (T - to ) ; if ( Input_shift == Output_shift ) disp ( The g i v e n d i s c r e t e s y s t e m i s a Time In v a r i a n t system ); else disp ( The g i v e n d i s c r e t e s y s t e m i s a Time V a r i a n t system ); end

19

Figure 1.2: Results of Exa 1.14 Example 1.15 Classication of a System:Time Invariance Property
1 2 3 4 5 6 7 8

// Example 1 . 1 5 : C l a s s i f i c a t i o n o f a System : Time Invariance Property // Page 51 //To c h e c k w h e t h e r t h e g i v e n s y s t e m i s a Time v a r i a n t ( o r ) Time In v a r i a n t // The g i v e n d i s c r e t e s i g n a l i s y [ n ] = n . x [ n ] clear ; clc ; no = 2; // Assume t h e amount o f t i m e s h i f t =2 L = 10; // Length o f g i v e n signal 20

9 for n = 1: L 10 x(n) = n; 11 y(n) = n*x(n); 12 end 13 // F i r s t s h i f t t h e i n p u t s i g n a l o n l y 14 Input_shift = x (L - no ) ; 15 Output_shift = y (L - no ) ; 16 if ( Input_shift == Output_shift ) 17 disp ( The g i v e n d i s c r e t e s y s t e m i s a Time In

v a r i a n t system );
18 19

else disp ( The g i v e n d i s c r e t e s y s t e m i s a Time V a r i a n t system ); 20 end Example 1.16 Classication of system:Time Invariance Property
1 2 3

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

// Example 1 . 1 6 : C l a s s i f i c a t i o n o f s y s t e m : Time Invariance Property // Page 52 //To c h e c k w h e t h e r t h e g i v e n s y s t e m i s a Time v a r i a n t ( o r ) Time In v a r i a n t // The g i v e n d i s c r e t e s i g n a l i s y ( t ) = x ( 2 t ) clear ; clc ; to = 2; // Assume t h e amount o f t i m e s h i f t =2 T = 10; // Length o f g i v e n signal x = [1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10]; y = zeros (1 , length ( x ) ) ; for t = 1: length ( x ) /2 y ( t ) = x (2* t ) ; end // F i r s t s h i f t t h e i n p u t s i g n a l o n l y Input_shift = x (T - to ) ; Output_shift = y (T - to ) ; if ( Input_shift == Output_shift ) disp ( The g i v e n d i s c r e t e s y s t e m i s a Time In v a r i a n t system ); 21

19 20

else disp ( The g i v e n d i s c r e t e s y s t e m i s a Time V a r i a n t system ); 21 end Example 1.17 Classication of system:Linearity Property
1 2 3

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

// Example 1 . 1 7 : C l a s s i f i c a t i o n o f s y s t e m : L i n e a r i t y Property // Page 54 //To c h e c k w h e t h e r t h e g i v e n d i s c r e t e s y s t e m i s a L i n e a r System ( o r ) Non L i n e a r System // Given d i s c r e t e s y s t e m y ( t )= t x ( t ) clear ; clc ; x1 = [1 ,1 ,1 ,1]; x2 = [2 ,2 ,2 ,2]; a = 1; b = 1; for t = 1: length ( x1 ) x3 ( t ) = a * x1 ( t ) + b * x2 ( t ) ; end for t = 1: length ( x1 ) y1 ( t ) = t * x1 ( t ) ; y2 ( t ) = t * x2 ( t ) ; y3 ( t ) = t * x3 ( t ) ; end for t = 1: length ( y1 ) z ( t ) = a * y1 ( t ) + b * y2 ( t ) ; end count = 0; for n =1: length ( y1 ) if ( y3 ( t ) == z ( t ) ) count = count +1; end end if ( count == length ( y3 ) )

22

29 30 31 32 33 34 35 36

disp ( S i n c e I t s a t i s i f i e s t h e s u p e r p o s i t i o n principle ) disp ( The g i v e n s y s t e m i s a L i n e a r s y s t e m ) y3 z else disp ( S i n c e I t d o e s n o t s a t i s i f y t h e superposition principle ) disp ( The g i v e n s y s t e m i s a Non L i n e a r s y s t e m ) end Example 1.18 Classsication of a system:Linearity Property

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

// Example 1 . 1 8 : C l a s s s i f i c a t i o n o f a s y s t e m : L i n e a r i t y Property // Page 54 //To c h e c k w h e t h e r t h e g i v e n d i s c r e t e s y s t e m i s a L i n e a r System ( o r ) Non L i n e a r System // Given d i s c r e t e s y s t e m y ( t )= ( x ( t ) 2 ) clear ; clc ; x1 = [1 ,1 ,1 ,1]; x2 = [2 ,2 ,2 ,2]; a = 1; b = 1; for t = 1: length ( x1 ) x3 ( t ) = a * x1 ( t ) + b * x2 ( t ) ; end for t = 1: length ( x1 ) y1 ( t ) = ( x1 ( t ) ^2) ; y2 ( t ) = ( x2 ( t ) ^2) ; y3 ( t ) = ( x3 ( t ) ^2) ; end for t = 1: length ( y1 ) z ( t ) = a * y1 ( t ) + b * y2 ( t ) ; end count = 0; for n =1: length ( y1 ) 23

24 if ( y3 ( t ) == z ( t ) ) 25 count = count +1; 26 end 27 end 28 if ( count == length ( y3 ) ) 29 disp ( S i n c e I t s a t i s i f i e s 30 31 32 33 34

the s u p e r p o s i t i o n

principle ) disp ( The g i v e n s y s t e m i s a L i n e a r s y s t e m ) y3 z else disp ( S i n c e I t d o e s n o t s a t i s i f y t h e superposition principle ) 35 disp ( The g i v e n s y s t e m i s a Non L i n e a r s y s t e m ) 36 end Example 1.20 Classsication of a system:Linearity Property
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

// Example 1 . 2 0 : C l a s s s i f i c a t i o n o f a s y s t e m : L i n e a r i t y Property // Page 55 //To c h e c k w h e t h e r t h e g i v e n d i s c r e t e s y s t e m i s a L i n e a r System ( o r ) Non L i n e a r System // Given d i s c r e t e s y s t e m y [ n ] ) = 2 x [ n ]+3 clear ; clc ; x1 = [1 ,1 ,1 ,1]; x2 = [2 ,2 ,2 ,2]; a = 1; b = 1; for n = 1: length ( x1 ) x3 ( n ) = a * x1 ( n ) + b * x2 ( n ) ; end for n = 1: length ( x1 ) y1 ( n ) = 2* x1 ( n ) +3; y2 ( n ) = 2* x2 ( n ) +3; y3 ( n ) = 2* x3 ( n ) +3; end 24

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

for n = 1: length ( y1 ) z ( n ) = a * y1 ( n ) + b * y2 ( n ) ; end count = 0; for n =1: length ( y1 ) if ( y3 ( n ) == z ( n ) ) count = count +1; end end if ( count == length ( y3 ) ) disp ( S i n c e I t s a t i s i f i e s t h e s u p e r p o s i t i o n principle ) disp ( The g i v e n s y s t e m i s a L i n e a r s y s t e m ) y3 z else disp ( S i n c e I t d o e s n o t s a t i s i f y t h e superposition principle ) disp ( The g i v e n s y s t e m i s a Non L i n e a r s y s t e m ) end

25

Chapter 2 Linear Time Invariant Systems


2.1 Scilab Codes

Example 2.1 Linear Convolution Sum


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

// Example 2 . 1 : L i n e a r C o n v o l u t i o n Sum // p a g e 80 clear all ; close ; clc ; h = [0 ,0 ,1 ,1 ,1 ,0 ,0]; N1 = -2:4; x = [0 ,0 ,0.5 ,2 ,0 ,0 ,0]; N2 = -2:4; y = convol (x , h ) ; for i = 1: length ( y ) if ( y ( i ) <=0.0001) y ( i ) =0; end end N = -4:8; figure a = gca () ; plot2d3 ( gnn ,N1 , h ) xtitle ( I m p u l s e R e s p o n s e , n , h [ n ] ) ;

26

21 22 23 24 25 26 27 28 29 30 31

a . thickness = 2; figure a = gca () ; plot2d3 ( gnn ,N2 , x ) xtitle ( I n p u t R e s p o n s e , n , x [ n ] ) ; a . thickness = 2; figure a = gca () ; plot2d3 ( gnn ,N , y ) xtitle ( Output R e s p o n s e , n , y [ n ] ) ; a . thickness = 2;

Figure 2.1: Results of Exa 2.1 27

Figure 2.2: Results of Exa 2.1

28

Figure 2.3: Results of Exa 2.1 Example 2.3 Convolution Sum:Convolution of x[n] and Unit Impulse response h[n]
1 2 3 4 5 6 7 8

// Example 2 . 3 : C o n v o l u t i o n Sum : C o n v o l u t i o n o f x [ n ] and // U n i t I m p u l s e r e s p o n s e h [ n ] clear ; close ; clc ; Max_Limit = 10; h = ones (1 , Max_Limit ) ; N1 = 0: Max_Limit -1; 29

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

Alpha = 0.5; // a l p h a < 1 for n = 1: Max_Limit x ( n ) = ( Alpha ^( n -1) ) *1; end N2 = 0: Max_Limit -1; y = convol (x , h ) ; N = 0:2* Max_Limit -2; figure a = gca () ; plot2d3 ( gnn ,N1 , h ) xtitle ( I m p u l s e R e s p o n s e F i g 2 . 5 . ( b ) , n , h [ n ] ) ; a . thickness = 2; figure a = gca () ; plot2d3 ( gnn ,N2 , x ) xtitle ( I n p u t R e s p o n s e F i g 2 . 5 . ( a ) , n , x [ n ] ) ; a . thickness = 2; figure a = gca () ; plot2d3 ( gnn ,N (1: Max_Limit ) ,y (1: Max_Limit ) ,5) xtitle ( Output R e s p o n s e F i g 2 . 7 , n , y [ n ] ) ; a . thickness = 2;

30

Figure 2.4: Results of Exa 2.3

31

Figure 2.5: Results of Exa 2.3

32

Figure 2.6: Results of Exa 2.3 Example 2.4 Convolution Sum of nite duration sequences
1 2 3 4 5 6 7 8 9

// Example 2 . 4 : C o n v o l u t i o n Sum o f f i n i t e d u r a t i o n sequences clear ; close ; clc ; x = ones (1 ,5) ; N1 =0: length ( x ) -1; Alpha = 1.4; // a l p h a > 1 for n = 1:7 h ( n ) = ( Alpha ^( n -1) ) *1; 33

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

end N2 =0: length ( h ) -1; y = convol (x , h ) ; N = 0: length ( x ) + length ( h ) -2; figure a = gca () ; plot2d3 ( gnn ,N2 , h ) xtitle ( I m p u l s e R e s p o n s e , n , h [ n ] ) ; a . thickness = 2; figure a = gca () ; plot2d3 ( gnn ,N1 , x ) xtitle ( I n p u t R e s p o n s e , n , x [ n ] ) ; a . thickness = 2; figure a = gca () ; plot2d3 ( gnn ,N , y ) xtitle ( Output R e s p o n s e , n , y [ n ] ) ; a . thickness = 2;

34

Figure 2.7: Results of Exa 2.4

35

Figure 2.8: Results of Exa 2.4

36

Figure 2.9: Results of Exa 2.4 Example 2.5 Convolution Sum of input sequence x[n] = (2n ).u[n]andh[n] = u[n]
1 2 3 4 5 6 7 8

// Example 2 . 5 : C o n v o l u t i o n Sum o f i n p u t s e q u e n c e x [ n ] = ( 2 n ) . u[ n ] // and h [ n ] = u [ n ] clear ; close ; clc ; Max_Limit = 10; h = ones (1 , Max_Limit ) ; N2 =0: length ( h ) -1; 37

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

for n = 1: Max_Limit x1 ( n ) = (2^( -( n -1) ) ) *1; end x = x1 ( $ : -1:1) ; N1 = - length ( x ) +1:0; y = convol (x , h ) ; N = - length ( x ) +1: length ( h ) -1; figure a = gca () ; plot2d3 ( gnn ,N2 , h ) xtitle ( I m p u l s e R e s p o n s e , n , h [ n ] ) ; a . thickness = 2; figure a = gca () ; a . y_location = o r i g i n ; plot2d3 ( gnn ,N1 , x ) xtitle ( I n p u t R e s p o n s e F i g 2 . 1 1 ( a ) , n , x [ n ] ) ; a . thickness = 2; figure a = gca () ; a . y_location = o r i g i n ; plot2d3 ( gnn ,N , y ) xtitle ( Output R e s p o n s e F i g 2 . 1 1 ( b ) , n , y [ n ] ) ; a . thickness = 2;

38

Figure 2.10: Results of Exa 2.5

39

Figure 2.11: Results of Exa 2.5

40

Figure 2.12: Results of Exa 2.5 Example 2.6 onvolution Integral of input x(t) = (e at).u(t)andh(t) = u(t)
1 2 3 4 5 6 7 8 9

// Example 2 . 6 : C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) = ( e a t ) . u ( t ) // and h ( t ) =u ( t ) clear ; close ; clc ; Max_Limit = 10; h = ones (1 , Max_Limit ) ; N2 =0: length ( h ) -1; a = 0.5; // c o n s t a n t a >0 41

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

for t = 1: Max_Limit x ( t ) = exp ( - a *( t -1) ) ; end N1 =0: length ( x ) -1; y = convol (x , h ) -1; N = 0: length ( x ) + length ( h ) -2; figure a = gca () ; plot2d ( N2 , h ) xtitle ( I m p u l s e R e s p o n s e , t , h ( t ) ) ; a . thickness = 2; figure a = gca () ; plot2d ( N1 , x ) xtitle ( I n p u t R e s p o n s e , t , x ( t ) ) ; a . thickness = 2; figure a = gca () ; plot2d ( N (1: Max_Limit ) ,y (1: Max_Limit ) ) xtitle ( Output R e s p o n s e , t , y ( t ) ) ; a . thickness = 2;

42

Figure 2.13: Results of Exa 2.6

43

Figure 2.14: Results of Exa 2.6

44

Figure 2.15: Results of Exa 2.6 Example 2.7 Convolution Integral of ntie duration signals
1 2 3 4 5 6 7 8 9

// Example 2 . 7 : C o n v o l u t i o n I n t e g r a l o f f i n t i e duration s ign als // p a g e 9 9 clear ; close ; clc ; T = 10; x = ones (1 , T ) ; // I n p u t R e s p o n s e for t = 1:2* T h ( t ) = t -1; // I m p u l s e R e s p o n s e 45

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

end N1 = 0: length ( x ) -1; N2 = 0: length ( h ) -1; y = convol (x , h ) ; N = 0: length ( x ) + length ( h ) -2; figure a = gca () ; a . x_location = o r i g i n ; plot2d ( N2 , h ) xtitle ( I m p u l s e R e s p o n s e , t , h ( t ) ) ; a . thickness = 2; figure a = gca () ; plot2d ( N1 , x ) xtitle ( I n p u t R e s p o n s e , t , x ( t ) ) ; a . thickness = 2; figure a = gca () ; plot2d (N , y ) xtitle ( Output R e s p o n s e , t , y ( t ) ) ; a . thickness = 2;

46

Figure 2.16: Results of Exa 2.7

47

Figure 2.17: Results of Exa 2.7

48

Figure 2.18: Results of Exa 2.7 Example 2.8 Convolution Integral of input x(t) = (e2 t).u(t)andh(t) = u(t 3)
1 2 3 4 5 6 7 8

// Example 2 . 8 : C o n v o l u t i o n I n t e g r a l o f i n p u t x ( t ) =( e 2 t ) . u( t ) and // h ( t ) = u ( t 3) clear ; close ; clc ; Max_Limit = 10; h =[0 ,0 ,0 , ones (1 , Max_Limit -3) ]; // h ( n 3) a = 2; 49

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

t = -9:0; x = exp ( a * t ) ; // x = x1 ( $ : 1 : 1 ) N2 = 0: length ( h ) -1; N1 = - length ( x ) +1:0; t1 = -6:3; y1 = (1/ a ) * exp ( a *( t1 -3) ) ; y2 = (1/ a ) * ones (1 , Max_Limit ) ; y = [ y1 y2 ] N = - length ( h ) +1: length ( x ) -1; figure a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot2d ( - Max_Limit +1:0 , h ( $ : -1:1) ) xtitle ( I m p u l s e R e s p o n s e , t , h ( t T) ) ; a . thickness = 2; figure a = gca () ; a . y_location = o r i g i n ; plot2d (t , x ) xtitle ( I n p u t R e s p o n s e , t , x ( t ) ) ; a . thickness = 2; figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -10 ,0;13 ,1]; plot2d ( - Max_Limit +4: Max_Limit +3 , y ) xtitle ( Output R e s p o n s e , t , y ( t ) ) ; a . thickness = 2;

50

Figure 2.19: Results of Exa 2.8

51

Figure 2.20: Results of Exa 2.8

52

Figure 2.21: Results of Exa 2.8

53

Chapter 3 Fourier Series Repreentation of Periodic Signals


3.1 Scilab Codes

Example 3.2 CTFS of a periodic signal x(t)Expression of continuous time signal


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// Example 3 . 2 : CTFS o f a p e r i o d i c s i g n a l x ( t ) // E x p r e s s i o n o f c o n t i n u o u s t i m e s i g n a l // u s i n g c o n t i n u o u s t i m e f o u r i e r s e r i e s clear ; close ; clc ; t = -3:0.01:3; // t 1 = %pi 4 : ( %pi 4 ) / 1 0 0 : %pi 4 ; // t 2 =%pi 6 : ( %pi 6 ) / 1 0 0 : %pi 6 ; xot = ones (1 , length ( t ) ) ; x1t = (1/2) * cos ( %pi *2* t ) ; xot_x1t = xot + x1t ; x2t = cos ( %pi *4* t ) ; xot_x1t_x2t = xot + x1t + x2t ; x3t = (2/3) * cos ( %pi *6* t ) ; xt = xot + x1t + x2t + x3t ; //

54

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 ,0;2 4]; plot (t , xot ) ylabel ( t ) title ( x o t =1 ) // figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 , -3;2 4]; plot (t , x1t ) ylabel ( t ) title ( x1 ( t ) =1/2 c o s ( 2 p i t ) ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 ,0;2 4]; plot (t , xot_x1t ) ylabel ( t ) title ( xo ( t )+x1 ( t ) ) // figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 , -2;4 2]; plot (t , x2t ) ylabel ( t ) title ( x2 ( t ) =c o s ( 4 p i t ) ) subplot (2 ,1 ,2) a = gca () ; 55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 ,0;4 4]; plot (t , xot_x1t_x2t ) ylabel ( t ) title ( xo ( t )+x1 ( t )+x2 ( t ) ) // figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 , -3;4 3]; plot (t , x3t ) ylabel ( t ) title ( x1 ( t ) =2/3 c o s ( 6 p i t ) ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -4 , -3;4 3]; plot (t , xt ) ylabel ( t ) title ( x ( t )=xo ( t )+x1 ( t )+x2 ( t )+x3 ( t ) )

56

Figure 3.1: Results of Exa 3.2

57

Figure 3.2: Results of Exa 3.2

58

Figure 3.3: Results of Exa 3.2

59

Figure 3.4: Results of Exa 3.2 Example 3.3 Continuous Time Fourier Series Coecients of a periodic signal x(t) = sin(W ot)
1 2 3 4 5 6 7 8

// Example3 . 3 : C o n t i n u o u s Time F o u r i e r S e r i e s Coefficients of // a p e r i o d i c s i g n a l x ( t ) = s i n ( Wot ) clear ; close ; clc ; t = 0:0.01:1; T = 1; Wo = 2* %pi / T ; 60

9 10 11 12 13 14 15 16 17 18

xt = sin ( Wo * t ) ; for k =0:5 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * t .* k ) ; a ( k +1) = xt * C ( k +1 ,:) / length ( t ) ; if ( abs ( a ( k +1) ) <=0.01) a ( k +1) =0; end end a =a ; ak = [ -a , a (2: $ ) ]; Example 3.4 CTFS coecients of a periodic signal x(t) = 1 + sin(W ot) + 2cos(W ot) + cos(2W ot + pi/4)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

// Example3 . 4 : CTFS c o e f f i c i e n t s o f a p e r i o d i c s i g n a l // x ( t ) = 1+ s i n ( Wot ) +2 c o s ( Wot )+c o s ( 2 Wot+%pi / 4 ) clear ; close ; clc ; t = 0:0.01:1; T = 1; Wo = 2* %pi / T ; xt = ones (1 , length ( t ) ) + sin ( Wo * t ) +2* cos ( Wo * t ) + cos (2* Wo * t + %pi /4) ; for k =0:5 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * t .* k ) ; a ( k +1) = xt * C ( k +1 ,:) / length ( t ) ; if ( abs ( a ( k +1) ) <=0.1) a ( k +1) =0; end end a =a ; a_conj = conj ( a ) ; ak = [ a_conj ( $ : -1:1) ,a (2: $ ) ]; Mag_ak = abs ( ak ) ; for i = 1: length ( a ) Phase_ak ( i ) = atan ( imag ( ak ( i ) ) /( real ( ak ( i ) ) +0.0001) ) ; 61

23 24 25 26 27 28 29 30 31 32 33 34 35

end Phase_ak = Phase_ak Phase_ak = [ Phase_ak (1: $ ) - Phase_ak ($ -1: -1:1) ]; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,[ - k : k ] , Mag_ak ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( a b s ( ak ) ) xlabel ( k ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,[ - k : k ] , Phase_ak ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( <(ak ) ) xlabel ( k )

36 37 38 39 40 41 42 43 44

62

Figure 3.5: Results of Exa 3.4 Example 3.5 CTFS coecients of a periodic signal x(t) = 1, |t| < T 1, and0, T 1 < |t| < T /2
1 2 3 4 5 6 7 8 9

// Example3 . 5 : CTFS c o e f f i c i e n t s o f a p e r i o d i c s i g n a l // x ( t ) = 1 , | t | < T1 , and 0 , T1 < | t | <T/2 clear ; close ; clc ; T =4; T1 = T /4; t = - T1 : T1 /100: T1 ; Wo = 2* %pi / T ; 63

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

xt = ones (1 , length ( t ) ) ; // for k =0:5 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * t .* k ) ; a ( k +1) = xt * C ( k +1 ,:) / length ( t ) ; if ( abs ( a ( k +1) ) <=0.1) a ( k +1) =0; end end a =a ; a_conj = real ( a (:) ) - sqrt ( -1) * imag ( a (:) ) ; ak = [ a_conj ( $ : -1:1) ,a (2: $ ) ]; k = 0:5; k = [ - k ( $ : -1:1) ,k (2: $ ) ]; Spectrum_ak = (1/2) * real ( ak ) ; // figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -2 ,0;2 ,2]; plot2d (t , xt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( x ( t ) ) xlabel ( t )

36 // 37 figure 38 a = gca () ; 39 a . y_location = o r i g i n ; 40 a . x_location = o r i g i n ; 41 plot2d3 ( gnn ,k , Spectrum_ak ,5) 42 poly1 = a . children (1) . children (1) ; 43 poly1 . thickness = 3; 44 title ( a b s ( ak ) ) 45 xlabel (

64

k )

Figure 3.6: Results of Exa 3.5

65

Figure 3.7: Results of Exa 3.5 Example 3.6 Time Shift Property of CTFS
1 2 3 4 5 6 7 8 9 10

// Example3 . 6 : Time S h i f t P r o p e r t y o f CTFS clear ; close ; clc ; T =4; T1 = T /2; t = 0: T1 /100: T1 ; Wo = 2* %pi / T ; gt =(1/2) * ones (1 , length ( t ) ) ; a (1) =0; // k =0 , ak =0 66

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

d (1) =0; for k =1:5 a ( k +1) = ( sin ( %pi * k /2) /( k * %pi ) ) ; if ( abs ( a ( k +1) ) <=0.01) a ( k +1) =0; end d ( k +1) = a ( k +1) * exp ( - sqrt ( -1) * k * %pi /2) ; end k = 0:5 disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f S q u a r e Wave ) a disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f g ( t )=x ( t 1) 0.5 ) d // figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -1 , -2;1 ,4]; plot2d ([ - t ( $ : -1:1) ,t (1: $ ) ] ,[ - gt , gt ] ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( g ( t ) ) xlabel ( t )

67

Figure 3.8: Results of Exa 3.6 Example 3.7 Derivative Property of CTFS
1 2 3 4 5 6 7 8 9 10

// Example3 . 7 : D e r i v a t i v e P r o p e r t y o f CTFS clear ; clc ; close ; T =4; T1 = T /2; t = 0: T1 /100: T1 ; xt = [ t ( $ : -1:1) t ]/ T1 ; gt =(1/2) * ones (1 , length ( t ) ) ; e (1) = 1/2; // k =0 , e 0 = 1/2 68

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

for k =1:5 a ( k +1) = ( sin ( %pi * k /2) /( k * %pi ) ) ; if ( abs ( a ( k +1) ) <=0.01) a ( k +1) =0; end d ( k +1) = a ( k +1) * exp ( - sqrt ( -1) * k * %pi /2) ; e ( k +1) = 2* d ( k +1) /( sqrt ( -1) * k * %pi ) ; end k = 0:5 disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f S q u a r e Wave ) a disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f g ( t )=x ( t 1) 0.5 ) d disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f T r i a n g u l a r Wave ) e // P l o t t i n g t h e t i m e s h i f t e d s q u a r e waveform figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -1 , -2;1 ,2]; plot2d ([ - t ( $ : -1:1) ,t (1: $ ) ] ,[ - gt , gt ] ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( g ( t ) ) xlabel ( t ) // P l o t t i n g t h e T r i a n g u l a r waveform figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -1 ,0;1 ,2]; plot2d ([ - t ( $ : -1:1) ,t (1: $ ) ] , xt ,5) poly1 = a . children (1) . children (1) ; 69

37 38 39 40 41 42 43 44

45 46 47

poly1 . thickness = 3; title ( x ( t ) ) xlabel ( t )

Figure 3.9: Results of Exa 3.7

70

Figure 3.10: Results of Exa 3.7 Example 3.8 Fourier Series Representation of Periodic Impulse Train
1 2 3 4 5 6 7 8

// Example3 . 8 : F o u r i e r S e r i e s R e p r e s e n t a t i o n o f P e r i o d i c Impulse Train clear ; clc ; close ; T =4; T1 = T /4; t = [ -T ,0 , T ]; xt = [1 ,1 ,1]; // G e n e r a t i o n o f P e r i o d i c t r a i n o f Impulses 71

9 t1 = - T1 : T1 /100: T1 ; 10 gt = ones (1 , length ( t1 ) ) ; // G e n e r a t i o n o f 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

periodic s q u a r e wave t2 = [ - T1 ,0 , T1 ]; qt = [1 ,0 , -1]; // D e r i v a t i v e o f p e r i o d i c s q u a r e wave Wo = 2* %pi / T ; ak = 1/ T ; b (1) = 0; c (1) = 2* T1 / T ; for k =1:5 b ( k +1) = ak *( exp ( sqrt ( -1) * k * Wo * T1 ) - exp ( - sqrt ( -1) * k * Wo * T1 ) ) ; if ( abs ( b ( k +1) ) <=0.1) b ( k +1) =0; end c ( k +1) = b ( k +1) /( sqrt ( -1) * k * Wo ) ; if ( abs ( c ( k +1) ) <=0.1) c ( k +1) =0; end end k = 0:5 disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f p e r i o d i c S q u a r e Wave ) disp ( b ) disp ( F o u r i e r S e r i e s C o e f f i c i e n t s o f d e r i v a t i v e o f p e r i o d i c s q u a r e wave ) disp ( c ) // P l o t t i n g t h e p e r i o d i c t r a i n o f i m p u l s e s figure subplot (3 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -6 ,0;6 ,2]; plot2d3 ( gnn ,t , xt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( x ( t ) ) 72

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

// P l o t t i n g t h e p e r i o d i c s q u a r e waveform subplot (3 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -6 ,0;6 ,2]; plot2d ( t1 , gt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d ( T + t1 , gt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d ( - T + t1 , gt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( g ( t ) ) // P l o t t i n g t h e p e r i o d i c s q u a r e waveform subplot (3 ,1 ,3) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -6 , -2;6 ,2]; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn ,t2 , qt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn ,T + t2 , qt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn ,-T + t2 , qt ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( q ( t ) )

73

Figure 3.11: Results of Exa 3.8 Example 3.10 DTFS of x(n) = sin(W on)
1 2 3 4 5 6 7 8 9 10

// Example3 . 1 0 : DTFS o f x [ n ] =s i n (Won) clear ; close ; clc ; n = 0:0.01:5; N = 5; Wo = 2* %pi / N ; xn = sin ( Wo * n ) ; for k =0: N -2 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * n .* k ) ; 74

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

a ( k +1) = xn * C ( k +1 ,:) / length ( n ) ; if ( abs ( a ( k +1) ) <=0.01) a ( k +1) =0; end end a =a a_conj = conj ( a ) ; ak = [ a_conj ( $ : -1:1) ,a (2: $ ) ] k = -(N -2) :( N -2) ; // figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -8 , -1;8 ,1]; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn ,k , - imag ( ak ) ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn ,N +k , - imag ( ak ) ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn , -( N + k ) ,- imag ( ak ( $ : -1:1) ) ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( ak )

75

Figure 3.12: Results of Exa 3.10 Example 3.11 DTFS of x(n) = 1 + sin(2 pi/N ) n + 3 cos(2 pi/N ) n + cos((4 pi/N ) n + pi/2)
1 2 3 4 5 6 7 8

// Example3 . 1 1 : DTFS o f // x [ n ] = 1+ s i n ( 2 %pi /N) n+3 c o s ( 2 %pi /N) n+c o s [ ( 4 %pi /N ) n+%pi / 2 ] clear ; close ; clc ; N = 10; n = 0:0.01: N ; Wo = 2* %pi / N ; 76

9 xn = ones (1 , length ( n ) ) + sin ( Wo * n ) +3* cos ( Wo * n ) + cos (2* Wo 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

* n + %pi /2) ; for k =0: N -2 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * n .* k ) ; a ( k +1) = xn * C ( k +1 ,:) / length ( n ) ; if ( abs ( a ( k +1) ) <=0.1) a ( k +1) =0; end end a =a ; a_conj = conj ( a ) ; ak = [ a_conj ( $ : -1:1) ,a (2: $ ) ]; Mag_ak = abs ( ak ) ; for i = 1: length ( a ) Phase_ak ( i ) = atan ( imag ( ak ( i ) ) /( real ( ak ( i ) ) +0.0001) ) ; end Phase_ak = Phase_ak Phase_ak = [ Phase_ak (1: $ -1) - Phase_ak ( $ : -1:1) ]; k = -(N -2) :( N -2) ; // figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,k , real ( ak ) ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( R e a l p a r t o f ( ak ) ) xlabel ( k )

38 subplot (2 ,1 ,2) 39 a = gca () ; 40 a . y_location = o r i g i n ; 41 a . x_location = o r i g i n ; 42 plot2d3 ( gnn ,k , imag ( ak ) ,5)

77

43 44 45 46

poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( i m a g i n a r y p a r t o f ( ak ) ) xlabel ( k )

47 // 48 figure 49 subplot (2 ,1 ,1) 50 a = gca () ; 51 a . y_location = o r i g i n ; 52 a . x_location = o r i g i n ; 53 plot2d3 ( gnn ,k , Mag_ak ,5) 54 poly1 = a . children (1) . children (1) ; 55 poly1 . thickness = 3; 56 title ( a b s ( ak ) ) 57 xlabel (

58 59 60 61 62 63 64 65 66

k ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,k , Phase_ak ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( <(ak ) ) xlabel ( k )

78

Figure 3.13: Results of Exa 3.11

79

Figure 3.14: Results of Exa 3.11 Example 3.12 DTFS coecients of periodic square wave
1 2 3 4 5 6 7 8 9

// Example3 . 1 2 : DTFS c o e f f i c i e n t s o f p e r i o d i c s q u a r e wave clear ; close ; clc ; N = 10; N1 = 2; Wo = 2* %pi / N ; xn = ones (1 , length ( N ) ) ; n = -(2* N1 +1) :(2* N1 +1) ; 80

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

a (1) = (2* N1 +1) / N ; for k =1:2* N1 a ( k +1) = sin ((2* %pi * k *( N1 +0.5) ) / N ) / sin ( %pi * k / N ) ; a ( k +1) = a ( k +1) / N ; if ( abs ( a ( k +1) ) <=0.1) a ( k +1) =0; end end a =a ; a_conj = conj ( a ) ; ak = [ a_conj ( $ : -1:1) ,a (2: $ ) ]; k = -2* N1 :2* N1 ; // figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,k , real ( ak ) ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( R e a l p a r t o f ( ak ) ) xlabel ( k )

81

Figure 3.15: Results of Exa 3.12 Example 3.13 TFS:Expression of periodic sequence using
1 2 3 4 5 6 7 8 9 10

// Example3 . 1 3 : DTFS // E x p r e s s i o n o f p e r i o d i c s e q u e n c e u s i n g // t h e summation two d i f f e r e n t s e q u e n c e clear ; close ; clc ; N = 5; n = 0: N -1; x1 = [1 ,1 ,0 ,0 ,1]; x1 = [ x1 ( $ : -1:1) x1 (2: $ ) ]; // S q u a r e Wave x1 [ n ] 82

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

x2 = [1 ,1 ,1 ,1 ,1]; x2 = [ x2 ( $ : -1:1) x2 (2: $ ) ]; //DC s e q u e n c e o f x2 [ n ] x = x1 + x2 ; // sum o f x1 [ n ] & x2 [ n ] // Z e r o t h DTFS c o e f f i c i e n t o f dc s e q u e n c e c (1) = 1; // Z e r o t h DTFS c o e f f i c i e n t o f s q u a r e waveform b (1) = 3/5; // Z e r o t h DTFS c o e f f i c i e n t o f sum o f x1 [ n ] & x2 [ n ] a (1) = b (1) + c (1) ; // Wo = 2* %pi / N ; for k =1: N -1 a ( k +1) = sin ((3* %pi * k ) / N ) / sin ( %pi * k / N ) ; a ( k +1) = a ( k +1) / N ; if ( abs ( a ( k +1) ) <=0.1) a ( k +1) =0; end end a =a ; a_conj = conj ( a ) ; ak = [ a_conj ( $ : -1:1) ,a (2: $ ) ]; k = -(N -1) :( N -1) ; n = -(N -1) :( N -1) ; // figure subplot (3 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,n ,x ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( x [ n ] ) xlabel (

n ) 45 subplot (3 ,1 ,2) 46 a = gca () ; 83

47 a . y_location = o r i g i n ; 48 a . x_location = o r i g i n ; 49 plot2d3 ( gnn ,n , x1 ,5) 50 poly1 = a . children (1) . children (1) ; 51 poly1 . thickness = 3; 52 title ( x1 [ n ] ) 53 xlabel (

n )
54 subplot (3 ,1 ,3) 55 a = gca () ; 56 a . y_location = o r i g i n ; 57 a . x_location = o r i g i n ; 58 plot2d3 ( gnn ,n , x2 ,5) 59 poly1 = a . children (1) . children (1) ; 60 poly1 . thickness = 3; 61 title ( x2 [ n ] ) 62 xlabel (

n )

84

Figure 3.16: Results of Exa 3.13 Example 3.14 DTFS:Finding x[n] using parsevals relation of DTFS
1 2 3 4 5 6 7 8 9 10

// Example3 . 1 4 : DTFS // F i n d i n g x [ n ] u s i n g p a r s e v a l s r e l a t i o n o f DTFS clear ; close ; clc ; N = 6; n = 0: N -1; a (1) = 1/3; a (2) =0; a (4) =0; 85

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

a (5) =0; a1 = (1/6) *(( -1) ^ n ) ; x =0; for k = 0: N -2 if ( k ==2) x = x + a1 ; else x = x + a ( k +1) ; end end x = [ x ( $ : -1:1) ,x (2: $ ) ]; n = -(N -1) :( N -1) ; // figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,n ,x ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( x [ n ] ) xlabel ( n )

86

Figure 3.17: Results of Exa 3.14 Example 3.15 DTFS:Periodic Convolution Property
1 2 3 4 5 6 7 8 9 10

// Example3 . 1 5 : DTFS : P e r i o d i c C o n v o l u t i o n P r o p e r t y clear ; clc ; close ; x = [1 ,1 ,0 ,0 ,0 ,0 ,1]; X = fft ( x ) ; W = X .* X ; w = ifft ( W ) ; w = abs ( w ) ; for i =1: length ( x ) 87

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

if ( abs ( w ( i ) ) <=0.1) w ( i ) = 0; end end w = [ w ( $ : -1:1) w (2: $ ) ]; N = length ( x ) ; figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,[ -(N -1) :0 ,1: N -1] , w ,5) poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; title ( w [ n ] ) xlabel ( n )

88

Figure 3.18: Results of Exa 3.15

89

Chapter 4 The Continuous Time Fourier Transform


4.1 Scilab Codes

Example 4.1 Continuous Time Fourier Transform of a Continuous Time Signal x(t) = exp(A t)u(t), t > 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

// Example 4 . 1 : C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f a // C o n t i n u o u s Time S i g n a l x ( t )= exp ( A t ) u ( t ) , t >0 clear ; clc ; close ; // Analog S i g n a l A =1; // A m p l i t u d e Dt = 0.005; t = 0: Dt :10; xt = exp ( - A * t ) ; // // C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = xt * exp ( - sqrt ( -1) *t * W ) * Dt ;

90

18 XW_Mag = abs ( XW ) ; 19 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

48

Wmax t o Wmax XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ]; [ XW_Phase , db ] = phasemag ( XW ) ; XW_Phase = [ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001) ]; // P l o t t i n g C o n t i n u o u s Time S i g n a l figure a = gca () ; a . y_location = o r i g i n ; plot (t , xt ) ; xlabel ( t i n s e c . ) ; ylabel ( x ( t ) ) title ( C o n t i n u o u s Time S i g n a l ) figure // P l o t t i n g Magnitude R e s p o n s e o f CTS subplot (2 ,1 ,1) ; a = gca () ; a . y_location = o r i g i n ; plot (W , XW_Mag ) ; xlabel ( F r e q u e n c y i n R a d i a n s / S e c o n d s > W ) ; ylabel ( a b s (X(jW) ) ) title ( Magnitude R e s p o n s e (CTFT) ) // P l o t t i n g Phase Reponse o f CTS subplot (2 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (W , XW_Phase * %pi /180) ; xlabel ( Frequency in R a d i a n s / S e c o n d s > W ) ; ylabel ( <X (jW) ) title ( Phase R e s p o n s e (CTFT) i n R a d i a n s )

91

Figure 4.1: Results of Exa 4.1

92

Figure 4.2: Results of Exa 4.1 Example 4.2 Continuous Time Fourier Transform of a Continuous Time Signal x(t) = exp(A abs(t))
1 2 3 4 5 6 7 8 9

// Example 4 . 2 : C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f a // C o n t i n u o u s Time S i g n a l x ( t )= exp ( A a b s ( t ) ) clear ; clc ; close ; // Analog S i g n a l A =1; // A m p l i t u d e Dt = 0.005; t = -4.5: Dt :4.5; 93

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

xt = exp ( - A * abs ( t ) ) ; // // C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = xt * exp ( - sqrt ( -1) *t * W ) * Dt ; XW = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax XW = [ mtlb_fliplr ( XW ) , XW (2:1001) ]; subplot (1 ,1 ,1) subplot (2 ,1 ,1) ; a = gca () ; a . y_location = o r i g i n ; plot (t , xt ) ; xlabel ( t i n s e c . ) ; ylabel ( x ( t ) ) title ( C o n t i n u o u s Time S i g n a l ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; plot (W , XW ) ; xlabel ( F r e q u e n c y i n R a d i a n s / S e c o n d s W ) ; ylabel ( X(jW) ) title ( C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m )

94

Figure 4.3: Results of Exa 4.2 Example 4.4 Continuous Time Fourier Transform and Frequency Response of a Square Waveform x(t) = A, f rom T 1toT 1
1 // Example 4 . 4 2 // C o n t i n u o u s Time F o u r i e r T r a n s f o r m 3 // and F r e q u e n c y R e s p o n s e o f a S q u a r e Waveform 4 // x ( t )= A, from T1 t o T1 5 clear ; 6 clc ; 7 close ; 8 // CTS S i g n a l 9 A =1; // A m p l i t u d e

95

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

Dt = 0.005; T1 = 4; // Time i n s e c o n d s t = - T1 /2: Dt : T1 /2; for i = 1: length ( t ) xt ( i ) = A ; end // // C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; xt = xt ; XW = xt * exp ( - sqrt ( -1) *t * W ) * Dt ; XW_Mag = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ]; // subplot (2 ,1 ,1) ; a = gca () ; a . data_bounds =[ -4 ,0;4 ,2]; a . y_location = o r i g i n ; plot (t , xt ) ; xlabel ( t i n msec . ) ; title ( C o n t i u o u s Time S i g n a l x ( t ) ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; plot (W , XW_Mag ) ; xlabel ( F r e q u e n c y i n R a d i a n s / S e c o n d s ) ; title ( C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m X(jW) )

96

Figure 4.4: Results of Exa 4.4 Example 4.5 Inverse Continuous Time Fourier Transform X (jW ) = 1, from -T1 to T1
1 // Example 4 . 5 2 // I n v e r s e C o n t i n u o u s Time F o u r i e r T r a n s f o r m 3 // X(jW)= 1 , from T1 t o T1 4 clear ; 5 clc ; 6 close ; 7 // CTFT 8 A =1; // A m p l i t u d e 9 Dw = 0.005;

97

W1 = 4; // Time i n s e c o n d s w = - W1 /2: Dw : W1 /2; for i = 1: length ( w ) XW ( i ) = A ; end XW = XW ; // // I n v e r s e C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m t = - %pi : %pi / length ( w ) : %pi ; xt =(1/(2* %pi ) ) * XW * exp ( sqrt ( -1) *w * t ) * Dw ; xt = real ( xt ) ; figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (t , xt ) ; xlabel ( t time i n Seconds ); 27 title ( I n v e r s e C o n t i n u o u s Time F o u r i e r T r a n s f o r m x ( t ) )
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

98

Figure 4.5: Results of Exa 4.5 Example 4.6 Continuous Time Fourier Transform of Symmetric periodic Square waveform
1 // Example 4 . 6 2 // C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f Symmetric 3 // p e r i o d i c S q u a r e waveform 4 clear ; 5 clc ; 6 close ; 7 // CTFT 8 T1 = 2; 9 T = 4* T1 ;

99

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

Wo = 2* %pi / T ; W = - %pi : Wo : %pi ; delta = ones (1 , length ( W ) ) ; XW (1) = (2* %pi * Wo * T1 / %pi ) ; mid_value = ceil ( length ( W ) /2) ; for k = 2: mid_value XW ( k ) = (2* %pi * sin (( k -1) * Wo * T1 ) /( %pi *( k -1) ) ) ; end figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,W ( mid_value : $ ) ,XW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; plot2d3 ( gnn ,W (1: mid_value -1) , XW ( $ : -1:2) ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( W i n r a d i a n s / S e c o n d s ) ; title ( C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f P e r i o d i c S q u a r e Wave )

100

Figure 4.6: Results of Exa 4.6 Example 4.7 Continuous Time Fourier Transforms of Sinusoidal waveforms (a)sin(Wot) (b)cos(Wot)
1 // Example 4 . 7 2 // C o n t i n u o u s Time F o u r i e r T r a n s f o r m s o f 3 // S i n u s o i d a l w a v e f o r m s ( a ) s i n ( Wot ) ( b ) c o s ( Wot ) 4 clear ; 5 clc ; 6 close ; 7 // CTFT 8 T1 = 2; 9 T = 4* T1 ;

101

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

Wo = 2* %pi / T ; W = [ - Wo ,0 , Wo ]; ak = (2* %pi * Wo * T1 / %pi ) / sqrt ( -1) ; XW = [ - ak ,0 , ak ]; ak1 = (2* %pi * Wo * T1 / %pi ) ; XW1 =[ ak1 ,0 , ak1 ]; // figure a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,W , imag ( XW ) ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( W ) ;

25 title ( CTFT o f s i n ( Wot ) ) 26 // 27 figure 28 a = gca () ; 29 a . y_location = o r i g i n ; 30 a . x_location = o r i g i n ; 31 plot2d3 ( gnn ,W , XW1 ,2) ; 32 poly1 = a . children (1) . children (1) ; 33 poly1 . thickness = 3; 34 xlabel (

W ) ; 35 title ( CTFT o f c o s ( Wot ) )

102

Figure 4.7: Results of Exa 4.7

103

Figure 4.8: Results of Exa 4.7 Example 4.8 Continuous Time Fourier Transform of Periodic Impulse Train
1 2 3 4 5 6 7 8 9 10

// Example 4 . 8 // C o n t i n u o u s Time F o u r i e r T r a n s f o r m s o f // P e r i o d i c I m p u l s e T r a i n clear ; clc ; close ; // CTFT T = -4:4;; T1 = 1; // S a m p l i n g I n t e r v a l xt = ones (1 , length ( T ) ) ; 104

11 12 13 14 15 16 17 18 19 20 21 22 23

ak = 1/ T1 ; XW = 2* %pi * ak * ones (1 , length ( T ) ) ; Wo = 2* %pi / T1 ; W = Wo * T ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,T , xt ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( t ); title ( P e r i o d i c I m p u l s e T r a i n ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,W , XW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel (

24 25 26 27 28 29 30 31 32

t ); 33 title ( CTFT o f P e r i o d i c I m p u l s e T r a i n )

105

Figure 4.9: Results of Exa 4.8 Example 4.9 Continuous Time Fourier Transform Properties: Linearity and Time Shift Property
1 2 3 4 5 6 7 8

// Example 4 . 9 : C o n t i n u o u s Time F o u r i e r T r a n s f o r m Properties : // L i n e a r i t y and Time S h i f t P r o p e r t y clear ; clc ; close ; // CTFT t1 = -1/2:0.1:1/2; t2 = -3/2:0.1:3/2; 106

9 10 11 12 13 14

15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

x1 = ones (1 , length ( t1 ) ) ; x2 = ones (1 , length ( t2 ) ) ; t3 = t1 +2.5; t4 = t2 +2.5; x1 = (1/2) * x1 ; x = [ x2 (1: floor ( length ( x2 ) /3) ) , x1 + x2 ( ceil ( length ( x2 ) /3) :$ - floor ( length ( x2 ) /3) ) , x2 (( $ - ceil ( length ( x2 ) /3) ) +2: $ ) ]; subplot (3 ,1 ,1) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot ( t1 , x1 ) xtitle ( x1 ( t ) ) subplot (3 ,1 ,2) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot ( t2 , x2 ) xtitle ( x2 ( t ) ) subplot (3 ,1 ,3) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot ( t4 , x ) xtitle ( x ( t ) )

107

Figure 4.10: Results of Exa 4.9 Example 4.12 Continuous Time Fourier Transform: Derivative property
1 2 3 4 5 6 7 8 9 10

// Example 4 . 1 2 : C o n t i n u o u s Time F o u r i e r T r a n s f o r m : // D e r i v a t i v e p r o p e r t y clear ; clc ; close ; // CTFT t = -1:0.1:1; x1 = ones (1 , length ( t ) ) ; x2 = [ -1 , zeros (1 , length ( t ) -2) , -1]; x = t; 108

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

// d i f f e r e n t i a t i o n o f x can be e x p r e s s e d a s // summation o f x1 and x2 subplot (3 ,1 ,1) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot (t , x1 ) xtitle ( x1 ( t ) ) subplot (3 ,1 ,2) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot2d3 ( gnn ,t , x2 ) xtitle ( x2 ( t ) ) subplot (3 ,1 ,3) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot (t , x ) xtitle ( x ( t ) )

109

Figure 4.11: Results of Exa 4.12 Example 4.18 Frequency Response of Ideal Low pass Filter X (jW ) = 1, from -T1 to T1
1 2 3 4 5 6 7 8

// Example 4 . 1 8 : F r e q u e n c y R e s p o n s e o f I d e a l Low p a s s Filter // X(jW)= 1 , from T1 t o T1 clear ; clc ; close ; Wc = 10; // 1 r a d / s e c W = - Wc :0.1: Wc ; // Passband o f f i l t e r HW0 = 1; // Magnitude o f F i l t e r 110

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

HW = HW0 * ones (1 , length ( W ) ) ; // I n v e r s e C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m t = - %pi : %pi / length ( W ) : %pi ; Dw = 0.1; ht =(1/(2* %pi ) ) * HW * exp ( sqrt ( -1) *W * t ) * Dw ; ht = real ( ht ) ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (W , HW ) ; xtitle ( F r e q u e n c y R e s p o n s e o f F i l t e r H(jW) ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (t , ht ) ; xtitle ( I m p u l s e R e s p o n s e o f F i l t e r h ( t ) )

111

Figure 4.12: Results of Exa 4.18 Example 4.23 Multiplication Property of CTFT
1 2 3 4 5 6 7 8 9 10

// F i g u r e 4 . 2 3 : M u l t i p l i c a t i o n P r o p e r t y o f CTFT clear ; clc ; close ; W1 = -1:0.1:1; W2 = -2:0.1:2; W = -3:0.1:3; // F o u r i e r T r a n s f o r m o f s i n c f u n c i o n i s s q u a r e wave XW1 = (1/ %pi ) * ones (1 , length ( W1 ) ) ; //CTFT o f x1 ( t ) XW2 = (1/(2* %pi ) ) * ones (1 , length ( W2 ) ) ; //CTFT o f x2 ( t ) 112

11 XW = (1/2) * convol ( XW1 , XW2 ) ; //CTFT o f x ( t )=x1 ( t ) x2 ( t

)
12 //X( jw ) = l i n e a r c o n v o l u t i o n o f X1 ( jw ) and X2 ( jw ) 13 figure 14 a = gca () ; 15 a . y_location = o r i g i n ; 16 a . x_location = o r i g i n ; 17 plot (W , XW ) ; 18 xlabel ( F r e q u e n c y i n R a d i a n s / S e c o n d s > W ) ; 19 title ( M u l t i p l i c a t i o n P r o p e r t y X(jW) )

Figure 4.13: Results of Exa 4.23

113

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

Example 4.22 1 // F i g u r e 4 . 2 2 // P l o t t i n g C o n t i n u o u s Time F o u r i e r T r a n s f o r m o f // I m p u l s e R e s p o n s e h ( t )= exp ( A t ) u ( t ) , t >0 clear ; clc ; close ; // Analog S i g n a l A =1; // A m p l i t u d e Dt = 0.005; t = 0: Dt :10; ht = exp ( - A * t ) ; // C o n t i n u o u s t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; HW = ht * exp ( - sqrt ( -1) *t * W ) * Dt ; HW_Mag = abs ( HW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax HW_Mag = [ mtlb_fliplr ( HW_Mag ) , HW_Mag (2:1001) ]; // P l o t t i n g C o n t i n u o u s Time S i g n a l figure a = gca () ; a . y_location = o r i g i n ; plot (t , ht ) ; xlabel ( t i n s e c . ) ; title ( I m p u l s e R e s p o n s e h ( t ) ) figure // P l o t t i n g Magnitude R e s p o n s e o f CTS a = gca () ; a . y_location = o r i g i n ; plot (W , HW_Mag ) ; xlabel ( F r e q u e n c y i n R a d i a n s / S e c o n d s > W ) ; title ( F r e q u e n c y R e s p o n s e H(jW) )

114

Figure 4.14: Results of Exa 4.22

115

Figure 4.15: Results of Exa 4.22

116

Chapter 5 The Discreet Time Fourier Transform


5.1 Scilab Codes

Example 5.1 Discrete Time Fourier Transform of discrete sequence x[n] = (an ).u[n], a > 0anda < 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// Example 5 . 1 : D i s c r e t e Time F o u r i e r T r a n s f o r m o f d i s c r e t e sequence // x [ n ]= ( a n ) . u [ n ] , a >0 and a <0 clear ; clc ; close ; // DTS S i g n a l a1 = 0.5; a2 = -0.5; max_limit = 10; for n = 0: max_limit -1 x1 ( n +1) = ( a1 ^ n ) ; x2 ( n +1) = ( a2 ^ n ) ; end n = 0: max_limit -1; // D i s c r e t e t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi ;

117

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; x1 = x1 ; x2 = x2 ; XW1 = x1 * exp ( - sqrt ( -1) *n * W ) ; XW2 = x2 * exp ( - sqrt ( -1) *n * W ) ; XW1_Mag = abs ( XW1 ) ; XW2_Mag = abs ( XW2 ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax XW1_Mag = [ mtlb_fliplr ( XW1_Mag ) , XW1_Mag (2:1001) ]; XW2_Mag = [ mtlb_fliplr ( XW2_Mag ) , XW2_Mag (2:1001) ]; [ XW1_Phase , db ] = phasemag ( XW1 ) ; [ XW2_Phase , db ] = phasemag ( XW2 ) ; XW1_Phase = [ - mtlb_fliplr ( XW1_Phase ) , XW1_Phase (2:1001) ]; XW2_Phase = [ - mtlb_fliplr ( XW2_Phase ) , XW2_Phase (2:1001) ]; // p l o t f o r a >0 figure subplot (3 ,1 ,1) ; plot2d3 ( gnn ,n , x1 ) ; xtitle ( D i s c r e t e Time S e q u e n c e x [ n ] f o r a >0 ) subplot (3 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d (W , XW1_Mag ) ; title ( Magnitude R e s p o n s e a b s (X(jW) ) ) subplot (3 ,1 ,3) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d (W , XW1_Phase ) ; title ( Phase R e s p o n s e <(X(jW) ) ) // p l o t f o r a <0 figure 118

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

subplot (3 ,1 ,1) ; plot2d3 ( gnn ,n , x2 ) ; xtitle ( D i s c r e t e Time S e q u e n c e x [ n ] f o r a >0 ) subplot (3 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d (W , XW2_Mag ) ; title ( Magnitude R e s p o n s e a b s (X(jW) ) ) subplot (3 ,1 ,3) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d (W , XW2_Phase ) ; title ( Phase R e s p o n s e <(X(jW) ) )

119

Figure 5.1: Results of Exa 5.1

120

Figure 5.2: Results of Exa 5.1 Example 5.2 Discrete Time Fourier Transform of x[n] = (aa bs(n))a > 0anda < 0
1 // Example 5 . 2 : D i s c r e t e Time F o u r i e r T r a n s f o r m o f 2 // x [ n ]= ( a a b s ( n ) ) a >0 and a <0 3 clear ; 4 clc ; 5 close ; 6 // DTS S i g n a l 7 a = 0.5; 8 max_limit = 10; 9 n = - max_limit +1: max_limit -1;

121

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

x = a ^ abs ( n ) ; // D i s c r e t e t i m e F o u r i e r T r a n s f o r m Wmax = 2* %pi ; K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = x * exp ( - sqrt ( -1) *n * W ) ; XW_Mag = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ]; // p l o t f o r a b s ( a ) <1 figure subplot (2 ,1 ,1) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,n , x ) ; xtitle ( D i s c r e t e Time S e q u e n c e x [ n ] f o r a >0 ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d (W , XW_Mag ) ; title ( D i s c r e t e Time F o u r i e r T r a n s f o r m X( exp (jW) ) )

122

Figure 5.3: Results of Exa 5.2 Example 5.3 Discrete Time Fourier Transform of x[n] = 1, abs(n) <= N 1
1 2 3 4 5 6 7 8 9 10

// Example 5 . 3 : D i s c r e t e Time F o u r i e r T r a n s f o r m o f // x [ n ]= 1 , a b s ( n )<=N1 clear ; clc ; close ; // DTS S i g n a l N1 = 2; n = - N1 : N1 ; x = ones (1 , length ( n ) ) ; // D i s c r e t e t i m e F o u r i e r T r a n s f o r m 123

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32

Wmax = 2* %pi ; K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = x * exp ( - sqrt ( -1) *n * W ) ; XW_Mag = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ]; // p l o t f o r a b s ( a ) <1 figure subplot (2 ,1 ,1) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,n , x ) ; xtitle ( D i s c r e t e Time S e q u e n c e x [ n ] ) subplot (2 ,1 ,2) ; a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d (W , XW_Mag ) ; title ( D i s c r e t e Time F o u r i e r T r a n s f o r m X( exp (jW) ) )

124

Figure 5.4: Results of Exa 5.3 Example 5.5 Discrete Time Fourier Transform: x[n] = cos(nW o)
1 2 3 4 5 6 7 8 9

// Example5 . 5 : D i s c r e t e Time F o u r i e r T r a n s f o r m : x [ n ]= c o s (nWo) clear ; clc ; close ; N = 5; Wo = 2* %pi / N ; W = [ - Wo ,0 , Wo ]; XW =[ %pi ,0 , %pi ]; // 125

10 figure 11 a = gca () ; 12 a . y_location = o r i g i n ; 13 a . x_location = o r i g i n ; 14 plot2d3 ( gnn ,W , XW ,2) ; 15 poly1 = a . children (1) . children (1) ; 16 poly1 . thickness = 3; 17 xlabel (

W ) ; 18 title ( DTFT o f c o s (nWo) ) 19 disp ( Wo )

126

Figure 5.5: Results of Exa 5.5 Example 5.6 Discrete Time Fourier Transform of Periodic Impulse Train
1 2 3 4 5 6 7 8 9 10

// Example5 . 6 : D i s c r e t e Time F o u r i e r T r a n s f o r m o f // P e r i o d i c I m p u l s e T r a i n clear ; clc ; close ; N = 5; N1 = -3* N :3* N ; xn = [ zeros (1 ,N -1) ,1]; x = [1 xn xn xn xn xn xn ]; ak = 1/ N ; 127

11 12 13 14 15 16 17 18 19 20 21 22 23

XW = 2* %pi * ak * ones (1 ,2* N ) ; Wo = 2* %pi / N ; n = -N :N -1; W = Wo * n ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,N1 ,x ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel ( n ); title ( P e r i o d i c I m p u l s e T r a i n ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot2d3 ( gnn ,W , XW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xlabel (

24 25 26 27 28 29 30 31 32

W ) ; 33 title ( DTFT o f P e r i o d i c I m p u l s e T r a i n ) 34 disp ( Wo )

128

Figure 5.6: Results of Exa 5.6 Example 5.7 Frequency Shifting Property of DTFT:Frequency Response of Ideal Low pass Filter and HPF
1

2 3 4 5 6 7

// Example 5 . 7 : F r e q u e n c y S h i f t i n g P r o p e r t y o f DTFT : F r e q u e n c y R e s p o n s e o f I d e a l Low p a s s F i l t e r and HPF clear ; clc ; close ; Wc = 1; // 1 r a d / s e c W = - Wc :0.1: Wc ; // Passband o f f i l t e r H0 = 1; // Magnitude o f F i l t e r 129

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26

HlpW = H0 * ones (1 , length ( W ) ) ; Whp1 = W + %pi ; Whp2 = -W - %pi ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ - %pi ,0; %pi ,2]; plot2d (W , HlpW ) ; xtitle ( F r e q u e n c y R e s p o n s e o f LPF H( exp (jW) ) ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -2* %pi ,0;2* %pi ,2]; plot2d ( Whp1 , HlpW ) ; plot2d ( Whp2 , HlpW ) ; xtitle ( F r e q u e n c y R e s p o n s e o f HPF H( exp (jW) ) )

130

Figure 5.7: Results of Exa 5.7 Example 5.9 Time Expansion Property of DTFT
1 2 3 4 5 6 7 8 9 10

// Example 5 . 9 : Time E x p a n s i o n P r o p e r t y o f DTFT clear ; close ; clc ; n = -1:11; x = [0 ,1 ,2 ,1 ,2 ,1 ,2 ,1 ,2 ,1 ,2 ,0 ,0]; y = [1 ,1 ,1 ,1 ,1]; y_2_n = zeros (1 ,2* length ( y ) +1) ; y_2_n (1:2:2* length ( y ) ) = y ; y_2_n = [0 y_2_n 0]; 131

11 y_2_n_1 = [0 , y_2_n (1: $ -1) ]; 12 x_r = y_2_n +2* y_2_n_1 ; 13 y = [0 ,y , zeros (1 ,7) ]; 14 figure 15 subplot (4 ,1 ,1) 16 plot2d3 ( gnn ,n , y ) 17 title ( y [ n ] ) 18 subplot (4 ,1 ,2) 19 plot2d3 ( gnn ,n , y_2_n ) 20 title ( y ( 2 ) [ n ] ) 21 subplot (4 ,1 ,3) 22 plot2d3 ( gnn ,n , y_2_n_1 ) 23 title ( y ( 2 ) [ n 1] ) 24 subplot (4 ,1 ,4) 25 plot2d3 ( gnn ,n , x ) 26 title ( x [ n ]= y ( 2 ) [ n ]+2 y ( 2 ) [ n 1] )

132

Figure 5.8: Results of Exa 5.9 Example 5.12 IDTFT:Impulse Response of Ideal Low pass Filter
1 2 3 4 5 6 7 8 9

// Example 5 . 1 2 : IDTFT : I m p u l s e R e s p o n s e o f I d e a l Low pass F i l t e r clear ; clc ; close ; Wc = 1; // 1 r a d / s e c W = - Wc :0.1: Wc ; // Passband o f f i l t e r H0 = 1; // Magnitude o f F i l t e r HlpW = H0 * ones (1 , length ( W ) ) ; // I n v e r s e D i s c r e t e t i m e F o u r i e r T r a n s f o r m 133

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

t = -2* %pi :2* %pi / length ( W ) :2* %pi ; ht =(1/(2* %pi ) ) * HlpW * exp ( sqrt ( -1) *W * t ) ; ht = real ( ht ) ; figure subplot (2 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ - %pi ,0; %pi ,2]; plot2d (W , HlpW ,2) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xtitle ( F r e q u e n c y R e s p o n s e o f LPF H( exp (jW) ) ) subplot (2 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ -2* %pi , -1;2* %pi ,2]; plot2d3 ( gnn ,t , ht ) ; poly1 = a . children (1) . children (1) ; poly1 . thickness = 3; xtitle ( I m p u l s e R e s p o n s e o f LPF h ( t ) )

134

Figure 5.9: Results of Exa 5.12 Example 5.15 Multiplication Property of DTFT
1 2 3 4 5 6 7 8 9 10

// Example5 . 1 5 : M u l t i p l i c a t i o n P r o p e r t y o f DTFT clear ; clc ; close ; n = 1:100; x2 = [3/4 , sin (0.75* %pi * n ) ./( %pi * n ) ]; x1 = [1/2 , sin (0.5* %pi * n ) ./( %pi * n ) ]; x = x1 .* x2 ; Wmax = %pi ; K = 1; 135

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

k = 0:( K /1000) : K ; W = k * Wmax / K ; n = 0:100; XW1 = x1 * exp ( - sqrt ( -1) *n * W ) ; XW2 = x2 * exp ( - sqrt ( -1) *n * W ) ; XW = x * exp ( - sqrt ( -1) *n * W ) ; XW1_Mag = real ( XW1 ) ; XW2_Mag = real ( XW2 ) ; XW_Mag = real ( XW ) ; W = [ - mtlb_fliplr ( W ) , W (2: $ ) ]; // Omega from Wmax t o Wmax XW1_Mag = [ mtlb_fliplr ( XW1_Mag ) , XW1_Mag (2: $ ) ]; XW2_Mag = [ mtlb_fliplr ( XW2_Mag ) , XW2_Mag (2: $ ) ]; XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2: $ ) ]; figure subplot (3 ,1 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (W , XW1_Mag ) ; title ( DTFT X1 ( exp (jW) ) ) ; subplot (3 ,1 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (W , XW2_Mag ) ; title ( DTFT X2 ( exp (jW) ) ) ; subplot (3 ,1 ,3) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; plot (W , XW_Mag ) ; title ( M u l t i p l i c a t i o n P r o p e r t y o f DTFT ) ;

136

Figure 5.10: Results of Exa 5.15

137

Chapter 6 Time and Frequency Characterization of Signals and Systems


6.1 Scilab Codes

Example 6.1 Phase Response and Group Delay


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// Example6 . 1 : Phase R e s p o n s e and Group D e l a y clear ; clc ; close ; f1 = 50; f2 = 150; f3 = 300; w1 = 315; tuo1 = 0.066; w2 = 943; tuo2 = 0.033; w3 = 1888; tuo3 = 0.058; f = 0:0.1:400; W = 2* %pi * f ; for i =1: length ( f )

138

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

num1 ( i ) = (1+( sqrt ( -1) * f ( i ) / f1 ) ^2 -2* sqrt ( -1) * tuo1 *( f ( i ) / f1 ) ) ; den1 ( i ) = (1+( sqrt ( -1) * f ( i ) / f1 ) ^2+2* sqrt ( -1) * tuo1 *( f ( i ) / f1 ) ) ; H1W ( i ) = num1 ( i ) / den1 ( i ) ; num2 ( i ) = (1+( sqrt ( -1) * f ( i ) / f2 ) ^2 -2* sqrt ( -1) * tuo2 *( f ( i ) / f2 ) ) ; den2 ( i ) = (1+( sqrt ( -1) * f ( i ) / f2 ) ^2+2* sqrt ( -1) * tuo2 *( f ( i ) / f2 ) ) ; H2W ( i ) = num2 ( i ) / den2 ( i ) ; num3 ( i ) = (1+( sqrt ( -1) * f ( i ) / f3 ) ^2 -2* sqrt ( -1) * tuo3 *( f ( i ) / f3 ) ) ; den3 ( i ) = (1+( sqrt ( -1) * f ( i ) / f3 ) ^2+2* sqrt ( -1) * tuo3 *( f ( i ) / f3 ) ) ; H3W ( i ) = num3 ( i ) / den3 ( i ) ; H_W ( i ) = H1W ( i ) * H2W ( i ) ; HW ( i ) = H_W ( i ) * H3W ( i ) ; phase1 ( i ) = -2* atan ((2* tuo1 *( f ( i ) / f1 ) ) /(1.001 -( f ( i ) / f1 ) ^2) ) ; phase2 ( i ) = -2* atan ((2* tuo2 *( f ( i ) / f2 ) ) /(1.001 -( f ( i ) / f2 ) ^2) ) ; phase3 ( i ) = -2* atan ((2* tuo3 *( f ( i ) / f3 ) ) /(1.001 -( f ( i ) / f3 ) ^2) ) ; phase_total ( i ) = phase1 ( i ) + phase2 ( i ) + phase3 ( i ) ; if ( f ( i ) <=50) W_phase1 ( i ) = -2* atan ((2* tuo1 *( f ( i ) / f1 ) ) /(1.001 -( f ( i ) / f1 ) ^2) ) ; W_phase2 ( i ) = -2* atan ((2* tuo2 *( f ( i ) / f2 ) ) /(1.001 -( f ( i ) / f2 ) ^2) ) ; W_phase3 ( i ) = -2* atan ((2* tuo3 *( f ( i ) / f3 ) ) /(1.001 -( f ( i ) / f3 ) ^2) ) ; group_delay ( i ) = - phase_total ( i ) *0.1/ %pi ; // d e l t a f= 0.1 elseif ( f ( i ) >=50 & f ( i ) <=150) W_phase1 ( i ) = -2* %pi -2* atan ((2* tuo1 *( f ( i ) / f1 ) ) /(1.001 -( f ( i ) / f1 ) ^2) ) ; W_phase2 ( i ) = -2* atan ((2* tuo2 *( f ( i ) / f2 ) ) /(1.001 -( f ( i ) / f2 ) ^2) ) ; 139

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

W_phase3 ( i ) = -2* atan ((2* tuo3 *( f ( i ) / f3 ) ) /(1.001 -( f ( i ) / f3 ) ^2) ) ; group_delay ( i ) = - phase_total ( i ) *0.1/(2* %pi ) ; elseif ( f ( i ) >=150 & f ( i ) <=300) W_phase1 ( i ) = -2* atan ((2* tuo1 *( f ( i ) / f1 ) ) /(1.001 -( f ( i ) / f1 ) ^2) ) ; W_phase2 ( i ) = -4* %pi -2* atan ((2* tuo2 *( f ( i ) / f2 ) ) /(1.001 -( f ( i ) / f2 ) ^2) ) ; W_phase3 ( i ) = -2* atan ((2* tuo3 *( f ( i ) / f3 ) ) /(1.001 -( f ( i ) / f3 ) ^2) ) ; group_delay ( i ) = - phase_total ( i ) *0.1/(4* %pi ) ; elseif ( f ( i ) >300 & f ( i ) <=400) W_phase1 ( i ) = -2* atan ((2* tuo1 *( f ( i ) / f1 ) ) /(1.001 -( f ( i ) / f1 ) ^2) ) ; W_phase2 ( i ) = -2* atan ((2* tuo2 *( f ( i ) / f2 ) ) /(1.001 -( f ( i ) / f2 ) ^2) ) ; W_phase3 ( i ) = -6* %pi -2* atan ((2* tuo3 *( f ( i ) / f3 ) ) /(1.001 -( f ( i ) / f3 ) ^2) ) ; group_delay ( i ) = - phase_total ( i ) *0.1/(4* %pi ) ; end if ( f ( i ) ==300.1) W_phase_total ( i ) = 2* %pi + W_phase1 ( i ) + W_phase2 ( i ) + W_phase3 ( i ) ; else W_phase_total ( i ) = W_phase1 ( i ) + W_phase2 ( i ) + W_phase3 ( i ) ; end end figure plot2d (f , phase_total ,2) xtitle ( P r i n c i p a l p h a s e , F r e q u e n c y ( Hz ) , Phase ( r a d ) ); figure plot2d (f , W_phase_total ,2) xtitle ( unwrapped p h a s e , F r e q u e n c y ( Hz ) , Phase ( r a d ) ); figure plot2d (f , abs ( group_delay ) ,2) 140

67

xtitle ( g r o u p d e l a y , F r e q u e n c y ( Hz ) , Group D e l a y ( s e c ) );

Figure 6.1: Results of Exa 6.1

141

Figure 6.2: Results of Exa 6.1

142

Figure 6.3: Results of Exa 6.1 Example 6.3 Analog Lowpass IIR lter design Cuto frequency Fc = 500Hz Passband ripple 1-0.05 and stopband ripple = 0.05
1 // Example6 . 3 : Analog Lowpass I I R f i l t e r d e s i g n 2 // C u t o f f f r e q u e n c y Fc = 500 Hz 3 // Passband r i p p l e 1 0.05 and s t o p b a n d r i p p l e = 0 . 0 5 4 clear ; 5 close ; 6 clc ; 7 hs_butt = analpf (5 , b u t t ,[0.05 ,0.05] ,500) ; 8 hs_ellip = analpf (5 , e l l i p ,[0.05 ,0.05] ,500) ; 9 fr =0:.1:2000;

143

10 hf_butt = freq ( hs_butt (2) , hs_butt (3) , %i * fr ) ; 11 hm_butt = abs ( hf_butt ) ; 12 hf_ellip = freq ( hs_ellip (2) , hs_ellip (3) , %i * fr ) ; 13 hm_ellip = abs ( hf_ellip ) ; 14 // P l o t t i n g Magnitude R e s p o n s e o f Analog I I R F i l t e r s 15 a = gca () ; 16 plot2d ( fr , hm_butt ) 17 poly1 = a . children (1) . children (1) ; 18 poly1 . foreground = 2; 19 poly1 . thickness = 2; 20 poly1 . line_style = 3; 21 plot2d ( fr , hm_ellip ) 22 poly1 = a . children (1) . children (1) ; 23 poly1 . foreground = 5; 24 poly1 . thickness = 2; 25 xlabel ( F r e q u e n c y ( Hz ) ) 26 ylabel ( Magnitude o f f r e q u e n c y r e s p o n s e ) 27 legend ([ B u t t e r w o r t h F i l t e r ; E l l i p t i c F i l t e r ])

144

Figure 6.4: Results of Exa 6.3 Example 6.4 Bode Plot


1 // Example 6 . 4 : Bode P l o t 2 s = %s ; 3 // Open Loop T r a n s f e r F u n c t i o n 4 H = syslin ( c ,[20000/( s ^2+100* s +10000) ]) ; // jw

r e p l a c e d by s 5 clf ; 6 bode (H ,0.01 ,10000)

145

Figure 6.5: Results of Exa 6.4 Example 6.5 Bode Plot


1 // Example 6 . 5 : Bode P l o t 2 s = %s ; 3 // Open Loop T r a n s f e r F u n c t i o n 4 H = syslin ( c ,[(100*(1+ s ) ) /((10+ s ) *(100+ s ) ) ]) ; // jw

r e p l a c e d by s 5 clf ; 6 bode (H ,0.01 ,10000)

146

Figure 6.6: Results of Exa 6.5

147

Chapter 7 Sampling
7.1 Scilab Codes

Example 7.1 Sinusoidal signal


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

// Example7 . 1 : S i n u s o i d a l s i g n a l clear ; close ; clc ; Wm = 2* %pi ; Ws = 2* Wm ; t = -2:0.01:2; phi = - %pi /2; x = cos (( Ws /2) * t + phi ) ; y = sin (( Ws /2) * t ) ; subplot (2 ,1 ,1) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ; plot (t , x ) title ( c o s (Ws/2 t+p h i ) ) subplot (2 ,1 ,2) a = gca () ; a . x_location = o r i g i n ; a . y_location = o r i g i n ;

148

21 22

plot (t , y ) title ( s i n (Ws/2 t ) )

Figure 7.1: Results of Exa 7.1 Example 7.2 Digital Dierentiator


1 // Example7 . 2 : D i g i t a l D i f f e r e n t i a t o r 2 syms t n ; 3 T = 0.1; // S a m p l i n g t i m e i n s e c o n d s 4 xct = sin ( %pi * t / T ) /( %pi * t ) ; 5 yct = diff ( xct , t ) ; 6 disp ( yct , yc ( t )= ) ;

149

7 8 9 10 11 12 13 14

t = n*T; xdn = sin ( %pi * t / T ) /( %pi * t ) ; ydn = diff ( xdn , n ) ; disp ( ydn , yd [ n ]= ) ; hdn = T * ydn ; disp ( hdn , hd [ n ]= ) ; // R e s u l t // yc ( t ) = ( 1 0 c o s ( 3 1 . 4 1 5 9 2 7 t ) / t ) ( 0 . 3 1 8 3 0 9 9 s i n (31.415927 t ) /( t 2) ) 15 // yd [ n ] = ( 1 0 c o s ( 3 . 1 4 1 5 9 2 7 n ) / n ) 3.183 s i n ( 3 . 1 4 1 5 9 2 7 n) /(n 2) 16 // hd [ n ] = ( c o s ( 3 . 1 4 1 5 9 2 7 n ) / n ) 0.3183 s i n ( 3 . 1 4 1 5 9 2 7 n ) /(n 2) Example 7.3 Half Sample Delay system
1 // Example7 . 3 : H a l f Sample D e l a y s y s t e m 2 syms t n T ; 3 //T = 0 . 1 ; // S a m p l i n g t i m e i n s e c o n d s 4 xct = sin ( %pi * t / T ) /( %pi * t ) ; 5 t = t - T /2; 6 yct_del = sin ( %pi * t / T ) /( %pi * t ) ; 7 disp ( yct_del , Output o f H a l f Sample d e l a y s y s t e m

c o n t i n u o u s = );
8 t = n *T - T /2; 9 xdn = sin ( %pi * t / T ) /( %pi * t ) ; 10 ydn_del = xdn ; 11 disp ( ydn_del , Output o f H a l f Sample d e l a y s y s t e m

d i s c r e t e = );
12 hdn = T * ydn_del ; 13 disp ( hdn , I m p u l s e R e s p o n s e o f 14 15 16 17 18

d i s c r e t e time h a l f s a m p l e d e l a y s y s t e m= ) ; // R e s u l t // Output o f H a l f Sample d e l a y s y s t e m c o n t i n u o u s = // s i n ( 3 . 1 4 ( t T/ 2 ) /T) / ( 3 . 1 4 ( t T/ 2 ) ) // Output o f H a l f Sample d e l a y s y s t e m d i s c r e t e = // s i n ( 3 . 1 4 ( n TT/ 2 ) /T) / ( 3 . 1 4 ( n TT/ 2 ) )

150

19

// I m p u l s e R e s p o n s e o f d i s c r e t e t i m e h a l f s a m p l e d e l a y s y s t e m= 20 // T s i n ( 3 . 1 4 ( n TT/ 2 ) /T) / ( 3 . 1 4 ( n TT/ 2 ) ) Example 7.4 Finding the period of the sampled signal and Sampling frequency
1

2 3 4 5 6 7 8 9 10

// Example7 . 4 : F i n d i n g t h e p e r i o d o f t h e s a m p l e d signal // and S a m p l i n g f r e q u e n c y clear ; close ; clc ; Wm = 2* %pi /9; N = floor (2* %pi /(2* Wm ) ) disp (N , P e r i o d o f t h e d i s c r e t e s i g n a l ) Ws = 2* %pi / N ; disp ( Ws , The S a m p l i n g f r e q u e n c y c o r r e s p o n d i n g t o t h e period N) Example 7.5 Multirate Signal Processing:Sampling Rate Conversion (1)Downsampling by 4 (2)Upsampling by 2 (3)Upsampling by 2 and followed by downsampling by 9

1 2 3 4 5 6 7 8 9 10 11

// Example7 . 5 : M u l t i r a t e S i g n a l P r o c e s s i n g : S a m p l i n g Rate C o n v e r s i o n // ( 1 ) Downsampling by 4 // ( 2 ) Upsampling by 2 // ( 3 ) Upsampling by 2 and f o l l o w e d by d o w ns a m p l i n g by 9 clear ; close ; clc ; Wm = 2* %pi /9; //Maximum f r e q u e n c y o f s i g n a l Ws = 2* Wm ; // S a m p l i n g f r e q u e n c y N = floor (2* %pi / Ws ) ; // p e r i o d o f d i s c r e t e s i g n a l // O r i g i n a l d i s c r e t e t i m e s i g n a l g e n e r a t i o n and Magnitude r e s p o n s e 151

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

n = 0:0.01: N ; x = sin ( Wm * n ) ; Wmax = 2* %pi /9; K = 4; k = 0:( K /1000) : K ; W = k * Wmax / K ; XW = x * exp ( - sqrt ( -1) *n * W ) ; XW_Mag = real ( XW ) ; XW_Mag = XW_Mag / max ( XW_Mag ) ; W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from Wmax t o Wmax XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ]; // ( 1 ) d o wn s a m p l i n g by 4 and c o r r e s p o n d i n g m a g n i t u d e response n1 = 0:0.01: N /4; y = x (1:4: length ( x ) ) ; k1 = 0:( K /2000) : K ; W1 = k1 *4* Wmax / K ; XW4 = y * exp ( - sqrt ( -1) * n1 * W1 ) ; XW4_Mag = real ( XW4 ) ; XW4_Mag = XW4_Mag / max ( XW4_Mag ) ; W1 = [ - mtlb_fliplr ( W1 ) , W1 (2: $ ) ]; // Omega from Wmax t o Wmax XW4_Mag = [ mtlb_fliplr ( XW4_Mag ) , XW4_Mag (2: $ ) ]; // ( 2 ) Upsampling by 2 and c o r r e s p o n d i n g m a g n i t u d e response n2 = 0:0.01:2* N ; z = zeros (1 , length ( n2 ) ) ; z ([1:2: length ( z ) ]) = x ; k2 = 0:( K /500) : K ; W2 = k2 * Wmax /(2* K ) ; XW2 = z * exp ( - sqrt ( -1) * n2 * W2 ) ; XW2_Mag = real ( XW2 ) ; XW2_Mag = XW2_Mag / max ( XW2_Mag ) ; W2 = [ - mtlb_fliplr ( W2 ) , W2 (2: $ ) ]; // Omega from Wmax t o Wmax XW2_Mag = [ mtlb_fliplr ( XW2_Mag ) , XW2_Mag (2: $ ) ]; // ( 3 ) Upsampling by 2 and Downsampling by 9 152

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

c o r r e s p o n d i n g magnitude r e s p o n s e n3 = 0:0.01:2* N /9; g = z ([1:9: length ( z ) ]) ; k3 = 0: K /(9*500) : K ; W3 = k3 *9* Wmax /(2* K ) ; XW3 = g * exp ( - sqrt ( -1) * n3 * W3 ) ; XW3_Mag = real ( XW3 ) ; XW3_Mag = XW3_Mag / max ( XW3_Mag ) ; W3 = [ - mtlb_fliplr ( W3 ) , W3 (2: $ ) ]; // Omega from Wmax t o Wmax XW3_Mag = [ mtlb_fliplr ( XW3_Mag ) , XW3_Mag (2: $ ) ]; // figure subplot (2 ,2 ,1) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ - %pi ,0; %pi ,1.5]; plot2d (W , XW_Mag ,5) ; title ( Spectrum o f D i s c r e t e S i g n a l X( exp (jW) ) ) subplot (2 ,2 ,2) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ - %pi ,0; %pi ,1.5]; plot2d ( W1 , XW4_Mag ,5) ; title ( Spectrum o f downsampled s i g n a l by 4 X( exp (jW /4) ) ) subplot (2 ,2 ,3) a = gca () ; a . y_location = o r i g i n ; a . x_location = o r i g i n ; a . data_bounds =[ - %pi ,0; %pi ,1.5]; plot2d ( W2 , XW2_Mag ,5) ; title ( Spectrum o f Upsampled s i g n a l by 2 X( exp ( 2jW) ) ) subplot (2 ,2 ,4) a = gca () ; 153

79 a . y_location = o r i g i n ; 80 a . x_location = o r i g i n ; 81 a . data_bounds =[ - %pi ,0; %pi ,1.5]; 82 plot2d ( W3 , XW3_Mag ,5) ; 83 title ( Spectrum o f Upsampled by 2 and Downsampled by

X( exp ( 2jW/ 9 ) ) )

Figure 7.2: Results of Exa 7.5

154

Chapter 9 The Laplace Transform


9.1 Scilab Codes

Example 9.1 Lapalce Transform x(t) = exp(at).u(t)


1 // Example9 . 1 : L a p a l c e T r a n s f o r m x ( t ) = exp ( a t ) . u ( t ) 2 syms t s ; 3 a = 3; 4 y = laplace ( %e( a t ) ,t , s ) ; 5 disp ( y ) 6 // R e s u l t 7 // 1 / ( s+a )

Example 9.2 Lapalce Transform x(t) = exp(at).u(t)


1 2 3 4 5 6 7

// Example9 . 2 : L a p a l c e T r a n s f o r m x ( t ) = exp ( a t ) . u( t ) syms t s ; a =3; y = laplace ( %e ( a t ) ,t , s ) ; disp ( y ) // R e s u l t // 1 / ( s+a ) Example 9.3 Lapalce Transform x(t) = 3exp(2t)u(t) 2exp(t)u(t) 155

1 2 3 4 5 6

// Example9 . 3 : L a p a l c e T r a n s f o r m x ( t ) = 3 exp ( 2 t ) u ( t ) 2exp ( t ) u ( t ) syms t s ; y = laplace ( 3 %e( 2 t ) 2%e( t ) ,t , s ) ; disp ( y ) // R e s u l t // ( 3 / ( s +2) ) (2/( s +1) ) Example 9.4 Lapalce Transform x(t) = exp(2t)u(t) + exp(t)(cos3t)u(t)

1 2 3 4 5 6 7

// Example9 . 4 : L a p a l c e T r a n s f o r m x ( t ) = exp ( 2 t ) u ( t )+ exp ( t ) ( c o s 3 t ) u ( t ) syms t s ; y = laplace ( %e( 2 t )+%e( t ) c o s ( 3 t ) ,t , s ) ; disp ( y ) // R e s u l t // [ ( s +1) / ( s 2+2 s +10) ] + [ 1 / ( s +2) ] r e f e r equation 9.29 // E q u i v a l e n t t o ( 2 s 2+5 s +12) / ( ( s 2+2 s +10) ( s +2) ) r e f e r equation 9.30 Example 9.5 Lapalce Transform x(t) = s(t)(4/3)exp(t)u(t)+(1/3)exp(2t)u(t)

1 2 3 4 5 6 7

// Example9 . 5 : L a p a l c e T r a n s f o r m o f x ( t )=s ( t ) (4/3) exp ( t ) u ( t ) + ( 1 / 3 ) exp ( 2 t ) u ( t ) syms t s ; y = laplace ( (4/3) %e( t ) + ( 1 / 3 ) %e ( 2 t ) ,t , s ) ; y = 1+ y ; disp ( y ) // R e s u l t // [ 4 / ( 3 ( s +1) ) ] + [ 1 / ( 3 ( s 2) ) ]+1 Example 9.6 Lapalce Transform x(t) = exp(at)u(t), 0 < t < T

1 2 3

// Example9 . 6 // L a p a l c e T r a n s f o r m x ( t ) = exp ( a t ) u ( t ) , 0< t <T syms t s ; 156

4 a = 3; 5 T = 10; 6 // t = T ; 7 y = laplace ( %e( a t )%e( a t ) %e( ( s+a ) T) ,t , s )

; 8 disp ( y ) 9 // R e s u l t 10 // [ 1 / ( s+a ) ] [ ( exp (( s a ) T) ) / ( s+a ) ] Example 9.7 Lapalce Transform x(t) = exp(b.abs(t)).u(t), 0 < t < T x(t) = exp(bt).u(t) + exp(bt).u(t)
1 2 3 4 5 6 7 8 9

// Example9 . 7 // L a p a l c e T r a n s f o r m x ( t ) = exp ( b . a b s ( t ) ) . u ( t ) , 0< t < T // x ( t ) = exp ( b t ) . u ( t )+exp ( b t ) . u( t ) syms t s ; b = 3; y = laplace ( %e( b t )%e ( b t ) ,t , s ) ; disp ( y ) // R e s u l t // [ 1 / ( s+b ) ] [ 1 / ( s b ) ] Example 9.8 Inverse Lapalce Transform X (S ) = 1/((s + 1)(s + 2))

1 2 3 4 5 6 7 8 9 10 11 12

// Example9 . 8 : I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = 1 / ( ( s +1) ( s +2) ) s = %s ; G = syslin ( c ,(1/(( s +1) *( s +2) ) ) ) ; disp (G , G( s )= ) plzr ( G ) x = denom ( G ) ; disp (x , Ch a r a c t e r i s t i c s P o l y n o m i a l= ) y = roots ( x ) ; disp (y , P o l e s o f a s y s t e m= ) // R e s u l t // 1 and 2 157

Figure 9.1: Results of Exa 9.8 Example 9.9 Inverse Lapalce Transform X (S ) = 1/((s + 1)(s + 2))
1 2 3 4 5 6 7 8 9 10

// Example9 . 9 : I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = 1 / ( ( s +1) ( s +2) ) s = %s ; syms t ; [ A ]= pfss (1/(( s +1) *( s +2) ) ) // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F = F1 + F2 ; disp (F , f ( t )= ) // R e s u l t 158

11

// ( %e t ) (%e (2 t ) ) Example 9.10 Inverse Lapalce Transform X (S ) = 1/((s +1)(s +2))Re(s) < 1, Re(s) < 2

1 2 3 4 5 6 7 8 9 10 11

// Example9 . 1 0 : I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = 1 / ( ( s +1) ( s +2) ) Re ( s )< 1 ,Re ( s )< 2 s = %s ; syms t ; [ A ]= pfss (1/(( s +1) *( s +2) ) ) // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F = -F1 - F2 ; disp (F , f ( t )= ) // R e s u l t // %e (2 t )%e t Example 9.11 Inverse Lapalce Transform X (S ) = 1/((s + 1)(s + 2)) 2 < Re(s) < 1

1 2 3 4 5 6 7 8 9 10 11

// Example9 . 1 1 : I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = 1 / ( ( s +1) ( s +2) ) 2< Re ( s )< 1 s = %s ; syms t ; [ A ]= pfss (1/(( s +1) *( s +2) ) ) // p a r t i a l f r a c t i o n o f F ( s ) F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F = - F1 + F2 ; disp (F , f ( t )= ) // R e s u l t // (%e t ) (%e (2 t ) ) Example 9.12 Inverse Lapalce Transform X (S ) = 1/(s + (1/2))Re(s) > 1/2

1 2

// Example9 . 1 2 : I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = 1 / ( s + ( 1 / 2 ) ) Re ( s )> 1/2 159

3 s = %s ; 4 G = syslin ( c ,(1/( s +0.5) ) ) 5 disp (G , G( s )= ) 6 plzr ( G )

Example 9.13 Inverse Lapalce Transform X 1(S ) = 1/(s+1)Re(s) > 1, X 2(S ) = 1/((s + 1)(s + 2))Re(s) > 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

// Example9 . 1 3 // I n v e r s e L a p a l c e T r a n s f o r m //X1 ( S ) = 1 / ( s +1) Re ( s )> 1 //X2 ( S ) = 1 / ( ( s +1) ( s +2) ) Re ( s ) >1 s = %s ; syms t ; G1 = syslin ( c ,(1/( s +1) ) ) ; disp ( G1 , G( s )= ) figure plzr ( G1 ) G2 = syslin ( c ,(1/(( s +1) *( s +2) ) ) ) ; disp ( G2 , G( s )= ) figure plzr ( G2 ) G3 = syslin ( c ,(1/( s +1) ) -(1/(( s +1) *( s +2) ) ) ) ; disp ( G3 , G( s )= ) figure plzr ( G3 )

160

Figure 9.2: Results of Exa 9.13

161

Figure 9.3: Results of Exa 9.13

162

Figure 9.4: Results of Exa 9.13 Example 9.14 Lapalce Transform x(t) = t.exp(at), t > 0, x(t) = (t2 )/2.exp(at), t > 0
1 2 3 4 5 6 7 8 9

// Example9 . 1 4 : L a p a l c e T r a n s f o r m // x ( t ) = t . exp ( a t ) , t >0 // x ( t ) = ( t 2 ) / 2 . exp ( a t ) , t >0 s = %s ; syms t ; a =10; x1 = laplace ( t %e( 10 t ) ,t , s ) ; disp ( x1 ) x2 = laplace ( ( ( t 2 ) / 2 ) %e( 10 t ) ,t , s ) ; 163

10 11 12 13

disp ( x2 ) // R e s u l t // 1 / ( ( s +10) 2 ) // 1 / ( ( s +10) 3 ) Example 9.15 Inverse Lapalce Transform X (S ) = (2s2 + 5s + 5)/((s + 1)2 )(s + 2))Re(s) > 1

1 // Example9 . 1 5 : I n v e r s e L a p a l c e T r a n s f o r m 2 //X( S ) = ( 2 s 2+5 s +5) / ( ( s +1) 2 ) ( s +2) ) Re ( s ) >1 3 s = %s ; 4 syms t ; 5 [ A ]= pfss ((2*( s ^2) +5* s +5) /((( s +1) ^2) *( s +2) ) ) ; //

p a r t i a l f r a c t i o n o f F( s )
6 F1 = ilaplace ( A (1) ,s , t ) 7 F2 = ilaplace ( A (2) ,s , t ) 8 // F3 = i l a p l a c e (A( 3 ) , s , t ) 9 F = F1 + F2 ; 10 disp (F , f ( t )= ) 11 // R e s u l t 12 // ( 2 t ( %e t ) ) (%e t ) +(3 %e (2 t ) )

Example 9.16 Initial Value Theorem of Lapalace Transform


1 2 3 4 5 6 7 8 9 10 11

// Example9 . 1 6 : I n i t i a l V a l u e Theorem o f L a p a l a c e Transform syms s ; num = poly ([12 5 2] , s , c o e f f ) den = poly ([20 14 4 1] , s , c o e f f ) X = num / den disp (X , X( s )= ) SX = s * X ; Initial_Value = limit ( SX ,s , %inf ) ; disp ( Initial_Value , x ( 0 )= ) // R e s u l t // ( 2 % i n f 3+5 % i n f 2+12 % i n f ) / ( % i n f 3+4 % i n f 2+14 % i n f +20) =2 164

Example 9.17 Analysis and Characterization of LTI System Lapalce Transform h(t) = exp(t).u(t)
1 2 3 4 5 6 7

// Example9 . 1 7 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTI System // L a p a l c e T r a n s f o r m h ( t ) = exp ( t ) . u ( t ) syms t s ; h = laplace ( %e( t ) ,t , s ) ; disp ( h ) // R e s u l t // 1 / ( s +1) Example 9.18 Analysis and Characterization of LTI System Lapalce Transform x(t) = exp(abs(t))x(t) = exp(t).u(t) + exp(t).u(t)

1 2 3 4 5 6 7 8

// Example9 . 1 8 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTI System // L a p a l c e T r a n s f o r m x ( t ) = exp ( a b s ( t ) ) // x ( t ) = exp ( t ) . u ( t )+exp ( t ) . u( t ) syms t s ; y = laplace ( %e( t )%e ( t ) ,t , s ) ; disp ( y ) // R e s u l t // ( 1 / ( s +1) ) (1/( s 1) ) Example 9.19 Analysis and Characterization of LTI System Inverse Lapalce Transform X (S ) = (es )/(s + 1)

1 2 3 4 5 6 7 8 9

// Example9 . 1 9 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTI System // I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = ( e s ) / ( s +1) syms s t ; h1 = exp ( -1) ; // I n v e r s e L a p l a c e T r a n s f o r m o f exp ( s ) H2 =1/( s +1) ; h2 = ilaplace ( H2 ,s , t ) h = h1 * h2 ; disp (h , h ( t )= ) 165

10 11

// R e s u l t // ( 1 8 0 8 9 ( %e t ) ) / 4 9 1 7 1 =

0 . 3 6 7 8 7 9 4 ( %e t )

Example 9.20 Inverse Lapalce Transform X (S ) = ((s 1)/((s +1) (s 2)))


1 2 3 4 5 6 7 8 9 10 11 12 13 14

// Example9 . 2 0 : I n v e r s e L a p a l c e T r a n s f o r m //X( S ) = ( ( s 1) / ( ( s +1) ( s 2) ) ) s = %s ; syms t ; [ A ] = pfss ( s /(( s +1) *( s -2) ) ) ; [ B ] = pfss (1/(( s +1) *( s -2) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F3 = ilaplace ( B (1) ,s , t ) F4 = ilaplace ( B (2) ,s , t ) F = F1 + F2 - F3 - F4 ; disp (F , f ( t )= ) // R e s u l t // f ( t )= 3 3 3 3 3 3 2 9 9 9 9 9 9 9 exp ( 2 t ) / 9 9 9 9 9 9 7 0 0 0 0 0 0 0 + 6 6 6 6 6 6 4 %e t / 9 9 9 9 9 9 7 15 // i . e . f ( t ) = 0 . 3 3 3 3 3 3 4 exp ( 2 t ) + 0 . 6 6 6 6 6 6 6 %e( t ) 16 // R e f e r e q u a t i o n 9 . 1 2 0 . ( 1 / 3 ) = 0 . 3 3 3 3 and ( 2 / 3 ) = 0.66666 Example 9.21 Analysis and Characterization of LTI System Lapalce Transform h(t) = exp(2t)u(t), Re(s) > 2
1 2 3 4 5 6 7

// Example9 . 2 1 : A n a l y s i s and C h a r a c t e r i z a t i o n o f LTI System // L a p a l c e T r a n s f o r m h ( t ) = exp ( 2 t ) u ( t ) , Re ( s ) >2 syms t s ; X = laplace ( %e ( 2 t ) ,t , s ) ; disp ( X ) // R e s u l t // 1 / ( s 2)

166

Example 9.25 LTI Systems Characterized by Linear Constant Coecient dierential Equation Finding Transfer function H(S) of LTI system x(t) = exp(3t).u(t)y (t) = [exp(t) exp(2t)].u(t)
1 2 3 4 5 6 7 8 9 10 11 12

// Example9 . 2 5 : LTI S y s t e m s C h a r a c t e r i z e d by L i n e a r Constant // C o e f f i c i e n t d i f f e r e n t i a l E q u a t i o n // F i n d i n g T r a n s f e r f u n c t i o n H( S ) o f LTI s y s t e m // x ( t ) = exp ( 3 t ) . u ( t ) // y ( t ) = [ exp ( t ) exp ( 2 t ) ] . u ( t ) syms t s ; X = laplace ( %e( 3 t ) ,t , s ) ; Y = laplace ( %e( t )%e( 2 t ) ,t , s ) ; H = Y/X; disp ( H ) // R e s u l t // ( s +3) ( 1 / ( s +1) 1/( s +2) ) Example 9.31 Causal LTI Systems described by dierential equations and Rational System functions Partial Fraction H (S ) = ((s 1)/((s +1) (s 2)))

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// Example9 . 3 1 : C a u s a l LTI S y s t e m s d e s c r i b e d by d i f f e r e n t i a l equations // and R a t i o n a l System f u n c t i o n s // P a r t i a l F r a c t i o n //H( S ) = ( ( s 1) / ( ( s +1) ( s 2) ) ) s = %s ; syms t ; [ A ] = pfss ((2* s ^2+4* s -6) /( s ^2+3* s +2) ) ; disp (A , H( S )= ) // R e s u l t H( S )= // // 8 // // 1 + s // 6 // // 2 + s // 167

17

//

Example 9.33 Unilateral Laplace Transform:Time Shifting Property x(t) = exp(a(t + 1)).u(t + 1)
1 2 3 4 5 6 7 8

// Example9 . 3 3 : U n i l a t e r a l L a p l a c e T r a n s f o r m : Time S h i f t i n g Property // x ( t ) = exp ( a ( t +1) ) . u ( t +1) syms t s ; a = 2; X = laplace ( %e( a ( t +1) ) ,t , s ) ; disp ( X ) // R e s u l t //%e a / ( s+a ) Example 9.34 Unilateral Laplace Transform x(t) = s(t) + 2u(t) + et .u(t)

1 // Example9 . 3 4 : U n i l a t e r a l L a p l a c e T r a n s f o r m 2 // x ( t ) = s ( t ) +2u ( t )+e t . u ( t ) 3 syms t s ; 4 a = 2; 5 X = laplace ( 2+%e ( t ) ,t , s ) ; 6 Y = 1+ X ; 7 disp ( X ) 8 disp ( Y ) 9 // R e s u l t 10 // ( 2 / s ) +(1/( s 1) ) +1

Example 9.35 Unilateral Inverse Laplace Transform X (S ) = 1/((s +1)(s + 2))


1 // Example9 . 3 5 : U n i l a t e r a l 2 //X( S ) = 1 / ( ( s +1) ( s +2) ) 3 s = %s ; 4 syms t ; 5 X = 1/(( s +1) *( s +2) ) ; 6 x = ilaplace (X ,s , t ) ;

I n v e r s e Laplace Transform

168

7 8 9 10

disp ( X ) disp ( x ) // R e s u l t // ( %e t ) (%e (2 t ) ) Example 9.36 Unilateral Laplace Transform X (S ) = ((s2 ) 3)/(s + 2)

1 // Example9 . 3 6 : U n i l a t e r a l Laplace Transform 2 //X( S ) = ( ( s 2 ) 3) / ( s +2) 3 s = %s ; 4 syms t ; 5 [ X ] = pfss ((( s ^2) -3) /( s +2) ) ; 6 disp ( X )

Example 9.37 Unilateral Laplace Transform:Solving Dierential Equation Y (S ) = alpha/(s(s + 1)(s + 2))
1 2 3 4 5 6 7 8 9 10 11 12 13

// Example9 . 3 7 : U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation //Y( S ) = a l p h a / ( s ( s +1) ( s +2) ) s = %s ; syms t ; alpha = 1; // Alpha v a l u e a s s i g n e d a s some c o n s t a n t one [ A ] = pfss ( alpha /( s *( s +1) *( s +2) ) ) ; F1 = ilaplace ( A (1) ,s , t ) F2 = ilaplace ( A (2) ,s , t ) F3 = ilaplace ( A (3) ,s , t ) F = F1 + F2 + F3 disp ( F ) // r e s u l t // ( %e t ) +((%e (2 t ) ) / 2 ) +(1/2 ) Example 9.38 Unilateral Laplace Transform:Solving Dierential Equation Y (S ) = [beta(s +3)/((s +1)(s +2))]+[gamma/((s +2)(s +2))]+[alpha/(s(s + 1)(s + 2))]

169

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

// Example9 . 3 8 : U n i l a t e r a l Laplace Transform : S o l v i n g D i f f e r e n t i a l Equation //Y( S ) =[ b e t a ( s +3) / ( ( s +1) ( s +2) ) ] + [ gamma / ( ( s +2) ( s +2) ) ] + [ a l p h a / ( s ( s +1) ( s +2) ) ] s = %s ; syms t ; alpha = 2; // i n p u t c o n s t a n t beta_B = 3; // i n t i a l c o n d i t i o n gamma_v = -5; // i n i t i a l c o n d i t i o n Y1 = 1/ s ; Y2 = 1/( s +1) ; Y3 = 3/( s +2) ; Y = Y1 - Y2 + Y3 ; disp ( Y ) y = ilaplace (Y ,s , t ) disp ( y ) // r e s u l t // ( %e( t ) ) +3 (%e( (2 t ) ) ) +1

170

Chapter 10 The Z-Transform


10.1 Scilab Codes

Example 10.1 Ztransform of x[n] = (a)n .u[n]


1 // Example10 . 1 : Z t r a n s f o r m o f x [ n ] = ( a ) n . u [ n ] 2 syms n z ; 3 a = 0.5; 4 x =( a ) ^ n 5 X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) 6 disp (X , a n s= ) 7 // R e s u l t 8 // 1 . 0 ( 2 ( %inf 1) z ( %inf 1) 1) / ( 1 / ( 2 z ) 1) 9 // E q u i v a l e n t t o 1 / ( 0 . 5 ( z 1) 1)

Example 10.2 Ztransform of x[n] = an .u[n 1]


1 2 3 4 5 6 7 8 9

// Example 1 0 . 2 : Z t r a n s f o r m o f x [ n ] = a n . u[ n 1] // a = 0 . 5 clear all ; close ; clc ; syms n z ; a = 0.5; x = -(0.5) ^( - n ) X = symsum ( x *( z ^( n ) ) ,n ,1 , %inf ) 171

10 11 12 13

disp (X , a n s= ) // R e s u l t // 1 . 0 ( 2 ( % i n f +1) z ( % i n f +1) 2 z ) / ( 2 z 1) // E q u i v a l e n t t o 12 z / ( 2 z 1) = 1 / ( 1 0 . 5 z 1) Example 10.3 Ztransform of x[n] = 7.(1/3)n .u[n] 6.(1/2)n .u[n]

1 2 3 4 5 6 7 8 9 10 11 12

// Example 1 0 . 3 : Z t r a n s f o r m o f x [ n ] = 7 . ( 1 / 3 ) n . u [ n ] 6 . ( 1 / 2 ) n . u [ n ] syms n z ; x1 =(0.33) ^( n ) X1 = symsum (7* x1 *( z ^( - n ) ) ,n ,0 , %inf ) x2 =(0.5) ^( n ) X2 = symsum (6* x2 *( z ^( - n ) ) ,n ,0 , %inf ) X = X1 - X2 disp (X , a n s= ) // R e s u l t // 6.0 (2( %inf 1) z ( %inf 1) 1) / ( 1 / ( 2 z ) 1) // E q u i v a l e n t t o 6 1/(0.5 z 1 1) // The R e g i o n o f C o n v e r g e n c e i s | z | > 1/2 Example 10.4 Z-transform of sine signal

1 2 3 4 5 6 7 8 9 10

// Example10 . 4 : Z t r a n s f o r m o f s i n e s i g n a l syms n z ; Wo = %pi /4; a = (0.33) ^ n ; x1 = %e ^( sqrt ( -1) * Wo * n ) ; X1 = symsum ( a * x1 *( z ^( - n ) ) ,n ,0 , %inf ) x2 = %e ^( - sqrt ( -1) * Wo * n ) X2 = symsum ( a * x2 *( z ^( - n ) ) ,n ,0 , %inf ) X =(1/(2* sqrt ( -1) ) ) *( X1 - X2 ) disp (X , a n s= ) Example 10.5 Z-transform of Impulse Sequence

// Example10 . 5 : Z t r a n s f o r m o f I m p u l s e S e q u e n c e 172

2 syms n z ; 3 X = symsum (1*( z ^( - n ) ) ,n ,0 ,0) ; 4 disp (X , a n s= ) 5 // R e s u l t 6 // 1

Example 10.6 Ztransform of x[n] = an , 0 < n < N 1


1 2 3 4 5 6 7 8 9

// Example 1 0 . 6 : Z t r a n s f o r m o f x [ n ] = a n , 0 < n < N 1 syms n z ; a = 0.5; N =6; x =( a ) ^( n ) X = symsum ( x *( z ^( - n ) ) ,n ,0 , N ) disp (X , a n s= ) // R e s u l t // 0 . 5 / z + 0 . 2 5 / z 2 + 0 . 1 2 5 / z 3 + 0 . 0 6 2 5 / z 4 + 0 . 0 3 1 2 5 / z 5+0.015625/ z 6+1.0 Example 10.7 Ztransform of x[n] = bn .u[n] + b n.u[n 1]

1 2 3 4 5 6 7 8 9 10 11 12 13

// Example 1 0 . 7 : Z t r a n s f o r m o f x [ n ] = b n . u [ n ]+ bn . u [ n 1] syms n z ; b = 0.5; x1 =( b ) ^( n ) x2 =( b ) ^( - n ) X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) X2 = symsum ( x2 *( z ^( n ) ) ,n ,1 , %inf ) X = X1 + X2 ; disp (X , a n s= ) // R e s u l t // +1.0 (2( %inf 1) z ( %inf 1) 1) / ( 1 / ( 2 z ) 1) // E q u i v a l e n t t o 1 / ( 0 . 5 z 1 1 ) // R e g i o n o f C o n v e r g e n c e | z | > 0 . 5 Example 10.9 Inverse Z Transform :ROC |z | > 1/3 173

1 // Example10 . 9 : I n v e r s e Z T r a n s f o r m :ROC | z | > 1/3 2 z = %z ; 3 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must 4 5 6 7 8 9 10 11 12 13 14 15 16 17

be l i n e a r z = z 1 X = z *(3* z -(5/6) ) /(( z -(1/4) ) *( z -(1/3) ) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = z1 *(3* z1 -(5/6) ) /(( z1 -(1/4) ) *( z1 -(1/3) ) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 , h1 [ n ]= ) h2 = limit ( F2 , z1 , zp (2) ) ; disp ( h2 , h2 [ n ]= ) h = h1 + h2 ; disp (h , h [ n ]= ) // // R e s u l t // h [ n ]= ( 1 / 4 ) n + ( 2 / 3 ) n Example 10.10 Inverse Z Transform :ROC 1/4 < |z | < 1/3

1 // Example10 . 1 0 : I n v e r s e Z T r a n s f o r m :ROC 1/4 < | z | < 1/3 2 z = %z ; 3 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must 4 5 6 7 8 9 10 11 12 13 14 15 16

be l i n e a r z = z 1 X = z *(3* z -(5/6) ) /(( z -(1/4) ) *( z -(1/3) ) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = z1 *(3* z1 -(5/6) ) /(( z1 -(1/4) ) *( z1 -(1/3) ) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 * u ( n ) , h1 [ n ]= ) h2 = limit ( F2 , z1 , zp (2) ) ; disp (( h2 ) * u( n 1) , h2 [ n ]= ) disp (( h1 ) * u ( n ) -( h2 ) * u ( n 1) , h [ n ]= ) // // R e s u l t // h [ n ]= u ( n ) /4 n 2 u ( n 1) /3 n 174

17

// E q u i v a l e n t t o h [ n ] = ( 1 / 4 ) n . u [ n ] 2 ( 1 / 3 ) n . u[ n 1] Example 10.11 Inverse Z Transform :ROC |z | < 1/4

1 // Example10 . 1 1 : I n v e r s e Z T r a n s f o r m :ROC | z | < 1/4 2 z = %z ; 3 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must 4 5 6 7 8 9 10 11 12 13 14 15 16 17

be l i n e a r z = z 1 X = z *(3* z -(5/6) ) /(( z -(1/4) ) *( z -(1/3) ) ) X1 = denom ( X ) ; zp = roots ( X1 ) ; X1 = z1 *(3* z1 -(5/6) ) /(( z1 -(1/4) ) *( z1 -(1/3) ) ) F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; h1 = limit ( F1 , z1 , zp (1) ) ; disp ( h1 * u( n 1) , h1 [ n ]= ) h2 = limit ( F2 , z1 , zp (2) ) ; disp (( h2 ) * u( n 1) , h2 [ n ]= ) disp ( -( h1 ) * u( n 1) -( h2 ) * u( n 1) , h [ n ]= ) // // R e s u l t // h [ n ]= u( n 1) /4 n 2 u( n 1) /3 n // E q u i v a l e n t t o h [ n ] = (1/4) n . u[ n 1] 2 (1/3) n . u[ n 1] Example 10.12 Inverse z tranform:For Finite duration discrete sequence

1 2 3 4 5 6 7 8

// Example10 . 1 2 : I n v e r s e z t r a n f o r m : For F i n i t e duration d i s c r e t e sequence syms z ; X = [4* z ^2 0 2 3* z ^ -1]; n = -2:1; for i = 1: length ( X ) x ( i ) = X ( i ) *( z ^ n ( i ) ) ; end disp (x , x [ n ]= ) Example 10.13 Inverse z tranform ofInFinite duration discrete sequence Power Series Method (OR) Long Division Method 175

1 2 3 4 5

// Example10 . 1 3 : I n v e r s e z t r a n f o r m o f I n F i n i t e duration d i s c r e t e sequence // Power S e r i e s Method (OR) // Long D i v i s i o n Method z = %z ; a = 2; X = ldiv (z ,z -a ,5) Example 10.18 Ztransform-Dierentiation Property x[n] = (a)n .u[n]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

// Example10 . 1 8 : Z t r a n s f o r m D i f f e r e n t i a t i o n P r o p e r t y // x [ n ] = ( a ) n . u [ n ] syms n z ; a = 0.5; x =( a ) ^ n X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) X1 = -1/((1/(2* z ) ) -1) // z t r a n s f o r m o f 0 . 5 n . u [ n] Y = -z * diff (X , z ) // D i f f e r e n t i a t i o n p r o p e r t y o f z transform disp (X , a n s= ) disp (Y , a n s= ) // R e s u l t //X( z ) = 1 . 0 ( 2 ( %inf 1) z ( %inf 1) 1) / ( 1 / ( 2 z ) 1) //Y( z ) = 1.0 ( %inf 1) 2( %inf 1) z ( %inf 1) / ( 1 / ( 2 z ) 1) //Y1 ( z ) = 1 / ( 2 ( 1 / ( 2 z ) 1) 2 z ) // E q u i v a l e n t t o Y1 ( z ) = 0 . 5 z 1/((1 0.5 z 1) 2 ) Example 10.19 Z Transform : Initial Value Theorem

1 // Example10 . 1 9 : Z T r a n s f o r m : I n i t i a l V a l u e Theorem 2 z = %z ; 3 syms n z1 ; //To f i n d o u t I n v e r s e z t r a n s f o r m z must

be l i n e a r z = z 1 4 X = z *( z -(3/2) ) /(( z -(1/3) ) *( z -(1/2) ) ) 5 X1 = denom ( X ) ; 6 zp = roots ( X1 ) ; 7 X1 = z1 *( z1 -(3/2) ) /(( z1 -(1/3) ) *( z1 -(1/2) ) ) 176

8 9 10 11 12 13 14 15 16 17 18

F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ; F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ; x1 = limit ( F1 , z1 , zp (1) ) ; x2 = limit ( F2 , z1 , zp (2) ) ; x = x1 + x2 ; disp (x , x [ n ]= ) x_initial = limit (x ,n ,0) ; disp ( x_initial , x [ 0 ] = ) // // R e s u l t // x [ n ]= 7 / 3 n 3 2(1 n ) // x [ 0 ] = 1 ; I n i t i a l V a l u e Example 10.23 Inverse Z Transform H(z) =z/z-a

1 2 3 4 5 6 7 8

// Example10 . 2 3 : I n v e r s e Z T r a n s f o r m H( z ) =z / z a // z = %z ; syms n z ; a = 2; H = z /( z - a ) ; F = H * z ^( n -1) *( z - a ) ; h = limit (F ,z , a ) ; disp (h , h [ n ]= ) Example 10.25 LTi Systems characterized by Linear Constant Coecient Dierence equations Inverse Z Transform

1 2 3 4 5 6 7 8 9 10 11

// Example10 . 2 5 : LTi S y s t e m s c h a r a c t e r i z e d by L i n e a r Constant // C o e f f i c i e n t D i f f e r e n c e e q u a t i o n s // I n v e r s e Z T r a n s f o r m // z = %z ; syms n z ; H1 = z /( z -(1/2) ) ; H2 = (1/3) /( z -(1/2) ) ; F1 = H1 * z ^( n -1) *( z -(1/2) ) ; F2 = H2 * z ^( n -1) *( z -(1/2) ) ; h1 = limit ( F1 ,z ,1/2) ; disp ( h1 , h1 [ n ]= ) 177

12 h2 = limit ( F2 ,z ,1/2) ; 13 disp ( h2 , h2 [ n ]= ) 14 h = h1 + h2 ; 15 disp (h , h [ n ]= ) 16 // R e s u l t 17 // h [ n ]= [ ( 1 / 2 ) n ] + [ 2 (1 n ) ] / 3 18 // Which i s E q u i v a l e n t t o h [ n ] = [ ( 1 / 2 ) n ] + [ ( 1 / 2 ) ( n

1) ] / 3 Example 10.33 Dierentiation Property of Unilateral Ztransform x[n] = (a)( n + 1).u[n + 1]


1 2 3 4 5 6 7 8 9 10

// Example10 . 3 3 : D i f f e r e n t i a t i o n P r o p e r t y o f U n i l a t e r a l Ztransform // x [ n ] = ( a ) ( n+1) . u [ n +1] syms n z ; a = 0.5; x =( a ) ^( n +1) X = symsum ( x *( z ^( - n ) ) ,n , -1 , %inf ) disp (X , a n s= ) // R e s u l t //X( z )= 0 . 5 ( 2 ( %inf 1) z ( %inf 1) 2 z ) / ( 1 / ( 2 z ) 1) // E q u i v a l e n t t o z / ( 1 0 . 5 z 1) Example 10.34 Unilateral Ztransform- partial fraction X (z ) = (3 (5/6) (z 1))/((1 (1/4) (z 1)) (1 (1/3) (z 1)))

1 2 3 4 5 6 7

// Example10 . 3 4 : U n i l a t e r a l Z t r a n s f o r m p a r t i a l fraction // X( z ) =(3 (5/6) ( z 1) ) / ( ( 1 ( 1 / 4 ) ( z 1) ) ( 1 ( 1 / 3 ) ( z 1) ) ) z = %z ; s = %s ; syms n t ; a = 0.5; [ A ]= pfss ((3 -(5/6) *( z ^ -1) ) /((1 -(1/4) *( z ^ -1) ) *(1 -(1/3) *( z ^ -1) ) ) ) 178

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

x1 = horner ( A (1) ,z ) x2 = horner ( A (2) ,z ) x3 = A (3) x = x1 + x2 + x3 disp ( x1 , a n s= ) disp ( x2 , a n s= ) disp ( x3 , a n s= ) disp (x , a n s= ) // R e s u l t // // // // // // // 3 // sum o f t h e s e , g i v e s t h e o r i g i n a l v a l u e // 2 // 0.8333333 z + 3z // // 2 // 0.0833333 0.5833333 z + z Example 10.36 Output response of an LTI System 0.6666667 0.3333333 + z 0.25 0.25 + z

1 2 3 4 5 6 7 8

// Example 1 0 . 3 6 : To f i n d o u t p u t r e s p o n s e o f an LTI System syms n z ; H = z /( z +3) X = z /( z -1) Y = X*H F1 = Y *( z ^( n -1) ) *( z -1) ; y1 = limit ( F1 ,z ,1) ; F2 = Y *( z ^( n -1) ) *( z +3) ; 179

9 y2 = limit ( F2 ,z , -3) ; 10 disp ( y1 * u ( n ) + y2 * u ( n ) , y [ n ]= ) 11 // R e s u l t 12 // y [ n ] = u ( n ) /4 ( 3) ( n+1) u ( n ) /4 13 // E q u i v a l e n t t o = ( 1 / 4 ) . u [ n ] ( 3 / 4 ) ( 3) n . u [ n ]

Example 10.37 Output response of an LTI System


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

// Example 1 0 . 3 7 : To f i n d o u t p u t r e s p o n s e o f an LTI System syms n z ; alpha = 8; // i n p u t c o n s t a n t beta_b = 1; // i n i t i a l c o n d i t i o n y [ 1 ] = 1 Y1 = -((3* beta_b * z ) /( z +3) ) Y2 = ( alpha * z ^2/(( z +3) *( z -1) ) ) F1 = Y1 *( z ^( n -1) ) *( z +3) ; y1 = limit ( F1 ,z , -3) ; F2 = Y2 *( z ^( n -1) ) *( z +3) ; y2 = limit ( F2 ,z , -3) ; F3 = Y2 *( z ^( n -1) ) *( z -1) ; y3 = limit ( F3 ,z ,1) ; disp (( y1 + y2 + y3 ) * u ( n ) , y [ n ]= ) // R e s u l t // y [ n ] = (2 ( 3) ( n+1) ) u ( n )

180

Chapter 11 Linear Feedback Systems


11.1 Scilab Codes

Example 11.1 Root locus Analysis of Linear Feedback Systems Continuous Time Systems
1 2 3 4 5 6 7 8 9

// Example11 . 1 : Root l o c u s A n a l y s i s o f L i n e a r Feedback Systems // C o n t i n u o u s Time S y s t e m s // R e f e r f i g u r e 1 1 . 1 2 ( a ) i n Openhiem &W i l l k s y p a g e 840 s = %s ; H = syslin ( c ,[1/( s +1) ]) ; G = syslin ( c ,[1/( s +2) ]) ; F = G*H; clf ; evans (F ,3)

181

Figure 11.1: Results of Exa 11.1 Example 11.2 Root locus Analysis of Linear Feedback Systems Continuous Time Systems
1 2 3 4 5 6 7

// Example11 . 2 : Root l o c u s A n a l y s i s o f L i n e a r Feedback Systems // C o n t i n u o u s Time S y s t e m s // R e f e r f i g u r e 1 1 . 1 4 ( a ) i n Openhiem &W i l l k s y p a g e 844 s = %s ; G = syslin ( c ,[(s -1) /(( s +1) *( s +2) ) ]) ; clf ; evans (G ,2) 182

Figure 11.2: Results of Exa 11.2 Example 11.3 Root locus Analysis of Linear Feedback Systems Discrete time system // Example11 . 3 : Root l o c u s A n a l y s i s o f L i n e a r Feedback Systems 2 // // D i s c r e t e t i m e s y s t e m 3 // R e f e r f i g u r e 1 1 . 1 6 ( a ) i n Openhiem &W i l l k s y p a g e 846 4 z = %z ;
1

183

5 G = syslin ( d ,[ z /(( z -0.5) *( z -0.25) ) ]) ; 6 clf ; 7 evans (G ,2)

Figure 11.3: Results of Exa 11.3 Example 11.5Bode Nyquist criterion for Continuous Time Systems Bode Plot // Example 1 1 . 5 : N y q u i s t c r i t e r i o n f o r C o n t i n u o u s Time Systems 2 // Bode P l o t 3 s = %s ;
1

184

4 5 6 7 8 9 10

// Open Loop T r a n s f e r F u n c t i o n G = syslin ( c ,[1/( s +1) ]) ; H = syslin ( c ,[1/(0.5* s +1) ]) ; F = G*H; clf ; bode (F ,0.01 ,100) show_margins ( F )

Figure 11.4: Results of Exa 11.5Bode Example 11.5Nyquist Nyquist criterion for Continuous Time Systems Nyquist Plot

185

1 2 3 4 5 6 7 8 9 10

// Example 1 1 . 5 : N y q u i s t c r i t e r i o n f o r C o n t i n u o u s Time Systems // N y q u i s t P l o t s = %s ; // Open Loop T r a n s f e r F u n c t i o n G = syslin ( c ,[1/( s +1) ]) ; H = syslin ( c ,[1/(0.5* s +1) ]) ; F = G*H; clf ; nyquist ( F ) show_margins (F , n y q u i s t )

Figure 11.5: Results of Exa 11.5Nyquist 186

Example 11.6 Nyquist criterion for Continuous Time Systems Nyquist Plot
1 2 3 4 5 6 7 8

// Example 1 1 . 6 : N y q u i s t c r i t e r i o n f o r C o n t i n u o u s Time Systems // N y q u i s t P l o t s = %s ; // Open Loop T r a n s f e r F u n c t i o n F = syslin ( c ,[( s +1) /(( s -1) *(0.5* s +1) ) ]) clf ; nyquist ( F ) show_margins (F , n y q u i s t )

Figure 11.6: Results of Exa 11.6 187

Example 11.7 Nyquist Plot


1 2 3 4 5 6 7 8 9

// Example 1 1 . 7 // N y q u i s t P l o t s = %s ; T =1; // Open Loop T r a n s f e r F u n c t i o n G = syslin ( c ,[ - %e ^( - s * T ) ]) ; clf ; nyquist ( G ) show_margins (G , n y q u i s t ) Example 11.8 Nyquist criterion for Discrete Time Systems Nyquist Plot Discrete Time System

1 2 3 4 5 6 7 8 9

// Example 1 1 . 8 : N y q u i s t c r i t e r i o n f o r D i s c r e t e Time Systems // N y q u i s t P l o t // D i s c r e t e Time System z = %z ; // Open Loop T r a n s f e r F u n c t i o n F = syslin ( d ,[1/( z *( z +0.5) ) ]) clf ; nyquist ( F ) show_margins (F , n y q u i s t )

188

Figure 11.7: Results of Exa 11.8 Example 11.9 Gain and Phase Margins and their associated cross over frequencies
1 // Example 1 1 . 9 : Gain and Phase M a r g i n s and t h e i r 2 // a s s o c i a t e d c r o s s o v e r f r e q u e n c i e s 3 s = poly (0 , s ) ; // D e f i n e s s a s p o l y n o m i a l v a r i a b l e 4 // C r e a t e s t r a n s f e r f u n c t i o n i n f o r w a r d p a t h 5 F = syslin ( c ,[(4*(1+0.5* s ) ) /( s *(1+2* s ) *(1+0.05* s

+(0.125* s ) ^2) ) ])
6 B = syslin ( c ,(1+0* s ) /(1+0* s ) ) 7 OL = F * B ; 8 fmin = 0.01; // Min f r e q i n Hz

189

9 fmax = 10; // Max f r e q i n Hz 10 scf (1) ; 11 // c l f ; 12 // P l o t f r e q u e n c y r e s p o n s e o f open l o o p 13 14 15 16 17 18 19 20 21

transfer function bode ( OL ,0.01 ,10) ; // d i s p l a y g a i n and p h a s e m a r g i n and c r o s s o v e r frequencies show_margins ( OL ) ; [ gm , fr1 ] = g_margin ( OL ) [ phm , fr2 ] = p_margin ( OL ) disp ( gm , g a i n m a r g i n i n dB ) disp ( fr1 , g a i n c r o s s o v e r f r e q u e n c y i n Hz ) disp ( phm , p h a s e m a r g i n i n dB ) disp ( fr2 , p h a s e c r o s s o v e r f r e q u e n c y i n Hz )

190

Figure 11.8: Results of Exa 11.9

2 3 4 5 6 7 8 9 10

Example 11.9 1 // F i g u r e 1 1 . 9 : Root l o c u s a n a l y s i s o f Linear feedback systems s = %s ; beta_b1 = 1; beta_b2 = -1; G1 = syslin ( c ,[2* beta_b1 / s ]) ; G2 = syslin ( c ,[2* beta_b2 / s ]) ; H = syslin ( c ,[ s /( s -2) ]) ; F1 = G1 * H ; F2 = G2 * H ; clf ; 191

11 12 13

evans ( F1 ,2) figure evans ( F2 ,2)

Figure 11.9: Results of Exa 11.9

192

Figure 11.10: Results of Exa 11.9

193