0% found this document useful (0 votes)
307 views202 pages

Scilab Companion for Signals and Systems

This document provides a list of Scilab codes that correspond to examples, equations, and sections from the textbook "Signals And Systems" by P. R. Rao. There are over 100 Scilab codes listed that provide worked examples and simulations related to signals and systems topics like Laplace transforms, Fourier analysis, sampling, and more. The codes are grouped by chapter and labeled according to the example or section they relate to from the textbook for easy reference.

Uploaded by

Shirish Ransing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
307 views202 pages

Scilab Companion for Signals and Systems

This document provides a list of Scilab codes that correspond to examples, equations, and sections from the textbook "Signals And Systems" by P. R. Rao. There are over 100 Scilab codes listed that provide worked examples and simulations related to signals and systems topics like Laplace transforms, Fourier analysis, sampling, and more. The codes are grouped by chapter and labeled according to the example or section they relate to from the textbook for easy reference.

Uploaded by

Shirish Ransing
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Scilab Textbook Companion for

Signals And Systems


by P. R. Rao1

Created by
Satyam Agrawal
[Link]
Instrumentation Engineering
Krishna Institute Of Engineering and Technology
College Teacher
Varun Gupta
Cross-Checked by
Chaitanya

May 24, 2016

1 Funded by a grant from the National Mission on Education through ICT,


[Link] This Textbook Companion and Scilab
codes written in it can be downloaded from the Textbook Companion Project
section at the website [Link]
Book Description

Title: Signals And Systems

Author: P. R. Rao

Publisher: TMH Education Pvt. Ltd., New Delhi

Edition: 5

Year: 2011

ISBN: 978-0-07-066927-7

1
Scilab numbering policy used in this document and the relation to the
above book.

Exa Example (Solved example)

Eqn Equation (Particular equation of the above book)

AP Appendix to Example(Scilab Code that is an Appednix to a particular


Example of the above book)

For example, Exa 3.51 means solved example 3.51 of this book. Sec 2.3 means
a scilab code whose theory is explained in Section 2.3 of the book.

2
Contents

List of Scilab Codes 4

1 Signals Continuous and Discrete time 6

2 Laplace and Z Transform 28

3 Fourier Series of Continuous Time Signals 43

4 The Continuous Time Fourier Transform 56

5 Fourier Representation of Discrete Time Signals 79

6 Sampling and Reconstruction of Bandlimited Signals 101

7 Systems 113

8 Systems Time and Frequency Domain Analysis 143

9 Convolution and Correlation Continuous Time Signals 158

10 Discrete Time Convolution and Correlation 174

11 Hilbert Transform Continuous and Discrete 184

3
List of Scilab Codes

Exa 1.1 Finding Fundamental Period . . . . . . . . . . . . . . 6


Exa 1.3.a Periodicity . . . . . . . . . . . . . . . . . . . . . . . . 7
Exa 1.3.b Periodicity and fundamental period . . . . . . . . . . . 9
Exa 1.4 Fundamental Period . . . . . . . . . . . . . . . . . . . 11
Exa 1.5 Fundamental Period . . . . . . . . . . . . . . . . . . . 12
Exa 1.6 Fundamental Period . . . . . . . . . . . . . . . . . . . 14
Exa 1.7 Even and odd Components . . . . . . . . . . . . . . . 15
Exa 1.11 Waveforms . . . . . . . . . . . . . . . . . . . . . . . . 17
Exa 1.12 Time Scaling . . . . . . . . . . . . . . . . . . . . . . . 23
Exa 1.13 Plot at a particular sampling frequency . . . . . . . . 23
Exa 2.1 Laplace Transform . . . . . . . . . . . . . . . . . . . . 28
Exa 2.2 Inverse Laplace . . . . . . . . . . . . . . . . . . . . . . 28
Exa 2.3 Initial Value Theorem . . . . . . . . . . . . . . . . . . 29
Exa 2.4 Laplace Transform . . . . . . . . . . . . . . . . . . . . 30
Exa 2.6 Circuit Current . . . . . . . . . . . . . . . . . . . . . . 30
Exa 2.7 Inverse Laplace Transform . . . . . . . . . . . . . . . . 30
Exa 2.8 Inverse Laplace Transform . . . . . . . . . . . . . . . . 31
Exa 2.9 Circuit Current . . . . . . . . . . . . . . . . . . . . . . 32
Exa 2.10 Laplace Transform . . . . . . . . . . . . . . . . . . . . 32
Exa 2.15 Laplace Transform . . . . . . . . . . . . . . . . . . . . 33
Exa 2.16 Laplace Transform . . . . . . . . . . . . . . . . . . . . 34
Exa 2.17 Laplace Transform . . . . . . . . . . . . . . . . . . . . 34
Exa 2.19 Laplace Transform . . . . . . . . . . . . . . . . . . . . 36
Exa 2.21 Unilateral Z Transform . . . . . . . . . . . . . . . . . 37
Exa 2.29 Z Transform . . . . . . . . . . . . . . . . . . . . . . . 38
Exa 2.37 Inverse Z Transform . . . . . . . . . . . . . . . . . . . 38
Exa 2.38.a Inverse Z Transform . . . . . . . . . . . . . . . . . . . 39
Exa 2.38.b Inverse Z Transform . . . . . . . . . . . . . . . . . . . 40

4
Exa 2.39 Inverse Z Transform . . . . . . . . . . . . . . . . . . . 41
Exa 2.40 Inverse Z Transform . . . . . . . . . . . . . . . . . . . 41
Exa 3.13 Complex Fourier Exponential Series . . . . . . . . . . 43
Exa 3.14 Complex Fourier Exponential Series . . . . . . . . . . 49
Exa 3.16 Complex Fourier Exponential Series . . . . . . . . . . 50
Exa 3.17 Complex Fourier Exponential Series . . . . . . . . . . 54
Exa 3.18 Trignometric Series . . . . . . . . . . . . . . . . . . . . 55
Exa 4.1 Magnitude and Phase Spectra . . . . . . . . . . . . . . 56
Exa 4.2 Magnitude and Phase Spectra . . . . . . . . . . . . . . 60
Exa 4.3 Magnitude and Phase Spectra . . . . . . . . . . . . . . 65
Exa 4.4 Energy at output . . . . . . . . . . . . . . . . . . . . . 66
Exa 4.5 Fourier Transform . . . . . . . . . . . . . . . . . . . . 66
Exa 4.6 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 69
Exa 4.7 Energy in Signal . . . . . . . . . . . . . . . . . . . . . 71
Exa 4.11 Fourier Transform . . . . . . . . . . . . . . . . . . . . 72
Exa 4.14 Fourier Transform . . . . . . . . . . . . . . . . . . . . 72
Exa 4.17 Fourier Transform . . . . . . . . . . . . . . . . . . . . 75
Exa 5.1 DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Exa 5.2 DTFT and Spectra . . . . . . . . . . . . . . . . . . . . 80
Exa 5.3 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . 83
Exa 5.4 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . 86
Exa 5.5 Fourier series . . . . . . . . . . . . . . . . . . . . . . . 89
Exa 5.9.i DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Exa [Link] DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Exa [Link] DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Exa 5.11 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . 95
Exa 5.13 Circular Convolution . . . . . . . . . . . . . . . . . . . 96
Exa 5.14 Circular Convolution . . . . . . . . . . . . . . . . . . . 98
Exa 5.16 DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Exa 5.18 DFT coefficients . . . . . . . . . . . . . . . . . . . . . 100
Exa 6.1 Sampling and Reconstruction . . . . . . . . . . . . . . 101
Exa 6.2 Sampling and Reconstruction . . . . . . . . . . . . . . 102
Exa 6.3 Minimum Number of samples . . . . . . . . . . . . . . 106
Exa 6.4 Minimum Sampling Frequency . . . . . . . . . . . . . 108
Exa 6.5 LPF output . . . . . . . . . . . . . . . . . . . . . . . . 108
Exa 6.6 Sampling Frequency . . . . . . . . . . . . . . . . . . . 110
Exa 6.8 Minimum Sampling Frequency . . . . . . . . . . . . . 112
Exa 7.1 Properties of System . . . . . . . . . . . . . . . . . . . 113

5
Exa 7.3 System Properties . . . . . . . . . . . . . . . . . . . . 114
Exa 7.4 System Properties . . . . . . . . . . . . . . . . . . . . 115
Exa 7.5 System Properties . . . . . . . . . . . . . . . . . . . . 116
Exa 7.6 System Properties . . . . . . . . . . . . . . . . . . . . 117
Exa 7.7 Properties of System . . . . . . . . . . . . . . . . . . . 118
Exa 7.8 Properties of System . . . . . . . . . . . . . . . . . . . 119
Exa 7.9 Properties of System . . . . . . . . . . . . . . . . . . . 120
Exa 7.10 Output of an LTI . . . . . . . . . . . . . . . . . . . . 121
Exa 7.11 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 121
Exa 7.14 Impulse and Step response . . . . . . . . . . . . . . . 123
Exa 7.15 Impulse and Step Response . . . . . . . . . . . . . . . 125
Exa 7.19 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 128
Exa 7.22 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 131
Exa 7.23 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 134
Exa 7.24 Step Response . . . . . . . . . . . . . . . . . . . . . . 135
Exa 7.25 Step response . . . . . . . . . . . . . . . . . . . . . . . 137
Exa 7.33 Magnitude and Phase Response . . . . . . . . . . . . . 140
Exa 8.1 Magnitude and Phase Responses . . . . . . . . . . . . 143
Exa 8.2 Transfer Function of system . . . . . . . . . . . . . . . 146
Exa 8.3 Magnitude and Phase Responses . . . . . . . . . . . . 146
Exa 8.4 system response . . . . . . . . . . . . . . . . . . . . . 149
Exa 8.5 System function . . . . . . . . . . . . . . . . . . . . . 151
Exa 8.8 Transfer function . . . . . . . . . . . . . . . . . . . . . 153
Exa 8.9 Transfer function by block diagram reduction . . . . . 155
Exa 8.10 Realization Structure . . . . . . . . . . . . . . . . . . 155
Exa 8.12 Transfer function Realization . . . . . . . . . . . . . . 156
Exa 8.13 Parallel form realization . . . . . . . . . . . . . . . . . 157
Exa 9.1 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 158
Exa 9.3 Convolution . . . . . . . . . . . . . . . . . . . . . . . . 160
Exa 9.4 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . 161
Exa 9.5 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . 163
Exa 9.6 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . 165
Exa 9.7 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . 168
Exa 9.10 Autocorrelation Function . . . . . . . . . . . . . . . . 171
Exa 9.11 PSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Exa 10.1 Cross Correlation . . . . . . . . . . . . . . . . . . . . . 174
Exa 10.2 Cross Correlation Sequence . . . . . . . . . . . . . . . 176
Exa 10.4 Auto Correlation . . . . . . . . . . . . . . . . . . . . . 178

6
Exa 10.5 Auto Correlation . . . . . . . . . . . . . . . . . . . . . 178
Exa 10.8 Auto Correlation . . . . . . . . . . . . . . . . . . . . . 180
Exa 10.11 System response . . . . . . . . . . . . . . . . . . . . . 181
Exa 11.1 Hilbert Transform . . . . . . . . . . . . . . . . . . . . 184
Exa 11.2 Hilbert Transform . . . . . . . . . . . . . . . . . . . . 187
Exa 11.3 Hilbert Transform . . . . . . . . . . . . . . . . . . . . 189
Exa 11.6 Hilbert Transform . . . . . . . . . . . . . . . . . . . . 192

7
List of Figures

1.1 Finding Fundamental Period . . . . . . . . . . . . . . . . . . 7


1.2 Finding Fundamental Period . . . . . . . . . . . . . . . . . . 8
1.3 Periodicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Periodicity and fundamental period . . . . . . . . . . . . . . 11
1.5 Fundamental Period . . . . . . . . . . . . . . . . . . . . . . 13
1.6 Fundamental Period . . . . . . . . . . . . . . . . . . . . . . 14
1.7 Fundamental Period . . . . . . . . . . . . . . . . . . . . . . 16
1.8 Even and odd Components . . . . . . . . . . . . . . . . . . . 18
1.9 Even and odd Components . . . . . . . . . . . . . . . . . . . 19
1.10 Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.11 Waveforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
1.12 Time Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1.13 Time Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.14 Plot at a particular sampling frequency . . . . . . . . . . . . 27

2.1 Laplace Transform . . . . . . . . . . . . . . . . . . . . . . . 33


2.2 Laplace Transform . . . . . . . . . . . . . . . . . . . . . . . 35
2.3 Laplace Transform . . . . . . . . . . . . . . . . . . . . . . . 36
2.4 Laplace Transform . . . . . . . . . . . . . . . . . . . . . . . 37

3.1 Complex Fourier Exponential Series . . . . . . . . . . . . . . 44


3.2 Complex Fourier Exponential Series . . . . . . . . . . . . . . 45
3.3 Complex Fourier Exponential Series . . . . . . . . . . . . . . 47
3.4 Complex Fourier Exponential Series . . . . . . . . . . . . . . 48
3.5 Complex Fourier Exponential Series . . . . . . . . . . . . . . 50
3.6 Complex Fourier Exponential Series . . . . . . . . . . . . . . 52
3.7 Complex Fourier Exponential Series . . . . . . . . . . . . . . 53

4.1 Magnitude and Phase Spectra . . . . . . . . . . . . . . . . . 57

8
4.2 Magnitude and Phase Spectra . . . . . . . . . . . . . . . . . 58
4.3 Magnitude and Phase Spectra . . . . . . . . . . . . . . . . . 60
4.4 Magnitude and Phase Spectra . . . . . . . . . . . . . . . . . 61
4.5 Magnitude and Phase Spectra . . . . . . . . . . . . . . . . . 63
4.6 Magnitude and Phase Spectra . . . . . . . . . . . . . . . . . 64
4.7 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . 67
4.8 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . 68
4.9 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
4.10 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . 73
4.11 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . 74
4.12 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . 76
4.13 Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . 77

5.1 DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
5.2 DTFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
5.3 DTFT and Spectra . . . . . . . . . . . . . . . . . . . . . . . 84
5.4 DTFT and Spectra . . . . . . . . . . . . . . . . . . . . . . . 85
5.5 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . . . . 87
5.6 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . . . . 88
5.7 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.8 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . . . . 91
5.9 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . . . . 96
5.10 Inverse Fourier . . . . . . . . . . . . . . . . . . . . . . . . . 97

6.1 Sampling and Reconstruction . . . . . . . . . . . . . . . . . 103


6.2 Sampling and Reconstruction . . . . . . . . . . . . . . . . . 104
6.3 Sampling and Reconstruction . . . . . . . . . . . . . . . . . 106
6.4 Sampling and Reconstruction . . . . . . . . . . . . . . . . . 107
6.5 LPF output . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
6.6 LPF output . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

7.1 Output of an LTI . . . . . . . . . . . . . . . . . . . . . . . . 122


7.2 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
7.3 Impulse and Step response . . . . . . . . . . . . . . . . . . . 126
7.4 Impulse and Step response . . . . . . . . . . . . . . . . . . . 127
7.5 Impulse and Step Response . . . . . . . . . . . . . . . . . . 129
7.6 Impulse and Step Response . . . . . . . . . . . . . . . . . . 130
7.7 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

9
7.8 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
7.9 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
7.10 Step Response . . . . . . . . . . . . . . . . . . . . . . . . . . 138
7.11 Step response . . . . . . . . . . . . . . . . . . . . . . . . . . 139
7.12 Magnitude and Phase Response . . . . . . . . . . . . . . . . 141
7.13 Magnitude and Phase Response . . . . . . . . . . . . . . . . 142

8.1 Magnitude and Phase Responses . . . . . . . . . . . . . . . . 144


8.2 Magnitude and Phase Responses . . . . . . . . . . . . . . . . 145
8.3 Transfer Function of system . . . . . . . . . . . . . . . . . . 147
8.4 Magnitude and Phase Responses . . . . . . . . . . . . . . . . 149
8.5 Magnitude and Phase Responses . . . . . . . . . . . . . . . . 150
8.6 system response . . . . . . . . . . . . . . . . . . . . . . . . . 152
8.7 System function . . . . . . . . . . . . . . . . . . . . . . . . . 154

9.1 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 159


9.2 Convolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
9.3 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 162
9.4 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 163
9.5 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 164
9.6 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 166
9.7 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 167
9.8 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 169
9.9 Autocorrelation . . . . . . . . . . . . . . . . . . . . . . . . . 170
9.10 PSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172

10.1 Cross Correlation . . . . . . . . . . . . . . . . . . . . . . . . 175


10.2 Cross Correlation Sequence . . . . . . . . . . . . . . . . . . 176
10.3 Auto Correlation . . . . . . . . . . . . . . . . . . . . . . . . 177
10.4 Auto Correlation . . . . . . . . . . . . . . . . . . . . . . . . 179
10.5 Auto Correlation . . . . . . . . . . . . . . . . . . . . . . . . 180
10.6 System response . . . . . . . . . . . . . . . . . . . . . . . . . 182

11.1 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 185


11.2 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 186
11.3 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 187
11.4 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 188
11.5 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 190
11.6 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 191

10
11.7 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 193
11.8 Hilbert Transform . . . . . . . . . . . . . . . . . . . . . . . . 194

11
Chapter 1

Signals Continuous and


Discrete time

Scilab code Exa 1.1 Finding Fundamental Period

1 // S c i l a b Code f o r Example 1 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // D e t e r m i n e w h e t h e r t h e g i v e n s i g n a l i s p e r i o d i c o r
not
4 // x ( t ) =10( c o s ( 1 0 p i t ) ) 2
5 clc ;
6 clear ;
7 syms t ;
8 x =10*( cos (10* %pi * t ) ) ^2;
9 disp (x , x ( t ) ) ;
10 t =0:0.01:1;
11 x =10*( cos (10* %pi * t ) ) ^2;
12 t =0:0.01:1;
13 plot (t ,x , r )
14 title ( x ( t ) ) ;
15 xlabel ( Time i n s e c o n d s ) ;
16 disp ( t h e s i g n a l i s p l o t t e d and i t shows i t i s
p e r i o d i c );

12
Figure 1.1: Finding Fundamental Period

Scilab code Exa 1.3.a Periodicity

1 // S c i l a b Code f o r Example 1 . 3 ( a ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // D e t e r m i n e w h e t h e r t h e g i v e n s i g n a l i s p e r i o d i c o r
not
4 // x ( t ) =3 c o s ( 0 . 4 p i t ) +2 s i n ( 0 . 6 6 t )

13
Figure 1.2: Finding Fundamental Period

14
5 clc ;
6 clear ;
7 syms t ;
8 x =3* cos (0.4* %pi * t ) +2* sin (0.66* t ) ;
9 disp (x , x ( t ) ) ;
10 t =0:1/50:50;
11 x =3* cos (0.4* %pi * t ) +2* sin (0.66* t ) ;
12 t =0:1/50:50;
13 plot (t , x ) ;
14 title ( x ( t ) ) ;
15 xlabel ( Time i n s e c o n d s ) ;
16 disp ( p l o t t e d t h e s i g n a l and shown t h a t i t i s not
p e r i o d i c and i s i n c r e a s i n g ) ;

Scilab code Exa 1.3.b Periodicity and fundamental period

1 // S c i l a b Code f o r Example 1 . 3 ( b ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // D e t e r m i n e w h e t h e r t h e g i v e n s i g n a l i s p e r i o d i c o r
not
4 // x ( t ) =5 c o s ( ( 4 / 3 ) t ) +3 s i n ( t )
5 clc ;
6 clear ;
7 syms t ;
8 x =5* cos ((4/3) * t ) +3* sin ( t ) ;
9 disp (x , x ( t ) ) ;
10 t =0:1/80:80;
11 x =5* cos ((4/3) * t ) +3* sin ( t ) ;
12 t =0:1/80:80;
13 plot (t , x ) ;
14 title ( x ( t ) ) ;
15 xlabel ( Time i n s e c o n d s ) ;

15
Figure 1.3: Periodicity

16
Figure 1.4: Periodicity and fundamental period

16 disp ( p l o t t e d t h e s i g n a l and shown t h a t i t i s


p e r i o d i c w i t h a p e r i o d o f LCM o f 2 p i and ( 2 p i
/ ( 4 / 3 ) );

Scilab code Exa 1.4 Fundamental Period

1 // S c i l a b Code f o r Example 1 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // D e t e r m i n e w h e t h e r t h e g i v e n s i g n a l i s p e r i o d i c o r
not

17
4 // x ( t )=c o s ( 7 t )+s i n ( 4 t )
5 clc ;
6 clear ;
7 syms t ;
8 x = sin (4* t ) + cos (7* t ) ;
9 disp (x , x ( t ) ) ;
10 t =0:1/12:12
11 x = sin (4* t ) + cos (7* t ) ;
12 t =0:1/12:12;
13 plot (t , x ) ;
14 title ( x ( t ) ) ;
15 xlabel ( Time i n s e c o n d s ) ;
16 disp ( p l o t t e d t h e s i g n a l and shown t h a t i t is
p e r i o d i c with p e r i o d o f 2 p i );

Scilab code Exa 1.5 Fundamental Period

1 // S c i l a b Code f o r Example 1 . 5 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // D e t e r m i n e w h e t h e r t h e g i v e n s i g n a l i s p e r i o d i c o r
not
4 // x ( t )=c o s ( t )+s i n ( s q r t ( 2 ) t )
5 clc ;
6 clear ;
7 syms t ;
8 x = cos ( t ) + sin ( sqrt (2) * t ) ;
9 disp (x , x ( t ) ) ;
10 for t =0:1:100;
11 x ( t +1) = cos ( t ) + sin ( sqrt (2) * t ) ;
12 end
13 t =0:1:100;
14 plot (t , x ) ;

18
Figure 1.5: Fundamental Period

19
Figure 1.6: Fundamental Period

15 title ( x ( t ) ) ;
16 xlabel ( Time i n s e c o n d s ) ;
17 disp ( p l o t t e d t h e s i g n a l and shown t h a t i t i s not
p e r i o d i c );

Scilab code Exa 1.6 Fundamental Period

1 // S c i l a b Code f o r Example 1 . 6 ( i ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // D e t e r m i n e w h e t h e r t h e g i v e n s i g n a l i s p e r i o d i c o r

20
not
4 clc ;
5 clear ;
6
7 n =0:1:10;
8 x ( n +1) =2* sin (0.8* %pi * n ) ;
9 a = gca () ;
10 a . x_location = o r i g i n ;
11 a . y_location = o r i g i n ;
12 n =0:1:10;
13 plot2d3 (n ,x ,9) ;
14 title ( x ( n ) ) ;
15 disp ( p l o t i n g t h e s i g n a l and s h o w i n g t h a t i t is
p e r i o d i c with p e r i o d o f 5 );

Scilab code Exa 1.7 Even and odd Components

1 // S c i l a b Code f o r Example 1 . 7 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 n =1;
6 for t = -10:0.1:10;
7 // F u n c t i o n f o r Even s i g n a l
8 y1 ( n ) =0.5*( exp ( - t ) * u ( t ) + exp ( t ) * u ( - t ) ) ;
9 n = n +1;
10 end
11 a = gca () ;
12 a . x_location = o r i g i n ;
13 a . y_location = o r i g i n ;
14 t = -10:0.1:10;
15 // P l o t o f Even S i g n a l

21
Figure 1.7: Fundamental Period

22
16 plot (t , y1 ) ;
17 title ( y1 ( t ) ) ;
18 xlabel ( Time i n s e c o n d s ) ;
19 n =1;
20 for t = -1:0.01:1;
21 // F u n c t i o n f o r Odd s i g n a l
22 y2 ( n ) =0.5*( exp ( - t ) * u ( t ) - exp ( t ) * u ( - t ) ) ;
23 n = n +1;
24 end
25 figure (1) ;
26 a = gca () ;
27 a . x_location = o r i g i n ;
28 a . y_location = o r i g i n ;
29 t = -1:0.01:1;
30 // P l o t o f Odd S i g n a l
31 plot (t , y2 )
32 disp ( p l o t t e d t h e s i g n a l b o t h i n e v e n and odd f o r m s
);
33 title ( y2 ( t ) ) ;
34 xlabel ( Time i n s e c o n d s ) ;

Scilab code Exa 1.11 Waveforms

1 // S c i l a b Code f o r Example 1 . 1 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // d i s p l a y i n g p l o t s f o r t h e g i v e n s i g n a l s
4 clear ;
5 clc ;
6 for t = -3:1:3
7 y ( t +4) = abs ( t +3) * u ( t +3) - abs ( t +1) * u ( t +1) - abs (t -1) * u (t

23
Figure 1.8: Even and odd Components

24
Figure 1.9: Even and odd Components

25
-1) + abs (t -3) * u (t -3) ;
8 end
9 t = -3:1:3;
10 // f o r t h e main g i v e n s i g n a l
11 a = gca () ;
12 a . x_location = o r i g i n ;
13 a . y_location = o r i g i n ;
14 plot (t , y ) ;
15 title ( Main S i g n a l ) ) ;
16 dy =0* y ;
17 for i =1:6
18 dy ( i ) =( y ( i +1) -y ( i ) ) /1;
19 end
20 // f o r t h e d e r i v a t i v e o f t h e g i v e n s i g n a l
21 figure (1) ;
22 a = gca () ;
23 a . x_location = o r i g i n ;
24 a . y_location = o r i g i n ;
25 plot2d2 (t , dy ) ;
26 title ( D e r i v a t i v e o f S i g n a l ) ;
27 dy2 =0* dy ;
28 dy2 (1) = dy (1) -0;
29 for i =1:6
30 dy2 ( i +1) =( dy ( i +1) - dy ( i ) ) /1;
31 end
32 // f o r t h e i m p u l s e r e s p o n s e r e p r e s e n t a t i o n o r s e c o n d
derivative
33 figure (2) ;
34 a = gca () ;
35 a . x_location = o r i g i n ;
36 a . y_location = o r i g i n ;
37 plot2d3 (t , dy2 , -5) ;
38 title ( I m p u l s e r e s p o n s e r e p r e s e n t a t i o n ) ;

26
Figure 1.10: Waveforms

27
Figure 1.11: Waveforms

28
Scilab code Exa 1.12 Time Scaling

1 // S c i l a b Code f o r Example 1 . 1 2 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 x = -2:1:3;
6 y =[ -1.5 ,2 ,2 ,1 , -1.5 ,2.5];
7 // P l o t o f x ( n )
8 plot2d3 (x ,y ,5) ;
9 xtitle ( Time S c a l i n g x ( n ) ) ;
10 a = gca () ; // g e t t h e c u r r e n t a x e s
11 a . x_location = o r i g i n ;
12 a . y_location = o r i g i n ;
13 x = -2:1:3;
14 y =[0 , -1.5 ,2 , -1.5 ,0 ,0];
15 figure (1) ;
16 // P l o t o f x ( 2 n )
17 plot2d3 (x ,y ,5) ;
18 a = gca () ; // g e t t h e c u r r e n t a x e s
19 a . x_location = o r i g i n ;
20 a . y_location = o r i g i n ;
21 xtitle ( Time S c a l i n g x ( 2 n ) ) ;

Scilab code Exa 1.13 Plot at a particular sampling frequency

29
Figure 1.12: Time Scaling

30
Figure 1.13: Time Scaling

31
1 // S c i l a b Code f o r Example 1 . 1 3 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 // D i s c r e t e t i m e s e q u e n c e p l o t
6 clc
7 A =10;
8 t =0:1/1000:1;
9 x = A * sin (2* %pi *100* t ) ;
10 q = plot2d3 (t , x ) ;
11 disp ( d i s p l a y i n g a f u n c t i o n p l o t on d i s c r e t e t i m e
s c a l e t h a t has a sampling f r e q u e n c y o f 1000
samples ps );

32
Figure 1.14: Plot at a particular sampling frequency

33
Chapter 2

Laplace and Z Transform

Scilab code Exa 2.1 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // L a p l a c e T r a n s f o r m
4 clear ;
5 clc ;
6 syms t s X
7 X = laplace ( exp ( -3* t ) * cos (2* %pi *100* t ) ,t , s )
8 disp ( On S i m p l i f i c a t i o n )
9 // A f t e r S i m p l i f y i n g t h e a b o v e e q u a t i o n
10 X =( s +3) /(( s +3) ^2 + (200* %pi ) ^2) ;
11 disp ( Re ( s )>3 ,X , X( s ) ) ;
12 // Re ( s )>3

Scilab code Exa 2.2 Inverse Laplace

1 // S c i l a b Code f o r Example 2 . 2 o f S i g n a l s and s y s t e m s


by

34
2 //P . Ramakrishna Rao
3 // I n v e r s e L a p l a c e T r a n s f o r m
4 clc ;
5 clear ;
6 syms t s
7 X =( s +2) /( s ^2+8* s +25)
8 f4 = ilaplace ( X ) ;
9 disp ( f4 * u ( t ) , x ( t )= ) ;
10 // t >=0

Scilab code Exa 2.3 Initial Value Theorem

1 // S c i l a b Code f o r Example 2 . 3 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms s0 ;
6 s = %s ;
7 I =( s +8) /( s ^2+6* s +13)
8 i = pfss ( s * I )
9 disp ( i (1) , sF ( s ) ( 1 )= )
10 disp ( i (2) , sF ( s ) ( 2 )= )
11 I1 =(2* s0 -13) /( s0 ^2+6* s0 +13) ;
12 I2 =1;
13 Io1 = limit ( I1 , s0 ,10^8) ;
14 Io2 = limit ( I2 , s0 ,10^8) ;
15 Ix =2 -((25* s0 +26) /( s0 ^2+6* s0 +13) ) ;
16 f0 =( Io1 ) +( Io2 ) ;
17 f0_dash = limit ( Ix , s0 ,10^8) ;
18 disp ( f0 , INITIAL VALUE OF f ( t ) i . e . f ( 0 )= ) ;
19 disp ( abs ( f0_dash ) , INITIAL VALUE OF f ( t ) i . e . f ( 0 )
= );

35
Scilab code Exa 2.4 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 // Time s h i f t e d l a p l a c e T r a n s f o r m
6 syms t y s a0 ;
7 y = laplace ( t exp ( s a0 ) ,t , s ) ;
8 disp ( Re ( s ) >0 ,y , X( s ) ) ;

Scilab code Exa 2.6 Circuit Current

1 // S c i l a b Code f o r Example 2 . 6 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna R a o c l e a r ;
3 clc ;
4 clear ;
5 syms s X x t R C V Vo ;
6 // A f t e r s o l v i n g f o r I ( s )
7 // I ( s ) =(VVo ) /R . 1 / ( s +1/RC)
8 X =( V - Vo ) /(( s +1/( R * C ) ) * R ) ;
9 disp (X , I ( s )= ) ;
10 x = ilaplace ( X ) ;
11 disp (x , i ( t )= ) ;

Scilab code Exa 2.7 Inverse Laplace Transform

36
1 // S c i l a b Code f o r Example 2 . 7 o f S i g n a l s and s y s t e m s
by
2 //P . Ramakrishna Rao
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 u s i n g p a r t i a l
fraction
4 clear ;
5 clc ;
6 syms t s ;
7 s = %s ;
8 a1 = pfss (( s +3) /( s ^2+3* s +2) )
9 f1 = ilaplace ( a1 (1) )
10 f2 = ilaplace ( a1 (2) )
11 fy = f1 + f2
12 disp ( fy * u ( t ) , i ) f ( t )= )
13 a2 = pfss ((2* s -1) /( s ^2+2* s +1) )
14 a2 (1) =2/( s +1)
15 a2 (2) = -3/( s +1) ^2
16 f1 = ilaplace ( a2 (1) )
17 f2 = ilaplace ( a2 (2) )
18 fz = f1 + f2
19 disp ( fz * u ( t ) , i i ) f ( t )= )

Scilab code Exa 2.8 Inverse Laplace Transform

1 // S c i l a b Code f o r Example 2 . 8 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
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
4 clear ;
5 clc ;
6 syms t s
7 s = %s ;
8 a = ilaplace (1/( s ^3+ s ^2) )
9 b =a -3;
10 disp ( a * u ( t ) + b * u ( t 3) , x ( t )= )

37
Scilab code Exa 2.9 Circuit Current

1 // S c i l a b Code f o r Example 2 . 2 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms s X ;
6 // A f t e r s o l v i n g f o r I ( s )
7 // I ( s ) =2/( s +1)
8 X =2/( s +1)
9 x = ilaplace ( X ) ;
10 disp (x , i ( t )= )

Scilab code Exa 2.10 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 1 0 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // The v a l u e o f X( s ) i s f o u n d by s o l v i n g t h e
d i f f e r e n t i a l equation
4 clear ;
5 clc ;
6 syms t s ;
7 s = %s ;
8 X = pfss (( s ^2+8* s +6) /(( s +2) *( s +3) * s ) ) ;
9 X (1) =1/ s ;
10 f1 = ilaplace ( X (1) )
11 f2 = ilaplace ( X (2) )
12 f3 = ilaplace ( X (3) )
13 fz = f1 + f2 + f3 ;
14 disp ( fz * u ( t ) , c ) x ( t )= ) ;

38
Figure 2.1: Laplace Transform

Scilab code Exa 2.15 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 1 5 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms t y ;
6 s = %s ;
7 y = laplace (5* exp ( -3* t ) ,t , s ) ;

39
8 disp (y , X( s )= ) ;
9 disp ( Re ( s )>3 ) ;
10 y =5/( s +3) ;
11 plzr ( y ) ;

Scilab code Exa 2.16 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 1 6 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms t y ;
6 s = %s ;
7 y = laplace (2* exp ( -2* t ) +3* exp ( -3* t ) ,t , s ) ;
8 disp (y , X( s )= ) ;
9 y =(2/( s +2) ) +(3/( s +3) ) ;
10 plzr ( y ) ;

Scilab code Exa 2.17 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 1 7 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms t y ;
6 s = %s ;
7 y = laplace ( -2* exp (2* t ) -3* exp (3* t ) ,t , s ) ;
8 disp (y , X( s )= ) ;
9 disp ( Re ( s ) <2 ) ;

40
Figure 2.2: Laplace Transform

41
Figure 2.3: Laplace Transform

10 y =( -2/( s -2) ) +( -3/( s -3) ) ;


11 plzr ( y ) ;

Scilab code Exa 2.19 Laplace Transform

1 // S c i l a b Code f o r Example 2 . 1 9 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms t y ;

42
Figure 2.4: Laplace Transform

6 s = %s ;
7 y = laplace ( exp ( - t ) - exp (2* t ) ,t , s ) ;
8 disp (y , X( s )= ) ;
9 y =(1/( s +1) ) -(1/( s -2) ) ;
10 plzr ( y ) ;

Scilab code Exa 2.21 Unilateral Z Transform

1 // S c i l a b Code f o r Example 2 . 2 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao

43
3 //Z t r a n s f o r m o f a n u ( n )
4 clear ;
5 clc ;
6 close ;
7 syms a n z ;
8 x1 =1/2;
9 x2 =1/3;
10 X1 = symsum ( x1 *( z ^( - n ) ) ,n ,0 , %inf ) ;
11 X2 = symsum ( x2 *( z ^( - n ) ) ,n ,0 , %inf ) ;
12 X = X1 + X2 ;
13 // D i s p l a y t h e r e s u l t
14 disp (X , Zt r a n s f o r m o f u ( n ) i s : ) ;
15 disp ( ROC i s t h e R e g i o n | z |> 1/2 ) ;

Scilab code Exa 2.29 Z Transform

1 // S c i l a b Code f o r Example 2 . 2 9 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 //Z t r a n s f o r m o f a n u ( n )
4 clear ;
5 clc ;
6 close ;
7 syms a n z ;
8 x =1;
9 X = symsum ( x *( z ^( - n ) ) ,n ,0 , %inf ) ;
10 // D i s p l a y t h e r e s u l t
11 disp (X , Zt r a n s f o r m o f u ( n ) i s : ) ;
12 disp ( ROC i s t h e R e g i o n | z |> 1 )

Scilab code Exa 2.37 Inverse Z Transform

44
1 // S c i l a b Code f o r Example 2 . 3 7 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 // I n v e r s e Z T r a n s f o r m :ROC 1 <| z | <2
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X =( z *( z ^2 - z +1) ) /(( z -0.5) *( z -2) *( z -1) )
10 X1 = denom ( X ) ;
11 zp = roots ( X1 ) ;
12 X1 = ( z1 *( z1 ^2 - z1 +1) ) /(( z1 -0.5) *( z1 -2) *( z1 -1) )
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) )
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) )
15 F3 = X1 *( z1 ^( n -1) ) *( z1 - zp (3) )
16 h1 = limit ( F1 , z1 , zp (1) ) ;
17 disp ( h1 * u(n 1) , h1 [ n ]= )
18 h2 = limit ( F2 , z1 , zp (2) ) ;
19 disp (( h2 ) * u ( n ) , h2 [ n ]= )
20 h3 = limit ( F3 , z1 , zp (3) ) ;
21 disp (( h3 ) * u ( n ) , h3 [ n ]= )
22 disp (( h3 ) * u ( n ) +( h2 ) * u ( n ) -( h1 ) * u(n 1) , h [ n ]= )
23 // // R e s u l t
24 // h [ n ]=1 0 . 5 n u ( n ) 2 u ( n ) 2 2 n u( n
1)

Scilab code Exa 2.38.a Inverse Z Transform

1 // S c i l a b Code f o r Example 2 . 3 8 ( i ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // I n v e r s e Z T r a n s f o r m :ROC | z | >2
4 clear ;

45
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X = z ^2/( z ^2+3* z +2) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 )
12 X1 = z1 ^2/( z1 ^2+3* z1 +2) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ;
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ;
15 h1 = limit ( F1 , z1 , zp (1) ) ;
16 disp ( h1 * u ( n ) , h1 [ n ]= )
17 h2 = limit ( F2 , z1 , zp (2) ) ;
18 disp (( h2 ) * u ( n ) , h2 [ n ]= ) ;
19 disp (( h1 ) * u ( n ) +( h2 ) * u ( n ) , h [ n ]= ) ;
20 // // R e s u l t
21 // h [ n ]= (2( 2 ) n+1 ( 1 ) n ) u ( n )

Scilab code Exa 2.38.b Inverse Z Transform

1 // S c i l a b Code f o r Example 2 . 3 8 ( i i ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // I n v e r s e Z T r a n s f o r m :ROC | z | >2
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X =( z +1) /( z ^2+5* z +4)
10 X1 = denom ( X ) ;
11 zp = roots ( X1 )
12 X1 = 1/( z1 +4) ;

46
13 F1 = X1 *( z1 ^( n ) ) *( z1 - zp (1) ) ;
14 h1 = limit ( F1 , z1 , zp (1) )
15 disp ( -( h1 ) * u(n 1) , h [ n ]= ) ;
16 // // R e s u l t
17 // h [ n ]= ( ( 4 ) n ) u(n 1)

Scilab code Exa 2.39 Inverse Z Transform

1 // S c i l a b Code f o r Example 2 . 3 9 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // I n v e r s e Z T r a n s f o r m :ROC | z | >2
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X =2/( z ^ -1+2) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 )
12 X1 = z1 /( z1 +0.5) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ;
14 h1 = limit ( F1 , z1 , zp (1) )
15 disp ( -( h1 ) * u(n 1) , h [ n ]= ) ;
16 // // R e s u l t
17 // h [ n ]= ( ( 0 . 5 ) n ) u(n 1)

Scilab code Exa 2.40 Inverse Z Transform

1 // S c i l a b Code f o r Example 2 . 4 0 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao

47
3 // I n v e r s e Z T r a n s f o r m :ROC | z | >2
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 //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
= z1
9 X = z ^2/(( z -0.5) *( z -1) ) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 )
12 X1 = z1 ^2/(( z1 -0.5) *( z1 -1) ) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) ) ;
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) ) ;
15 h1 = limit ( F1 , z1 , zp (1) ) ;
16 disp ( h1 * u ( n ) , h1 [ n ]= )
17 h2 = limit ( F2 , z1 , zp (2) ) ;
18 disp (( h2 ) * u ( n ) , h2 [ n ]= ) ;
19 disp ( -( h1 ) * u(n 1) -( h2 ) * u(n 1) , h [ n ]= ) ;
20 // // R e s u l t
21 // h [ n ]= ( ( 0 . 5 ) n 2 ) u(n 1)

48
Chapter 3

Fourier Series of Continuous


Time Signals

Scilab code Exa 3.13 Complex Fourier Exponential Series

1 // S c i l a b Code f o r Example 3 . 1 3 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // Complex E x p o n e n t i a l F o u r i e r E x p a n s i o n
4 //A=3.14 o r p i
5 clear ;
6 close ;
7 clc ;
8 T0 =4;
9 t = -5.99:0.01:6;
10 t_temp =0.01:0.01: T0 /2;
11 s = length ( t ) / length ( t_temp ) ;
12 x =[];
13 for i =1: s
14 if modulo (i ,2) ==1 then

49
Figure 3.1: Complex Fourier Exponential Series

50
Figure 3.2: Complex Fourier Exponential Series

51
15 x =[ x - ones (1 , length ( t_temp ) ) * %pi ];
16 else
17 x =[ x ones (1 , length ( t_temp ) ) * %pi ];
18 end
19 end
20 figure (1) ;
21 title ( S i g n a l ) ;
22 ylabel ( x ( t ) ) ;
23 xlabel ( t ) ;
24 plot (t ,x , r )
25 w0 = %pi /2;
26 for k = -10:10
27 cc ( k +11 ,:) = exp ( - %i * k * w0 * t ) ;
28 ck ( k +11) = x * cc ( k +11 ,:) / length ( t ) ;
29 if abs ( ck ( k +11) ) <0.01 then
30 ck ( k +11) =0;
31 else if real ( ck ( k +11) ) <0.1 then
32 ck ( k +11) = %i * imag ( ck ( k +11) ) ;
33 end
34 end
35 if k ==0 then
36 c0 = ck ( k +11) ;
37 end
38 end
39 q = abs ( ck ) ;
40 figure (2) ;
41 title ( Magnitude Spectrum ) ;
42 ylabel ( | cn | ) ;
43 xlabel ( f o ) ;
44 f = -10:1:10;
45 plot2d3 (f , q )

52
Figure 3.3: Complex Fourier Exponential Series

53
Figure 3.4: Complex Fourier Exponential Series

54
Scilab code Exa 3.14 Complex Fourier Exponential Series

1 // S c i l a b Code f o r Example 3 . 1 4 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 //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
4 // x ( wt ) = A s i n wt , 0<wt<p i , and 0 , p i <| t | <2 p i
5 clear ;
6 clc ;
7 A =6;
8 T =2* %pi ;
9 T1 = T /2;
10 t = 0:0.01: T1 ;
11 Wo = 2* %pi / T ;
12 xt = A * sin ( Wo * t ) ;
13 for k =0:6
14 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * t .* k ) ;
15 c ( k +1) = xt * C ( k +1 ,:) / length ( t ) ;
16 if ( abs ( c ( k +1) ) <=0.01)
17 c ( k +1) =0;
18 end
19 end
20 c =c ;
21 c_conj = real ( c (:) ) - sqrt ( -1) * imag ( c (:) ) ;
22 ck = [ c_conj ( $ : -1:1) ,c (2: $ ) ];
23 k = 0:6;
24 k = [ - k ( $ : -1:1) ,k (2: $ ) ];
25 figure (1) ;
26 c = gca () ;
27 c . y_location = o r i g i n ;
28 c . x_location = o r i g i n ;
29 // c . d a t a b o u n d s = [ 2 , 0 ; 2 , 2 ] ;
30 plot2d (t , xt ,5)
31 poly1 = c . children (1) . children (1) ;
32 poly1 . thickness = 3;
33 title ( x ( t ) )
34 xlabel ( t )
35 figure (2) ;

55
Figure 3.5: Complex Fourier Exponential Series

36 c = gca () ;
37 c . y_location = o r i g i n ;
38 c . x_location = o r i g i n ;
39 plot2d3 ( gnn ,k , abs ( ck ) ,9)
40 poly1 = c . children (1) . children (1) ;
41 poly1 . thickness = 3;
42 title ( | ck | )
43 xlabel ( k )

Scilab code Exa 3.16 Complex Fourier Exponential Series

56
1 // S c i l a b Code f o r Example 3 . 1 6 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 //A=%pi o r 3 . 1 4
4 clear ;
5 clc ;
6 // T r i g n o m e t r i c F o u r i e r C o e f f i c i e n t s
7 for n =0:5
8 a ( n +1) = integrate ( t c o s ( 2 %pi n t ) , t ,0 ,1) ;
9 end
10 for n =0:5
11 b ( n +1) = integrate ( t s i n ( 2 %pi n t ) , t ,0 ,1) ;
12 end
13 disp ( %pi * a (1) , an ( a0 ) )
14 disp ( an ( a1>a5 ) )
15 for n =1:5
16 disp (2* a ( n +1) * %pi )
17 end
18 disp ( bn ( b1>b5 ) )
19 for n =1:5
20 disp (2* %pi * b ( n +1) )
21 end
22 //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
23 // x ( t ) =t
24 t = 0:0.01:1;
25 xt =2* %pi * t ;
26 //
27 for k =0:6
28 C ( k +1 ,:) = exp ( - sqrt ( -1) *2* %pi * t * k ) ;
29 c ( k +1) = xt * C ( k +1 ,:) / length ( t ) ;
30 if ( abs ( c ( k +1) ) <=0.01)
31 c ( k +1) =0;
32 end
33 end
34 c =c ;
35 c_conj = real ( c (:) ) - sqrt ( -1) * imag ( c (:) ) ;
36 ck = [ c_conj ( $ : -1:1) ,c (2: $ ) ];
37 k = 0:6;

57
Figure 3.6: Complex Fourier Exponential Series

38 k = [ - k ( $ : -1:1) ,k (2: $ ) ];
39 c = gca () ;
40 c . y_location = o r i g i n ;
41 c . x_location = o r i g i n ;
42 plot2d3 ( gnn ,k , abs ( ck ) )
43 poly1 = c . children (1) . children (1) ;
44 poly1 . thickness = 3;
45 title ( | ck | )
46 xlabel ( k )

58
Figure 3.7: Complex Fourier Exponential Series

59
Scilab code Exa 3.17 Complex Fourier Exponential Series

1 // S c i l a b Code f o r Example 3 . 1 7 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 //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
4 // x ( wt ) = A s i n wt , 0<wt<p i
5 clear ;
6 close ;
7 clc ;
8 A =3.14;
9 T = %pi ;
10 T1 = T /2;
11 t = 0:0.01: T1 ;
12 Wo = 2* %pi / T ;
13 xt = A * sin ( Wo * t ) ;
14 //
15 for k =0:6
16 C ( k +1 ,:) = exp ( - sqrt ( -1) * Wo * t .* k ) ;
17 c ( k +1) = xt * C ( k +1 ,:) / length ( t ) ;
18 if ( abs ( c ( k +1) ) <=0.01)
19 c ( k +1) =0;
20 end
21 end
22 c =c ;
23 c_conj = real ( c (:) ) - sqrt ( -1) * imag ( c (:) ) ;
24 ck = [ c_conj ( $ : -1:1) ,c (2: $ ) ];
25 k = 0:6;
26 k = [ - k ( $ : -1:1) ,k (2: $ ) ];
27 c = gca () ;
28 c . y_location = o r i g i n ;
29 c . x_location = o r i g i n ;
30 // c . d a t a b o u n d s = [ 2 , 0 ; 2 , 2 ] ;
31 plot2d (t , xt ,5)
32 poly1 = c . children (1) . children (1) ;
33 poly1 . thickness = 3;
34 title ( x ( t ) )
35 xlabel ( t )

60
36 figure (1) ;
37 c = gca () ;
38 c . y_location = o r i g i n ;
39 c . x_location = o r i g i n ;
40 plot2d3 ( gnn ,k , abs ( ck ) )
41 poly1 = c . children (1) . children (1) ;
42 poly1 . thickness = 3;
43 title ( | ck | )
44 xlabel ( k )

Scilab code Exa 3.18 Trignometric Series

1 // S c i l a b Code f o r Example 3 . 1 8 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 //A=%pi o r 3 . 1 4
4 clear ;
5 clc ;
6 // T r i g n o m e t r i c F o u r i e r C o e f f i c i e n t s
7 a (1) = integrate ( s i n (w) , w ,0 , %pi ) ;
8 for n =1:8
9 a (2* n +1) = integrate ( s i n (w+2nw) , w ,0 , %pi ) +
integrate ( s i n (w2wn ) , w ,0 , %pi ) ;
10 end
11 for n =0:8
12 b ( n +1) =0;
13 end
14 disp ( abs ( a (1) ) , an ( a0 ) ) ;
15 disp ( an ( a1>a8 ) ) ;
16 n =1:8;
17 disp (2* a ( n +1) ) ;
18 disp ( bn ( b1>b8 ) ) ;
19 n =1:8;
20 disp ( b ( n ) ) ;

61
Chapter 4

The Continuous Time Fourier


Transform

Scilab code Exa 4.1 Magnitude and Phase Spectra

1 // S c i l a b Code f o r Example 4 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // P l o t t i n g Magnitude and Phase s p e c t r u m
4 clc ;
5 clear ;
6 A =8;
7 Dt =0.005;
8 T1 =4;
9 t = - T1 /2: Dt : T1 /2;
10 q = length ( t )
11 for i = -( q /2) +1: q /2
12 if i > - q /4 & i < q /4 then
13 xt ( i +( q /2) ) = A ;
14 else xt ( i +( q /2) ) =0;

62
Figure 4.1: Magnitude and Phase Spectra

63
Figure 4.2: Magnitude and Phase Spectra

64
15 end
16 end
17 Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz
18 K = 4;
19 k = 0:( K /1000) : K ;
20 W = k * Wmax / K ;
21 xt = xt ;
22 XW = xt * exp ( - sqrt ( -1) *t * W ) * Dt ;
23 XW_Mag = real ( XW ) ;
24 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from
Wmax t o Wmax
25 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
26 [ XW_Phase , db ] = phasemag ( XW ) ;
27 XW_Phase =[ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001) ];
28 // P l o t t i n g t h e F u n c t i o n
29 subplot (2 ,1 ,1) ;
30 a = gca () ;
31 a . data_bounds =[ -4 ,0;4 ,2];
32 a . y_location = o r i g i n ;
33 plot (t , xt ) ;
34 xlabel ( t i n s e c . ) ;
35 title ( C o n t i n o u s Time S i g n a l x ( t ) ) ;
36 // P l o t t i n g Magnitude Reponse o f CTS
37 subplot (2 ,1 ,2) ;
38 a = gca () ;
39 a . y_location = o r i g i n ;
40 plot ( W /(2* %pi ) , XW_Mag ) ;
41 xlabel ( F r e q u e n c y i n Hz ) ;
42 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) ) ;
43 // P l o t t i n g Phase Reponse o f CTS
44 figure (1) ;
45 a = gca () ;
46 a . y_location = o r i g i n ;
47 a . x_location = o r i g i n ;
48 plot ( W /(2* %pi ) ,- XW_Phase * %pi /180) ;
49 xlabel ( F r e q u e n c y i n Hz ) ;
50 ylabel ( <X(jW) )
51 title ( Phase R e s p o n s e (CTFT) i n R a d i a n s )

65
Figure 4.3: Magnitude and Phase Spectra

Scilab code Exa 4.2 Magnitude and Phase Spectra

1 // S c i l a b Code f o r Example 4 . 2 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // 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
4 // 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
5 clear ;

66
Figure 4.4: Magnitude and Phase Spectra

67
6 clc ;
7 close ;
8 // Analog S i g n a l
9 A =1; // A m p l i t u d e
10 T =1;
11 Dt = 0.005;
12 t = 0: Dt :10;
13 xt = A * exp ( - t / T ) ;
14 // 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
15 Wmax = 2* %pi *1; // Analog F r e q u e n c y = 1Hz
16 K = 4;
17 k = 0:( K /1000) : K ;
18 W = k * Wmax / K ;
19 XW = xt * exp ( - sqrt ( -1) *t * W ) * Dt ;
20 XW_Mag = abs ( XW ) ;
21 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from
Wmax t o Wmax
22 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
23 [ XW_Phase , db ] = phasemag ( XW ) ;
24 XW_Phase = [ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001)
];
25 // 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
26 a = gca () ;
27 a . y_location = o r i g i n ;
28 plot (t , xt ) ;
29 xlabel ( t i n s e c . ) ;
30 ylabel ( x ( t ) )
31 title ( C o n t i n u o u s Time S i g n a l )
32 figure
33 // P l o t t i n g Magnitude R e s p o n s e o f CTS
34 subplot (2 ,1 ,1) ;
35 a = gca () ;
36 a . y_location = o r i g i n ;
37 plot (W , XW_Mag ) ;
38 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 ) ;
39 ylabel ( a b s (X(jW) ) )
40 title ( Magnitude R e s p o n s e (CTFT) )
41 // P l o t t i n g Phase Reponse o f CTS

68
Figure 4.5: Magnitude and Phase Spectra

42 subplot (2 ,1 ,2) ;
43 a = gca () ;
44 a . y_location = o r i g i n ;
45 a . x_location = o r i g i n ;
46 plot (W , XW_Phase * %pi /180) ;
47 xlabel ( Frequency in
R a d i a n s / S e c o n d s > W ) ;
48 ylabel (
<X
(jW) )
49 title ( Phase R e s p o n s e (CTFT) i n R a d i a n s )

69
Figure 4.6: Magnitude and Phase Spectra

70
Scilab code Exa 4.3 Magnitude and Phase Spectra

1 // S c i l a b Code f o r Example 4 . 3 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // x ( t )=A c o s w0 t g a t e ( t /T)
4 //T=1/2 f o
5 // f o =0.5 Hz
6 clear ;
7 clc ;
8 // F o u r i e r T r a n s f o r m
9 A =1;
10 T =0.5;
11 fo =1/(2* T ) ;
12 Wo =2* %pi * fo ;
13 for f = -20:1:20;
14 X ( f +21) = A * integrate ( c o s (Wo t ) c o s ( 2 %pi f t ) , t
, -0.25 ,0.25) ;
15 end
16 disp (X , X( 0 )>X( 2 0 ) ) ;
17 t = -0.25:0.01:0.25;
18 q = cos ( Wo * t ) ;
19 a = gca () ;
20 a . y_location = o r i g i n ;
21 a . x_location = o r i g i n ;
22 plot (t , q ) ;
23 xlabel ( Time i n S e c o n d s ) ;
24 title ( S i g n a l x ( t ) ) ;
25 figure (1) ;
26 a = gca () ;
27 a . y_location = o r i g i n ;
28 a . x_location = o r i g i n ;
29 f = -20:1:20;
30 plot (f , X ) ;

71
31 xlabel ( F r e q u e n c y i n Hz ) ;
32 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 X(jW) ) ;

Scilab code Exa 4.4 Energy at output

1 // S c i l a b Code f o r Example 4 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 //X( f )=AT/1+ j 2 p i f T
6 syms f w ;
7 A =1;
8 T =1;
9 X =( A ^2* T ^2) /(1+4* %pi ^2* f ^2* T ^2)
10 disp ( P u t t i n g f = t a n @ ) ;
11 disp ( T o t a l Energy : ) ;
12 Ex = integrate ( (A2T) / ( 2 %pi ) , w ,- %pi /2 , %pi /2)
13 disp ( Energy C o n t a i n e d i n t h e Output S i g n a l ) ;
14 Ey = integrate ( (A2T) / ( 2 %pi ) , w ,- %pi /4 , %pi /4)
15 e = Ey *100/ Ex ;
16 disp (e , P e r c e n t a g e Energy C o n t a i n e d i n t h e Output : )
;

Scilab code Exa 4.5 Fourier Transform

1 // S c i l a b Code f o r Example 4 . 5 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao

72
Figure 4.7: Fourier Transform

73
Figure 4.8: Fourier Transform

74
3 // x ( t )=c o s p i t , | t | > 0 . 5 , z e r o o t h e r w i s e
4 clear ;
5 clc ;
6 // F o u r i e r T r a n s f o r m
7 for f = -20:1:20;
8 X ( f +21) = integrate ( c o s ( %pi t ) c o s ( 2 %pi f t ) , t
, -0.5 ,0.5) ;
9 end
10 disp (X , X( 0 )>X( 2 0 ) ) ;
11 t = -0.5:0.01:0.5;
12 q = cos ( %pi * t ) ;
13 a = gca () ;
14 a . y_location = o r i g i n ;
15 a . x_location = o r i g i n ;
16 plot (t , q ) ;
17 xlabel ( Time i n S e c o n d s ) ;
18 title ( S i g n a l x ( t ) ) ;
19 figure (1) ;
20 a = gca () ;
21 a . y_location = o r i g i n ;
22 a . x_location = o r i g i n ;
23 f = -20:1:20;
24 plot (f , X ) ;
25 xlabel ( F r e q u e n c y i n Hz ) ;
26 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 X(jW) ) ;

Scilab code Exa 4.6 Convolution

1 // S c i l a b Code f o r Example 4 . 6 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;

75
Figure 4.9: Convolution

76
5 close ;
6 disp ( X(w) =1/( a+jw ) 2=1/( a+jw ) 1 / ( a+jw ) ) ;
7 disp ( exp (a t ) u ( t ) <> 1 / ( a+jw ) ) ;
8 disp ( t h e r e f o r e x ( t )=c o n v o l u t i o n ( 2 s i n c ( 2 t ) , ( s i n c t
) 2 ) ;
9 a =2;
10 n =1;
11 for t = -10:0.1:10
12 y1 (1 , n ) =( sinc ( t ) ) ^2;
13 y2 (1 , n ) =2* sinc (2* t ) ;
14 n = n +1;
15 z = conv ( y1 , y2 ) ;
16 end
17 t = -20:0.1:20;
18 a = gca () ;
19 a . y_location = o r i g i n ;
20 a . x_location = o r i g i n ;
21 plot (t , z ) ;
22 title ( C o n v o l u t i o n o f x ( t ) and y ( t ) )

Scilab code Exa 4.7 Energy in Signal

1 // S c i l a b Code f o r Example 4 . 7 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms t ;
6 A =2;
7 // x ( t ) =20 s i n c ( 1 0 t ) ;
8 disp ( T o t a l Energy o f t h e s i g n a l : ) ;
9 q = integrate ( A2 , w , -5 ,5) ;
10 disp (q , Ex ) ;

77
Scilab code Exa 4.11 Fourier Transform

1 // S c i l a b Code f o r Example 4 . 1 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // Find s y s t e m f u n c t i o n and o u t p u t o f t h e s y s t e m
4 clear ;
5 clc ;
6 syms a t ;
7 for n =1:10;
8 h = t ^( n -1) * %e ^( - a * t ) ;
9 H = laplace (h ,t , jw ) ;
10 disp (H , SYSTEM FUNCTION X( f )= ,h , For x ( t )= ) ;
11 end

Scilab code Exa 4.14 Fourier Transform

1 // S c i l a b Code f o r Example 4 . 1 4 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 close ;
6 a =.5;
7 A =1/( sqrt (2) * %pi ) ;
8 t = -10:0.1:10;
9 x = A * exp ( - a * t .* t ) ;

78
Figure 4.10: Fourier Transform

79
Figure 4.11: Fourier Transform

80
10 disp ( G u a s s i a n p u l s e s i g n a l x ( t ) =(1/ s q r t ( 2 ) %pi ) exp
(a t 2 ) ) ;
11 disp ( X(w)= i n t e g r a l ( exp (a t 2 ) exp (%i w t ) ) w . r . t
dt );
12 disp ( d (X(w) ) /dw=%i w/ ( 2 a ) i n t e g r a l ( exp (a t 2 )
exp (%i w t ) ) ) ;
13 disp ( d (X(w) ) /dw=wX(w) /2 a ) ;
14 disp ( s o l v i n g t h i s we g e t X(w)=A exp (w 2 / 4 a ) )
15 disp ( A=s q r t ( %pi / a ) ) ;
16 d = gca ()
17 plot (t , x ) ;
18 poly1 = d . children . children ;
19 poly1 . thickness =3;
20 poly1 . foreground =2;
21 xtitle ( x ( t ) , t )
22 A =1;
23 f=t;
24 Xf = A * exp ( -2* %pi ^2* f ^2) ;
25 figure (1) ;
26 d = gca ()
27 plot (f , Xf ) ;
28 poly1 = d . children . children ;
29 poly1 . thickness =3;
30 poly1 . foreground =2;
31 xtitle ( X( f ) , f )

Scilab code Exa 4.17 Fourier Transform

1 // S c i l a b Code f o r Example 4 . 1 7 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao

81
Figure 4.12: Fourier Transform

82
Figure 4.13: Fourier Transform

83
3 clear ;
4 clc ;
5 // F o u r i e r T r a n s f o r m o f x ( t )
6 n =1;
7 for t = -10:0.1:10;
8 x (1 , n ) =1/(1+ t ^2) ;
9 n = n +1;
10 end
11 a = gca () ;
12 a . y_location = o r i g i n ;
13 a . x_location = o r i g i n ;
14 t = -10:0.1:10;
15 plot (t , x ) ;
16 xlabel ( Time i n S e c o n d ) ;
17 title ( x ( t ) ) ;
18 disp ( By D u a l i t y Theorem F o u r i e r T r a n s f o r m o f x ( t )
i s : );
19 disp ( %pi exp ( |w | ) ) ;
20 n =1;
21 for w = -10:0.1:10;
22 X (1 , n ) = %pi * exp ( - abs ( w ) ) ;
23 n = n +1;
24 end
25 figure (1) ;
26 a = gca () ;
27 a . y_location = o r i g i n ;
28 a . x_location = o r i g i n ;
29 w = -10:0.1:10;
30 plot (w , X ) ;
31 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 ) ;
32 title ( X(w) ) ;

84
Chapter 5

Fourier Representation of
Discrete Time Signals

Scilab code Exa 5.1 DTFT

1 // S c i l a b Code f o r Example 5 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
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
4 // x [ n ]= ( a a b s ( n ) ) 0<a<1
5 clear ;
6 clc ;
7 close ;
8 // DTS S i g n a l
9 a = 0.5; //0<a<1
10 max_limit = 10;
11 n = - max_limit +1: max_limit -1;
12 x = a ^ abs ( n ) ;
13 // 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
14 Wmax = 2* %pi ;
15 K = 4;
16 k = 0:( K /1000) : K ;
17 W = k * Wmax / K ;
18 XW = x * exp ( - sqrt ( -1) *n * W ) ;

85
19 XW_Mag = real ( XW ) ;
20 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from
Wmax t o Wmax
21 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
22 a = gca () ;
23 a . y_location = o r i g i n ;
24 a . x_location = o r i g i n ;
25 plot2d3 ( gnn ,n , x ) ;
26 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 )
27 figure (1) ;
28 a = gca () ;
29 a . y_location = o r i g i n ;
30 a . x_location = o r i g i n ;
31 plot2d (W , XW_Mag ) ;
32 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) ) )

Scilab code Exa 5.2 DTFT and Spectra

1 // S c i l a b Code f o r Example 5 . 2 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
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
4 // x [ n ]= 1 , 0=<n<=3
5 clear ;
6 clc ;
7 close ;
8 // DTS S i g n a l
9 N1 = 3;
10 n = 0: N1 ;
11 x = ones (1 , length ( n ) ) ;
12 // 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

86
Figure 5.1: DTFT

87
Figure 5.2: DTFT

88
13 Wmax = 2* %pi ;
14 K = 4;
15 k = 0:( K /1000) : K ;
16 W = k * Wmax / K ;
17 XW = x * exp ( - sqrt ( -1) *n * W ) ;
18 XW_Mag = real ( XW ) ;
19 [ XW_Phase , db ] = phasemag ( XW ) ;
20 W = [ - mtlb_fliplr ( W ) , W (2:1001) ]; // Omega from
Wmax t o Wmax
21 XW_Mag = [ mtlb_fliplr ( XW_Mag ) , XW_Mag (2:1001) ];
22 XW_Phase = [ - mtlb_fliplr ( XW_Phase ) , XW_Phase (2:1001)
];
23 a = gca () ;
24 a . y_location = o r i g i n ;
25 a . x_location = o r i g i n ;
26 plot2d3 ( gnn ,n , x ) ;
27 xtitle ( D i s c r e t e Time S e q u e n c e x [ n ] )
28 figure (1) ;
29 a = gca () ;
30 a . y_location = o r i g i n ;
31 a . x_location = o r i g i n ;
32 plot2d (W , abs ( XW_Mag ) ) ;
33 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) ) )
34 figure (2) ;
35 a = gca () ;
36 a . y_location = o r i g i n ;
37 a . x_location = o r i g i n ;
38 plot2d (W , XW_Phase ) ;
39 title ( Phase R e s p o n s e <(X(jW) ) )

Scilab code Exa 5.3 Inverse Fourier

89
Figure 5.3: DTFT and Spectra

90
Figure 5.4: DTFT and Spectra

91
1 // S c i l a b Code f o r Example 5 . 3 o f S i g n a l s and s y s t e m s
by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 // I n v e r s e F o u r i e r T r a n s f o r m
6 w = -20:20;
7 X =4*( cos ( w ) ) ^2;
8 a = gca () ;
9 a . y_location = o r i g i n ;
10 a . x_location = o r i g i n ;
11 plot (w , X ) ;
12 title ( X( e jw ) ) ;
13 xlabel ( F r e q u e n c y i n R a d i a n s / s e c ) ;
14 figure (1) ;
15 n = -50:50;
16 x =2* sinc ( n ) + sinc ( n +2) + sinc (n -2) ;
17 a = gca () ;
18 a . y_location = o r i g i n ;
19 a . x_location = o r i g i n ;
20 plot2d3 (n , x ) ;
21 title ( x ( n ) ) ;
22 xlabel ( Time i n s e c ) ;

Scilab code Exa 5.4 Inverse Fourier

1 // S c i l a b Code f o r Example 5 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
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
4 // X( e j w) =2%pi d e l t a (w)

92
Figure 5.5: Inverse Fourier

93
Figure 5.6: Inverse Fourier

94
5 clear ;
6 clc ;
7 close ;
8 N = 1;
9 N1 = -3* N :3* N ;
10 xn = [ zeros (1 ,N -1) ,1];
11 x = [1 xn xn xn xn xn xn ];
12 ak = 1/ N ;
13 XW = 2* %pi * ak * ones (1 ,2* N ) ;
14 Wo = 2* %pi / N ;
15 n = -N :N -1;
16 W = Wo * n ;
17 a = gca () ;
18 a . y_location = m i d d l e ;
19 a . x_location = o r i g i n ;
20 plot2d3 ( gnn ,W , XW ,2) ;
21 poly1 = a . children (1) . children (1) ;
22 poly1 . thickness = 3;
23 xlabel ( W ) ;
24 title ( DTFT o f P e r i o d i c I m p u l s e T r a i n )
25 figure (1) ;
26 a = gca () ;
27 a . y_location = o r i g i n ;
28 a . x_location = o r i g i n ;
29 plot2d3 ( gnn ,N1 ,x ,2) ;
30 poly1 = a . children (1) . children (1) ;
31 poly1 . thickness = 3;
32 xlabel ( n ) ;
33 title ( P e r i o d i c I m p u l s e T r a i n x ( n ) )

Scilab code Exa 5.5 Fourier series

95
Figure 5.7: Inverse Fourier

96
Figure 5.8: Inverse Fourier

97
1 // S c i l a b Code f o r Example 5 . 5 o f S i g n a l s and s y s t e m s
by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 x =[1 ,2 ,3 ,2 ,1];
6 q =0;
7 for n =1:5
8 q=x(n)+q;
9 end
10 disp (q , ( a ) X( e j 0 ) ) ;
11 q =0;
12 for n = -2:2
13 q =(( -1) ^ n ) * x ( n +3) + q ;
14 end
15 disp (q , ( c ) X( e j p i ) ) ;
16 disp ( ( d ) X( e j p i ) =2 p i x ( 0 ) ) ;
17 disp (2* %pi * x (3) ) ;
18 q =0;
19 for n = -2:2
20 q =( x ( n +3) ) ^2+ q ;
21 end
22 disp ( q *2* %pi , ( e ) | X( e j w) | 2 ) ;

Scilab code Exa 5.9.i DTFT

1 // S c i l a b Code f o r Example 5 . 9 ( i ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 q =0;
6 a1 =0.5
7 a2 = -0.5;
8 n =1:101;

98
9 x1 = a1 ^ n ;
10 x2 = a2 ^ n ;
11 w =2;
12 n =0:100;
13 z =( exp ( - %i * w * n ) ) ;
14 for n =0:33;
15 X ( n +1) = z ( n +1) * x1 (3* n +1) ;
16 q = X ( n +1) + q ;
17 end
18 disp (q , Y1 ( e 2 j ) a t a =0.5 ) ;
19 for n =0:33;
20 X ( n +1) = z ( n +1) * x2 (3* n +1) ;
21 q = X ( n +1) + q ;
22 end
23 disp (q , Y1 ( e 2 j ) a t a =0.5 ) ;

Scilab code Exa [Link] DTFT

1 // S c i l a b Code f o r Example 5 . 9 ( i i ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 q =0;
6 a1 =0.5
7 a2 = -0.5;
8 n =1:101;
9 x1 = a1 ^ n ;
10 x2 = a2 ^ n ;
11 w =2;
12 n =0:100;
13 z =( exp ( - %i * w * n ) ) ;
14 for n =0:33;
15 X ( n +1) = z ( n +1) * x1 ( n +1) ;
16 q = X ( n +1) + q ;

99
17 end
18 disp (q , Y2 ( e 2 j ) a t a =0.5 ) ;
19 for n =0:33;
20 X ( n +1) = z ( n +1) * x2 ( n +1) ;
21 q = X ( n +1) + q ;
22 end
23 disp (q , Y2 ( e 2 j ) a t a =0.5 ) ;

Scilab code Exa [Link] DTFT

1 // S c i l a b Code f o r Example 5 . 9 ( i i i ) o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 q =0;
6 a1 =0.5
7 a2 = -0.5;
8 n =1:101;
9 x1 = a1 ^ n ;
10 x2 = a2 ^ n ;
11 w =2;
12 n =0:100;
13 z =( exp ( - %i * w * n ) ) ;
14 for n =0:33;
15 X ( n +1) = z ( n +1) * x1 ( n +1) * cos (0.4* %pi * n ) ;
16 q = X ( n +1) + q ;
17 end
18 disp (q , Y3 ( e 2 j ) a t a =0.5 ) ;
19 for n =0:33;
20 X ( n +1) = z ( n +1) * x2 ( n +1) * cos (0.4* %pi * n ) ;
21 q = X ( n +1) + q ;
22 end
23 disp (q , Y3 ( e 2 j ) a t a =0.5 ) ;

100
Scilab code Exa 5.11 Inverse Fourier

1 // S c i l a b Code f o r Example 5 . 1 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 wc =1;
6 y =1;
7 for n = - %pi : %pi /80: %pi
8 if n < - wc | n > wc then
9 X (1 , y ) =1;
10 y = y +1;
11 else X (1 , y ) =0;
12 y = y +1;
13 end
14 end
15 n = - %pi : %pi /80: %pi ;
16 a = gca () ;
17 a . y_location = o r i g i n ;
18 a . x_location = o r i g i n ;
19 plot (n , X ) ;
20 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 ) ;
21 title ( X( e jw ) ) at Wc=1 ) ;
22 A =1/ %pi ;
23 for k = -10:10
24 x ( k +11) = A * integrate ( c o s (w k ) , w ,wc , %pi ) ;
25 end
26 figure (1) ;
27 k = -10:10;
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 (k , x ) ;

101
Figure 5.9: Inverse Fourier

32 xlabel ( Time i n S e c o n d s ) ;
33 title ( x ( n ) at Wc=1 ) ;

Scilab code Exa 5.13 Circular Convolution

1 // S c i l a b Code f o r Example 5 . 1 3 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // C i r c u l a r C o n v o l u t i o n

102
Figure 5.10: Inverse Fourier

103
4 clear ;
5 // F i r s t C a u s a l s e q u e n c e
6 x =[1 ,4 ,3 ,2;2 ,1 ,4 ,3;3 ,2 ,1 ,4;4 ,3 ,2 ,1]
7 // S e c o n d S e q u e n c e
8 y =[4;3;2;1]
9 // C o n o l u t i o n
10 z = x * y ;
11 disp (z , C o n v o l u t i o n Of x & y i s : )

Scilab code Exa 5.14 Circular Convolution

1 // S c i l a b Code f o r Example 5 . 1 4 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // C i r c u l a r C o n v o l u t i o n
4 clear ;
5 clc ;
6 close ;
7 // F i r s t C a u s a l s e q u e n c e
8 x =[1 ,1 ,1 ,1;1 , - %i , -1 , %i ;1 , -1 ,1 , -1;1 , %i , -1 , - %i ]
9 y1 =[1;2;3;4];
10 y2 =[4;3;2;1];
11 X = x * y1 ;
12 disp (X , V e c t o r X( 0 )>X( 3 ) )
13 Y = x * y2 ;
14 disp (Y , V e c t o r Y( 0 )>Y( 3 ) )
15 for n =1:4;
16 Z (n ,1) = X (n ,1) * Y (n ,1) ;
17 end
18 q =4* x ^ -1;
19 disp (q , IDFT m a t r i x ) ;
20 z =0.25* q * Z ;
21 disp (z , IDFT o f V e c t o r Z ( 0 )>Z ( 3 ) )

104
Scilab code Exa 5.16 DTFT

1 // S c i l a b Code f o r Example 5 . 1 6 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 q =0;
6 x =[1 ,2 ,3 ,4];
7 w =0;
8 n =0:3;
9 z =( exp ( - %i * w * n ) ) ;
10 for n =0:3
11 X ( n +1) = z ( n +1) * x ( n +1) ;
12 q = X ( n +1) + q ;
13 end
14 disp (q , X( 0 )>z e r o t h DFT c o e f f i c i e n t ) ;
15 q =0;
16 w = %pi /2;
17 n =0:3;
18 z =( exp ( - %i * w * n ) ) ;
19 for n =0:3
20 X ( n +1) = z ( n +1) * x ( n +1) ;
21 q = X ( n +1) + q ;
22 end
23 disp (q , X( 1 )> f i r s t DFT c o e f f i c i e n t ) ;
24 q =0;
25 w = %pi ;
26 n =0:3;
27 z =( exp ( - %i * w * n ) ) ;
28 for n =0:3
29 X ( n +1) = z ( n +1) * x ( n +1) ;
30 q = X ( n +1) + q ;
31 end

105
32 disp ( ceil ( q ) , X( 2 )>s e c o n d DFT c o e f f i c i e n t ) ;
33 q =0;
34 w =3* %pi /2;
35 n =0:3;
36 z =( exp ( - %i * w * n ) ) ;
37 for n =0:3
38 X ( n +1) = z ( n +1) * x ( n +1) ;
39 q = X ( n +1) + q ;
40 end
41 disp (q , X( 3 )> t h i r d DFT c o e f f i c i e n t ) ;

Scilab code Exa 5.18 DFT coefficients

1 // S c i l a b Code f o r Example 5 . 1 8 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // Given s i g n a l x ( n )
4 clear ;
5 clc ;
6 x =[1 ,2 ,3 ,4];
7 X = fft ( x ) ;
8 disp (X , FFT o f g i v e n s i g n a l i s : X( 0 )>X( 3 ) )

106
Chapter 6

Sampling and Reconstruction


of Bandlimited Signals

Scilab code Exa 6.1 Sampling and Reconstruction

1 // S c i l a b Code f o r Example 6 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S a m p l i n g o f s i g n a l
4 clc ;
5 clear f n X X_delta w ;
6 fs =200;
7 for f = -200:200
8 X ( f +201) =5*[ delta (f -75) + delta ( f +75) ];
9 end
10 figure (1) ;
11 f = -200:200;
12 plot2d3 (f ,X , -2) ;
13 title ( X( f ) ) ;
14 xlabel ( > f ) ;
15 w =1;
16 n = -1;
17 for f = -275:275
18 X_delta1 ( f +276) = fs *5*[ delta (f - n * fs -75) + delta (f - n

107
* fs +75) ];
19 end
20 n = n +1;
21 for f = -275:275
22 X_delta2 ( f +276) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
23 end
24 n = n +1;
25 for f = -275:275
26 X_delta3 ( f +276) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
27 end
28 X_delta = X_delta1 + X_delta2 + X_delta3 ;
29 figure (2) ;
30 f = -275:275;
31 plot2d3 (f , X_delta , -2) ;
32 title ( X d e l t a ( f ) a t f s =200 ) ;
33 xlabel ( > f ) ;

Scilab code Exa 6.2 Sampling and Reconstruction

1 // S c i l a b Code f o r Example 6 . 2 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S a m p l i n g o f s i g n a l and a l i a s i n g due t o low
Sampling f r e q u e n c y
4 clc ;
5 clear f n X X_delta X_delta1 X_delta2 X_delta3 w ;
6 fs =100;
7 for f = -200:200
8 X ( f +201) =5*[ delta (f -75) + delta ( f +75) ];

108
Figure 6.1: Sampling and Reconstruction

109
Figure 6.2: Sampling and Reconstruction

110
9 end
10 figure (1) ;
11 f = -200:200;
12 plot2d3 (f ,X , -2) ;
13 title ( X( f ) ) ;
14 xlabel ( > f ) ;
15 w =1;
16 n = -2;
17 for f = -175:175
18 X_delta1 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
19 end
20 n = n +1;
21 for f = -175:175
22 X_delta2 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
23 end
24 n = n +1;
25 for f = -175:175
26 X_delta3 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
27 end
28 n = n +1;
29 for f = -175:175
30 X_delta4 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
31 end
32 n = n +1;
33 for f = -175:175
34 X_delta5 ( f +176) = fs *5*[ delta (f - n * fs -75) + delta (f - n
* fs +75) ];
35 end
36 X_delta = X_delta1 + X_delta2 + X_delta3 + X_delta4 + X_delta5
;
37 figure (2) ;
38 f = -175:175;
39
40 plot2d3 (f , X_delta , -2) ;

111
Figure 6.3: Sampling and Reconstruction

41 title ( X d e l t a ( f ) a t f s =100 ) ;
42 xlabel ( > f ) ;
43 // The P r e s e n c e o f t h e 25 HZ component i n t h e
spectrum o f x d e l t a ( t )
44 // Due t o e f f e c t o f A l i a s i n g

Scilab code Exa 6.3 Minimum Number of samples

1 // S c i l a b Code f o r Example 6 . 3 o f S i g n a l s and s y s t e m s

112
Figure 6.4: Sampling and Reconstruction

113
by
2 //P . Ramakrishna Rao
3 // Minimum no . o f s a m p l e s r e q u i r e d
4 clc ;
5 clear ;
6 syms t ;
7 x =10* cos (6* %pi * t ) +4* sin (8* %pi * t ) ;
8 disp (x , x ( t ) ) ;
9 disp ( Maximum F r e q u e n c y component p r e s e n t : 4 Hz ) ;
10 fs =2*4;
11 disp ( fs , Minimum S a m p l i n g F r e q u e n c y t o a v o i d
d i s t o r t i o n i s : );

Scilab code Exa 6.4 Minimum Sampling Frequency

1 // S c i l a b Code f o r Example 6 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S a m p l i n g F r e q u e n c y
4 clc ;
5 clear ;
6 // x ( t ) =100( s i n c ( 1 0 0 t ) ) 2 ;
7 fo =100;
8 fs =2* fo ;
9 disp ( fs , Minimum S a m p l i n g F r e q u e n c y t o a v o i d
d i s t o r t i o n i s : );

Scilab code Exa 6.5 LPF output

1 // S c i l a b Code f o r Example 6 . 5 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao // Output o f LPF
3 clc ;

114
4 clear ;
5
6 for f = -100:100
7 X ( f +101) = delta ( f +100) + delta (f -100) +3*[ delta ( f
+90) + delta (f -90) ];
8 end
9 f = -100:100;
10 a = gca () ;
11 a . x_location = o r i g i n ;
12 a . y_location = o r i g i n ;
13 plot2d3 (f ,X , -2) ;
14 title ( Spectrum o f x ( t ) ) ;
15 xlabel ( > f ) ;
16 fs =150;
17 n = -1; f - n * fs
18 for f = -275:275
19 X_delta1 ( f +276) = delta (f - n * fs +100) + delta (f - n * fs
-100) +3*[ delta (f - n * fs +90) + delta (f - n * fs -90) ];
20 end
21 n = n +1;
22 for f = -275:275
23 X_delta2 ( f +276) = delta (f - n * fs +100) + delta (f - n * fs
-100) +3*[ delta (f - n * fs +90) + delta (f - n * fs -90) ];
24 end
25 n = n +1;
26 for f = -275:275
27 X_delta3 ( f +276) = delta (f - n * fs +100) + delta (f - n * fs
-100) +3*[ delta (f - n * fs +90) + delta (f - n * fs -90) ];
28 end
29 X_delta = X_delta1 + X_delta2 + X_delta3 ;
30 figure (2) ;
31 f = -275:275;
32 plot2d3 (f , X_delta , -2) ;
33 title ( X d e l t a ( f ) a t f s =150 ) ;
34 xlabel ( > f ) ;

115
Figure 6.5: LPF output

Scilab code Exa 6.6 Sampling Frequency

1 // S c i l a b Code f o r Example 6 . 6 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S a m p l i n g F r e q u e n c y / N y q u i s t Rate
4 clc ;
5 clear ;

116
Figure 6.6: LPF output

117
6 syms t ;
7 x =12* cos (800* %pi * t ) * cos ((1800* %pi * t ) ) ^2;
8 disp (x , x ( t ) ) ;
9 disp ( Maximum F r e q u e n c y component p r e s e n t : 2 2 0 0 Hz )
;
10 fs =2*2200;
11 disp ( fs , Minimum S a m p l i n g F r e q u e n c y t o a v o i d
d i s t o r t i o n i s ( Hz ) : ) ;

Scilab code Exa 6.8 Minimum Sampling Frequency

1 // S c i l a b Code f o r Example 6 . 8 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S a m p l i n g F r e q u e n c y o f BPS
4 clc ;
5 clear ;
6 disp ( Maximum F r e q u e n c y component p r e s e n t : 25 kHz ) ;
7 fs =2*25000;
8 disp ( fs , Minimum S a m p l i n g F r e q u e n c y t o a v o i d
d i s t o r t i o n i s : ( Hz ) ) ;

118
Chapter 7

Systems

Scilab code Exa 7.1 Properties of System

1 // S c i l a b Code f o r Example 7 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 a0 =2;
6 a1 =2;
7 a2 =4;
8 x1 =[1 ,3 ,5 ,7];
9 x2 =[2 ,4 ,6 ,8];
10 for t =1:4
11 y1 (1 , t ) = a0 + a1 * x1 ( t ) + a2 *( x1 ( t ) ) ^2;
12 y2 (1 , t ) = a0 + a1 * x2 ( t ) + a2 *( x2 ( t ) ) ^2;
13 end
14 b1 =2;
15 b2 =3;
16 x = b1 * x1 + b2 * x2 ;
17 disp ( y ( n ) d o e s n o t depend on p a s t i n p u t s ) ;
18 disp ( Hence t h e s y s t e m i s S t a t i c ) ;
19 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
20 for t =1:4

119
21 q (1 , t ) = a0 + a1 * x ( t ) + a2 *( x ( t ) ) ^2;
22 end
23 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
24 y = b1 * y1 + b2 * y2 ;
25 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ) ;
26 disp ( Hence t h e s y s t e m i s n o t l i n e a r ) ;

Scilab code Exa 7.3 System Properties

1 // S c i l a b Code f o r Example 7 . 3 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( n )=x ( n )x ( n1) ;
7 disp ( y ( n ) d e p e n d s upon p a s t i n p u t s a l s o ) ;
8 disp ( Output a t n=2 d e p e n d s upon v a l u e o f x a t n=1 )
;
9 disp ( Hence t h e s y s t e m i s Dynamic ) ;
10 x1 =[1 ,3 ,5 ,7 ,2];
11 x2 =[2 ,4 ,6 ,8 ,3];
12 for n =2:5
13 y1 (1 , n ) = x1 ( n ) - x1 (n -1)
14 y2 (1 , n ) = x2 ( n ) - x2 (n -1)
15 end
16 b1 =2;
17 b2 =3;
18 x = b1 * x1 + b2 * x2
19 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
20 for n =2:5
21 q (1 , n ) = x ( n ) -x (n -1) ;
22 end
23 y = b1 * y1 + b2 * y2 ;

120
24 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
25 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ) ;
26 disp ( Hence t h e s y s t e m i s l i n e a r ) ;

Scilab code Exa 7.4 System Properties

1 // S c i l a b Code f o r Example 7 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( t )=x ( 2 t )
7 disp ( y ( t ) d e p e n d s upon p a s t i n p u t s f o r t <0 ) ;
8 disp ( y ( t ) d e p e n d s upon f u t u r e i n p u t s f o r t >0 ) ;
9 disp ( Hence t h e s y s t e m i s Dynamic ) ;
10 x1 =[1 ,3 ,5 ,7 ,2 ,5 ,3 ,9]; //Random V a r i a b l e
11 x2 =[2 ,4 ,6 ,8 ,2 ,4 ,2 ,1];
12 for t =1:4
13 y1 (1 , t ) = x1 (2* t ) ;
14 y2 (1 , t ) = x2 (2* t ) ;
15 end
16 b1 =2;
17 b2 =3;
18 x = b1 * x1 + b2 * x2 ;
19 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
20 for t =1:4
21 q (1 , t ) = x (2* t ) ;
22 end
23 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
24 y = b1 * y1 + b2 * y2 ;
25 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ) ;
26 disp ( Hence t h e s y s t e m i s l i n e a r ) ;

121
27 disp ( For a d e l a y (T) o f 2 s e c o n d s ) ;
28 disp ( At t =3 s e c o n d s : ) ;
29 t =3;
30 a = x (1 ,2* t -2) ;
31 b = y (1 ,t -2) ;
32 c = x (1 ,2* t -4) ;
33 disp (a , x ( 2 tT) : ) ;
34 disp (b , i s n o t e q u a l t o y ( 2 tT) : ) ;
35 disp (c , w h i l e x ( 2 t 2T) : ) ;
36 disp ( Hence t h e s y s t e m i s Time v a r i a n t ) ;

Scilab code Exa 7.5 System Properties

1 // S c i l a b Code f o r Example 7 . 5 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( t )=x ( 2 n )
7 disp ( y ( n ) d e p e n d s upon p a s t i n p u t s f o r n<0 ) ;
8 disp ( y ( n ) d e p e n d s upon f u t u r e i n p u t s f o r n>0 ) ;
9 disp ( Hence t h e s y s t e m i s Dynamic ) ;
10 x1 =[1 ,3 ,5 ,3 ,2 ,5 ,3 ,9]; // random v a r i a b l e
11 x2 =[2 ,4 ,6 ,4 ,2 ,4 ,2 ,1];
12 for n =1:4
13 y1 (1 , n ) = x1 (2* n ) ;
14 y2 (1 , n ) = x2 (2* n ) ;
15 end
16 b1 =2;
17 b2 =3;
18 x = b1 * x1 + b2 * x2 ;
19 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
20 for n =1:4
21 q (1 , n ) = x (2* n ) ;

122
22 end
23 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
24 y = b1 * y1 + b2 * y2 ;
25 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ) ;
26 disp ( Hence t h e s y s t e m i s l i n e a r ) ;
27 disp ( For a d e l a y ( n0 ) o f 2 s e c o n d s ) ;
28 disp ( At n=3 s e c o n d s : ) ;
29 t =3;
30 a = x (1 ,2* n -2) ;
31 b = y (1 ,n -2) ;
32 c = x (1 ,2* n -4) ;
33 disp (a , x ( 2 nn0 ) : ) ;
34 disp (b , i s n o t e q u a l t o y ( 2 nn0 ) : ) ;
35 disp (c , w h i l e x ( 2 n2n0 ) : ) ;
36 disp ( Hence t h e s y s t e m i s Time v a r i a n t ) ;

Scilab code Exa 7.6 System Properties

1 // S c i l a b Code f o r Example 7 . 6 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( n )=x ( n )x ( n1) ;
7 x =[2 ,4 ,3 ,6 ,7]
8 for n =2:5
9 y (1 , n ) = x ( n ) -x (n -1) ;
10 end
11 disp (y , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
12 disp ( For a s h i f t ( n0 ) o f 2 s e c o n d s ) ;
13 disp ( At n=3 s e c o n d s : ) ;
14 n =5;
15 b = y (n -2) ;

123
16 a = x (n -2) -x (n -2 -1) ;
17 disp (a , x ( n 2) : ) ;
18 disp (b , i s e q u a l t o y ( n2) : ) ;
19 disp ( Hence t h e s y s t e m i s S h i f t i n v a r i a n t / f i x e d );

Scilab code Exa 7.7 Properties of System

1 // S c i l a b Code f o r Example 7 . 7 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( t )=n x ( n )
7 disp ( y ( n ) d e p e n d s o n l y upon p r e s e n t i n p u t s ) ;
8 disp ( ( i ) Hence t h e s y s t e m i s Dynamic ) ;
9 x1 =[1 ,3 ,5 ,3 ,2 ,5 ,3 ,9]; // random v a r i a b l e
10 x2 =[2 ,4 ,6 ,4 ,2 ,4 ,2 ,1];
11 for n =1:4
12 y1 (1 , n ) = n * x1 ( n ) ;
13 y2 (1 , n ) = n * x2 ( n ) ;
14 end
15 b1 =2;
16 b2 =3;
17 x = b1 * x1 + b2 * x2 ;
18 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
19 for n =1:4
20 q (1 , n ) = n * x ( n ) ;
21 end
22 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
23 y = b1 * y1 + b2 * y2 ;
24 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ) ;
25 disp ( ( i i ) Hence t h e s y s t e m i s l i n e a r ) ;
26 disp ( For a d e l a y ( n0 ) o f 2 s e c o n d s ) ;

124
27 disp ( At n=3 s e c o n d s : ) ;
28 t =3;
29 a = x (1 ,n -2) ;
30 b = y (1 ,n -2) ;
31 c =2* x (1 ,n -2) ;
32 disp (a , x ( nn0 ) : ) ;
33 disp (b , i s n o t e q u a l t o y ( nn0 ) : ) ;
34 disp (c , w h i l e ( nn0 ) x ( nn0 ) : ) ;
35 disp ( ( i i i ) Hence t h e s y s t e m i s Time v a r i a n t ) ;

Scilab code Exa 7.8 Properties of System

1 // S c i l a b Code f o r Example 7 . 8 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( t )=sum ( x ( n ) ) , n2<=n=<n+2
7 x1 =[1 ,3 ,5 ,3 ,0 ,0 ,0 ,0 ,0 ,0]; // random v a r i a b l e
8 x2 =[2 ,4 ,6 ,4 ,0 ,0 ,0 ,0 ,0 ,0];
9 for n =1:4
10 y1 (1 , n ) = x1 ( n ) + x1 ( n +1) + x1 ( n +2) + x1 ( n +3) + x1 ( n +4) ;
11 y2 (1 , n ) = x2 ( n ) + x2 ( n +1) + x2 ( n +2) + x2 ( n +3) + x2 ( n +4) ;
12 end
13 b1 =2;
14 b2 =3;
15 x = b1 * x1 + b2 * x2 ;
16 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
17 for n =1:4
18 q (1 , n ) = x ( n ) + x ( n +1) + x ( n +2) + x ( n +3) + x ( n +4) ;
19 end
20 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
21 y = b1 * y1 + b2 * y2 ;
22 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t

125
s h o u l d be : ) ;
23 disp ( ( i ) Hence t h e s y s t e m i s l i n e a r ) ;

Scilab code Exa 7.9 Properties of System

1 // S c i l a b Code f o r Example 7 . 9 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear x y1 y y2 q t n ;
5 clear ;
6 // y ( t )=exp | x ( n ) |
7 x1 =[1 ,3 ,5 ,3]; // random v a r i a b l e
8 x2 =[2 ,4 ,6 ,4];
9 for n =1:4
10 y1 (1 , n ) = exp ( abs ( x1 ( n ) ) ) ;
11 y2 (1 , n ) = exp ( abs ( x2 ( n ) ) ) ;
12 end
13 b1 =2;
14 b2 =3;
15 x = b1 * x1 + b2 * x2 ;
16 disp (x , The i n p u t t o t h e s y s t e m i s : ) ;
17 for n =1:4
18 q (1 , n ) = exp ( abs ( b1 *( x1 ( n ) ) + b2 *( x2 ( n ) ) ) ) ;
19 end
20 disp (q , T h i s i n p u t g i v e s t h e o u t p u t : ) ;
21 y = b1 * y1 + b2 * y2 ;
22 disp (y , For t h e s y s t e m t o be l i n e a r t h e o u t p u t
s h o u l d be : ) ;
23 disp ( ( i i ) Hence t h e s y s t e m i s n o t l i n e a r ) ;
24 disp ( For a d e l a y ( n0 ) o f 2 s e c o n d s ) ;
25 disp ( At n=3 s e c o n d s : ) ;
26 n =4;
27 a = exp ( abs ( x1 (n -2) ) ) ;
28 b = y1 (1 ,n -2) ;

126
29 disp (a , e x ( nn0 ) : ) ;
30 disp (b , i s e q u a l t o y ( nn0 ) : ) ;
31 disp ( ( i i i ) Hence t h e s y s t e m i s Time i n v a r i a n t ) ;

Scilab code Exa 7.10 Output of an LTI

1 // S c i l a b Code f o r Example 7 . 1 0 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 disp ( h ( t )=e 2 t . u ( t ) ) ;
6 for w =1:100
7 y (1 , w ) = integrate ( exp ( 2 t ) , t ,0 , w ) ;
8 end
9 w =1:100;
10 plot (w , y )
11 title ( Output S i g n a l y ( t ) ) ;
12 xlabel ( Time ) ;
13 ylabel ( A m p l i t u d e ) ;

Scilab code Exa 7.11 Convolution

1 // S c i l a b Code f o r Example 7 . 1 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 clear x y n ;
6 x =[0 ,0 ,2 ,0 ,0];
7 y =[0 ,0 ,1 ,1 ,0];

127
Figure 7.1: Output of an LTI

128
8 n = -2:2;
9 c = gca () ;
10 c . y_location = o r i g i n ;
11 c . x_location = o r i g i n ;
12 plot2d2 (n ,x ,2) ;
13 title ( x ( t ) )
14 xlabel ( t )
15 figure (1) ;
16 n = -2:2;
17 c = gca () ;
18 c . y_location = o r i g i n ;
19 c . x_location = o r i g i n ;
20 plot2d2 (n ,y ,5) ;
21 title ( y ( t ) )
22 xlabel ( t )
23 z = conv (x , y ) ;
24 figure (2) ;
25 n = -3:5;
26 c = gca () ;
27 c . y_location = o r i g i n ;
28 c . x_location = o r i g i n ;
29 plot (n ,z ,2) ;
30 title ( C o n v o l u t e d s i g n a l z( t ) )
31 xlabel ( t )

Scilab code Exa 7.14 Impulse and Step response

1 // S c i l a b Code f o r Example 7 . 1 4 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // P l o t t i n g t h e i m p u l s e and s t e p r e s p o n s e s
4 clc ;
5 clear ;

129
Figure 7.2: Convolution

130
6 syms s t R C ;
7 Y1 =(1/( R * C ) ) /( s +1/( R * C ) ) ;
8 disp ( Y1 , L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l Equation
is : )
9 y11 = ilaplace ( Y1 ,s , t ) ;
10 disp ( y11 , The I m p u l s e R e s p o n s e o f t h e System i s : ) ;
11 for k =0:10;
12 y1 ( k +1) = exp ( - k ) ;
13 end
14 k =0:10;
15 plot (k , y1 ) ;
16 title ( System R e s p o n s e t o i m p u l s e i n p u t ) ;
17 Y2 =(1/( R * C ) ) /( s ^2+ s /( R * C ) ) ;
18 disp ( Y2 , L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l E q u a t i o n
is : )
19 y22 = ilaplace ( Y2 ,s , t ) ;
20 disp ( y22 , The S t e p R e s p o n s e o f t h e System i s : ) ;
21 for k =0:10;
22 y2 ( k +1) =1 - exp ( - k ) ;
23 end
24 figure (1) ;
25 k =0:10;
26 plot (k , y2 ) ;
27 title ( System R e s p o n s e t o S t e p i n p u t ) ;

Scilab code Exa 7.15 Impulse and Step Response

1 // S c i l a b Code f o r Example 7 . 1 5 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // P l o t t i n g t h e i m p u l s e and s t e p r e s p o n s e s

131
Figure 7.3: Impulse and Step response

132
Figure 7.4: Impulse and Step response

133
4 clc ;
5 clear ;
6 syms s t R L ;
7 Y1 =(1/ s ) -(1/( s +( R / L ) ) ) ;
8 disp ( Y1 , L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l Equation
is : )
9 y1 = ilaplace ( Y1 ,s , t ) ;
10 disp ( y1 , The S t e p R e s p o n s e o f t h e System i s : ) ;
11 // Taking R/L=1;
12 for k =0:10;
13 y1 ( k +1) =1 - exp ( - k ) ;
14 end
15 k =0:10;
16 plot (k , y1 ) ;
17 title ( System R e s p o n s e t o S t e p i n p u t ) ;
18 Y2 =(1/( s +( R / L ) ) ) ;
19 disp ( Y2 , L a p l a c e T r a n s f o r m Of d i f f e r e n t i a l E q u a t i o n
is : )
20 y2 = ilaplace ( Y2 ,s , t ) ;
21 disp ( y2 , The I m p u l s e R e s p o n s e o f t h e System i s : ) ;
22 for k =0:10;
23 y2 ( k +1) = exp ( - k ) ;
24 end
25 figure (1) ;
26 k =0:10;
27 plot (k , y2 ) ;
28 title ( System R e s p o n s e t o i m p u l s e i n p u t ) ;

Scilab code Exa 7.19 Convolution

1 // S c i l a b Code f o r Example 7 . 1 9 o f S i g n a l s and

134
Figure 7.5: Impulse and Step Response

135
Figure 7.6: Impulse and Step Response

136
s y s t e m s by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;
5 clear ;
6 clear x y n ;
7 x =[2 , -1 ,1 ,0 ,2];
8 y =[1 ,0 , -1 ,2];
9 n = -1:3;
10 c = gca () ;
11 c . y_location = o r i g i n ;
12 c . x_location = o r i g i n ;
13 plot2d3 (n ,x , -5) ;
14 title ( x ( k ) )
15 xlabel ( k )
16 figure (1) ;
17 n =0:3;
18 c = gca () ;
19 c . y_location = o r i g i n ;
20 c . x_location = o r i g i n ;
21 plot2d3 (n ,y , -5) ;
22 title ( y ( k ) )
23 xlabel ( k )
24 z = conv (x , y ) ;
25 figure (2) ;
26 n = -1:6;
27 c = gca () ;
28 c . y_location = o r i g i n ;
29 c . x_location = o r i g i n ;
30 plot2d3 (n ,z , -5) ;
31 title ( C o n v o l u t e d s i g n a l z( t ) )
32 xlabel ( t )

137
Figure 7.7: Convolution

138
Scilab code Exa 7.22 Convolution

1 // S c i l a b Code f o r Example 7 . 2 2 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;
5 clear ;
6 clear x y n ;
7 for n =0:10;
8 x ( n +1) =(3/4) ^ n * u ( n ) ;
9 end
10 c = gca () ;
11 c . y_location = o r i g i n ;
12 c . x_location = o r i g i n ;
13 n =0:10;
14 plot2d3 (n ,x , -4) ;
15 title ( x ( n ) )
16 xlabel ( n )
17 for n =0:10;
18 y ( n +1) = u ( n ) ;
19 end
20 figure (1) ;
21 n =0:10;
22 c = gca () ;
23 c . y_location = o r i g i n ;
24 c . x_location = o r i g i n ;
25 plot2d3 (n ,y , -4) ;
26 title ( y ( k ) )
27 xlabel ( k )
28 z = conv (x , y ) ;
29 figure (2) ;
30 n =0:20;
31 c = gca () ;
32 c . y_location = o r i g i n ;
33 c . x_location = o r i g i n ;
34 plot2d3 (n ,z , -4) ;
35 title ( C o n v o l u t e d s i g n a l w( t ) ) ;

139
Figure 7.8: Convolution

36 xlabel ( t ) ;
37 disp ( z (1) , z ( 0 ) ,z (4) , z ( 3 ) ,z (6) , z ( 5 ) ,z (11) , z
( 1 0 ) );

Scilab code Exa 7.23 Convolution

1 // S c i l a b Code f o r Example 7 . 2 3 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;

140
5 clear ;
6 clear x y n ;
7 for n =0:10;
8 x ( n +1) =(0.5) ^ n * u (n -2) ;
9 end
10 c = gca () ;
11 c . y_location = o r i g i n ;
12 c . x_location = o r i g i n ;
13 n =0:10;
14 plot2d3 (n ,x , -4) ;
15 title ( x ( n ) )
16 xlabel ( n )
17 for n =0:10;
18 y ( n +1) = u ( n ) ;
19 end
20 figure (1) ;
21 n =0:10;
22 c = gca () ;
23 c . y_location = o r i g i n ;
24 c . x_location = o r i g i n ;
25 plot2d3 (n ,y , -4) ;
26 title ( y ( k ) )
27 xlabel ( k )
28 z = conv (x , y ) ;
29 figure (2) ;
30 n =0:20;
31 c = gca () ;
32 c . y_location = o r i g i n ;
33 c . x_location = o r i g i n ;
34 plot2d3 (n ,z , -4) ;
35 title ( C o n v o l u t e d s i g n a l z( t ) )
36 xlabel ( t )

141
Figure 7.9: Convolution

142
Scilab code Exa 7.24 Step Response

1 // S c i l a b Code f o r Example 7 . 2 4 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // P l o t t i n g t h e s t e p r e s p o n s e
4 clc ;
5 clear ;
6 syms z n ;
7 y1 =2*(1 -0.5^ n ) ;
8 disp ( y1 * u ( n ) , The s t e p R e s p o n s e o f t h e System i s :
);
9 for n =0:10;
10 q ( n +1) =2*(1 -0.5^ n ) ;
11 end
12 n =0:10;
13 plot (n , q ) ;
14 title ( S t e p R e s p o n s e g ( n ) );
15 xlabel ( n> ) ;

Scilab code Exa 7.25 Step response

1 // S c i l a b Code f o r Example 7 . 2 5 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // P l o t t i n g t h e i m p u l s e and s t e p r e s p o n s e s
4 clc ;
5 clear ;
6 syms z a n ;
7 Y1 =(2* z /( z - a ) ) ;
8 disp ( Y1 , Z T r a n s f o r m Of d i f f e r e n t i a l E q u a t i o n i s : )
9 y12 =2* a ^ n ;
10 disp ( y12 , The U n i t Sample R e s p o n s e o f t h e System i s :

143
Figure 7.10: Step Response

144
Figure 7.11: Step response

);
11 y2 =2*( a ^n -1) /( a -1) ;
12 disp ( y2 , The S t e p R e s p o n s e o f t h e System i s : ) ;
13 q =1;
14 a =0.5;
15 for k =0:0.1:5;
16 y2 ( q ) =2*(( a ^k -1) /( a -1) ) ;
17 q = q +1;
18 end
19 k =0:0.1:5;
20 plot (k , y2 ) ;

145
Scilab code Exa 7.33 Magnitude and Phase Response

1 // S c i l a b Code f o r Example 7 . 3 3 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // P l o t t i n g t h e m a g n i t u d e and p h a s e r e s p o n s e s
4 clc ;
5 clear ;
6 T =1;
7 n =1;
8 for w =0:0.1:20;
9 hmag ( n ) =2* sin ( w * T /2) ;
10 n = n +1;
11 end
12 n =1;
13 for w =0:0.1:20;
14 hphase ( n ) = %pi /2 -( w * T /2) ;
15 n = n +1;
16 end
17 // Magnitude p l o t
18 w =0:0.1:20;
19 plot (w , hmag ) ;
20 title ( Magnitude P l o t ) ;
21 xlabel ( w ) ;
22 ylabel ( | H( e jw ) | ) ;
23 figure (1) ;
24 // Phase P l o t
25 w =0:0.1:20;
26 plot (w , hphase ) ;
27 title ( Phase P l o t ) ;
28 xlabel ( w ) ;
29 ylabel ( t h e t a (wT) ) ;

146
Figure 7.12: Magnitude and Phase Response

147
Figure 7.13: Magnitude and Phase Response

148
Chapter 8

Systems Time and Frequency


Domain Analysis

Scilab code Exa 8.1 Magnitude and Phase Responses

1 // S c i l a b Code f o r Example 8 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // F i r s t Order c a u s a l LTI s y s t e m
4 clear ;
5 clc ;
6 syms s t ;
7 Y =1/( s +6) ;
8 h = exp ( -6* t ) ;
9 H = laplace (h ,t , jw ) ;
10 disp (H , H(w)= ) ;
11 n =1;
12 for w = -5*2* %pi :0.01:5*2* %pi
13 Hmag ( n ) =1/ sqrt (36+ w ^2)
14 Hphs ( n ) = - atan ( w /6) ;
15 n = n +1;
16 end
17 w = -5*2* %pi :0.01:5*2* %pi ;
18 plot (w , Hmag ) ;

149
Figure 8.1: Magnitude and Phase Responses

19 title ( I m p u l s e R e s p o n s e ) ;
20 ylabel ( A m p l i t u d e ) ;
21 xlabel ( t i m e i n s e c o n d s ) ;
22 figure (1) ;
23 w = -5*2* %pi :0.01:5*2* %pi ;
24 plot (w , Hphs ) ;
25 title ( Phase R e s p o n s e ) ;
26 ylabel ( t h e t a (w) ) ;
27 xlabel ( w i n r a d i a n s / s e c o n d ) ;

150
Figure 8.2: Magnitude and Phase Responses

151
Scilab code Exa 8.2 Transfer Function of system

1 // S c i l a b Code f o r Example 8 . 2 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S e c o n d o r d e r s y s t e m
4 clear ;
5 clc ;
6 syms t ;
7 L =1;
8 R =1.2;
9 C =10^ -6;
10 Rcr =2* sqrt ( L / C ) ;
11 eta = R / Rcr ;
12 disp ( eta , Damping R a t i o= ,Rcr , C r i t i c a l R e s i s t a n c e (
ohm ) , ( i ) ) ;
13 Wn =1/ sqrt ( L * C ) ;
14 disp ( Wn , Undamped N a t u r a l F r e q u e n c y ( Hz ) , ( i i ) ) ;
15 n =1;
16 h =(1250* sin (800* t ) ) * exp ( -600* t ) ;
17 H = laplace (h ,t , jW ) ;
18 for t =0:0.1:2;
19 h ( n ) =(1250* sin (800* t ) ) * exp ( -600* t ) ; // I m p u l s e
Response
20 n = n +1;
21 end
22 t =0:0.1:2;
23 plot (t , h ) ;
24 title ( I m p u l s e R e s p o n s e ) ;
25 ylabel ( A m p l i t u d e ) ;
26 xlabel ( t i m e i n s e c o n d s ) ;
27 disp (H , ( i v ) T r a n s f e r F u n c t i o n (H( jw ) ) : ) ;

152
Figure 8.3: Transfer Function of system

153
Scilab code Exa 8.3 Magnitude and Phase Responses

1 // S c i l a b Code f o r Example 8 . 3 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms n w ;
6 h =(0.3) ^ n ;
7 disp (h , The i m p u l s e r e s p o n s e o f t h e s y s t e m i s : ) ;
8 H =1/(1 -(0.3* exp ( - %i * w ) ) ) ;
9 disp (H , The T r a n s f e r f u n c t i o n o f t h e s y s t e m i s : ) ;
10 n =1;
11 for w = - %pi :0.1: %pi
12 Hmag ( n ) =1/ sqrt (1.09 -(0.6* cos ( w ) ) ) ;
13 Hphs ( n ) = - atan (0.3* sin ( w ) /(1 -0.3* cos ( w ) ) ) ;
14 n = n +1;
15 end
16 w = - %pi :0.1: %pi ;
17 c = gca () ;
18 c . y_location = o r i g i n ;
19 c . x_location = o r i g i n ;
20 c . thickness =2;
21 plot (w , Hmag ) ;
22 title ( Magnitude S k e t c h ) ;
23 ylabel ( A m p l i t u d e ) ;
24 xlabel ( W i n r a d i a n s ) ;
25 figure (1) ;
26 w = - %pi :0.1: %pi ;
27 c = gca () ;
28 c . y_location = o r i g i n ;
29 c . x_location = o r i g i n ;
30 c . thickness =2;
31 plot (w , Hphs ) ;
32 title ( Phase R e s p o n s e ) ;
33 ylabel ( t h e t a (w) ) ;
34 xlabel ( W i n r a d i a n s )

154
Figure 8.4: Magnitude and Phase Responses

Scilab code Exa 8.4 system response

1 // S c i l a b Code f o r Example 8 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S e c o n d Order System
4 clear ;
5 clc ;

155
Figure 8.5: Magnitude and Phase Responses

156
6 z = %z ;
7 syms n z1 ;
8 X =( z -1) /(( z +(1/2) ) *( z -(1/5) ) )
9 disp (X , ( i ) System F u n c t i o n i s : ) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 ) ;
12 X1 = ( z1 -1) /(( z1 +(1/2) ) *( z1 -(1/5) ) ) ;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 - zp (1) )
14 F2 = X1 *( z1 ^( n -1) ) *( z1 - zp (2) )
15 h1 = limit ( F1 , z1 , zp (1) )
16 h2 = limit ( F2 , z1 , zp (2) )
17 h = h1 + h2 ;
18 disp ( ( i v ) U n i t s a m p l e r e s p o n s e s e q u e n c e : )
19 disp ( h * u ( n ) , h [ n ]= ) ;
20 for n =0:10;
21 w ( n +1) =( - 5.714*(0.2) ^n - 4.285*( - 0.5^ n ) ) ;
22 end
23 n =0:10;
24 plot (n , w ) ;
25 title ( ( i i i ) U n i t Sample R e s p o n s e S e q u e n c e ) ;
26 disp ( where z=e jw ,X , ( i ) T r a n s f e r F u n c t i o n i s : ) ;

Scilab code Exa 8.5 System function

1 // S c i l a b Code f o r Example 8 . 5 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // S e c o n d Order System
4 clear ;
5 clc ;
6 z = %z ;
7 syms n z1 ;
8 X = z ^2/( z -0.5) ^2

157
Figure 8.6: system response

158
9 disp (X , ( i ) System F u n c t i o n i s : ) ;
10 X1 = denom ( X ) ;
11 zp = roots ( X1 ) ;
12 X1 = z1 ^2/( z1 -0.5) ^2;
13 F1 = X1 *( z1 ^( n -1) ) *( z1 -0.5) ^2;
14 h1 = limit ( F1 , z1 , zp (1) ) ;
15 h = h1 ;
16 disp ( ( i i i ) U n i t s t e p r e s p o n s e s e q u e n c e : )
17 disp ( h * u ( n ) , h [ n ]= ) ;
18 for n =0:20;
19 w1 ( n +1) =1 -(0.5) ^ n ;
20 end
21 n =0:20;
22 plot (n , w1 ) ;
23 title ( ( i i ) U n i t Sample R e s p o n s e S e q u e n c e ) ;
24 disp ( where z=e jw ,X , ( i v ) T r a n s f e r F u n c t i o n (H( e
jw ) ) i s : ) ;

Scilab code Exa 8.8 Transfer function

1 // S c i l a b Code f o r Example 8 . 8 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms R L C s I ;
6 X = I *( R +1/( C * s ) ) ;
7 Y=R*I;
8 Z=Y/X;
9 disp (Z , ( a ) RC High p a s s F i l t e r : H( s ) ) ;
10 X = I *( L * s +1/( C * s ) ) ;
11 Y = I /( C * s ) ;
12 Z=Y/X;

159
Figure 8.7: System function

160
13 disp (Z , ( b ) LC Low p a s s F i l t e r : H( s ) ) ;

Scilab code Exa 8.9 Transfer function by block diagram reduction

1 // S c i l a b Code f o r Example 8 . 9 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms G1 G2 G3 G4 H1 H2 s ;
6 G1 = s /( s +5) ;
7 G2 =10/( s +10) ;
8 H1 = s ;
9 H2 =1/ s ;
10 disp ( ( i ) S h i f t i n g t h e t a k e o f f p o i n t ) ;
11 H1 = H1 / G2 ;
12 disp ( ( i i ) S o l v i n g s e c o n d Feedback Loop ) ;
13 G3 = H1 -1;
14 disp ( ( i i i ) S o l v i n g f i r s t Feedbac k Loop ) ;
15 G4 = G2 /(1+ G2 * H2 ) ;
16 Z = G1 * G3 * G4 ;
17 disp (Z , ( i v ) The T r a n s f e r F u n c t i o n i s : ) ;

Scilab code Exa 8.10 Realization Structure

1 // S c i l a b Code f o r Example 8 . 1 0 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms s1 ;
6 s = %s ;
7 H = poly (0 , s ) ;

161
8 H = s ^3/( s ^3+6* s ^2++11* s +6) ;
9 H1 = denom ( H ) ;
10 a = roots ( H1 ) ;
11 H2 =5*( s1 ^3/( s1 - a (1) ) ) *( s1 /( s1 - a (2) ) ) *( s1 /( s1 - a (3) ) ) ;
12 disp ( H2 , ( i i ) C a s c a d e Form : H( s ) ) ;
13 h1 = s1 ^3*( s1 - a (1) ) /(( s1 +1) *( s1 +2) *( s1 +3) ) ;
14 h2 = s1 ^3*( s1 - a (2) ) /(( s1 +1) *( s1 +2) *( s1 +3) ) ;
15 h3 = s1 ^3*( s1 - a (3) ) /(( s1 +1) *( s1 +2) *( s1 +3) ) ;
16 A = limit ( h1 , s1 , a (1) ) /( s - a (1) ) ;
17 B = limit ( h2 , s1 , a (2) ) /( s - a (2) ) ;
18 C = limit ( h3 , s1 , a (3) ) /( s - a (3) ) ;
19 Z =5*(1+ A + B + C ) ;
20 disp (Z , ( i i i ) P a r a l l e l Form R e a l i z a t i o n : H( s ) ) ;

Scilab code Exa 8.12 Transfer function Realization

1 // S c i l a b Code f o r Example 8 . 1 2 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // S e c o n d Order LSI s y s t e m
4 z = %z ;
5 s = %s ;
6 X = z ^ -1/(0.7* z ^ -2 -3.7* z ^ -1+3) ;
7 [ A ]= pfss ( z ^ -1/(0.7* z ^ -2 -3.7* z ^ -1+3) )
8 x1 = horner ( A (1) ,z )
9 x2 = horner ( A (2) ,z )
10 q = denom ( X ) ;
11 a = roots ( q )
12 H =[ x1 x2 z /3];
13 disp (H , ( a ) H( z )= ) ;
14 clear z ;
15 syms z n ;
16 F1 = ((1/6) *( z /( z -1) ) * z ^( n -1) *( z - a (1) ) )
17 F2 = ((0.7/54) *( z /( z -0.233333) ) * z ^( n -1) *( z - a (2) ) )
18 w1 = limit ( F1 ,z , a (1) )

162
19 w2 = limit ( F2 ,z , a (2) )
20 w = w1 + w2 ;
21 disp (w , ( b ) h ( n ) )= ) ;
22 z = %z ;
23 x11 = z * x1 /3
24 x12 = z * x2 /3
25 disp ( x11 , ( c ) P a r a l l e l r e a l i z a t i o n : H1 ( z ) ) ;
26 disp ( x12 , H2 ( z ) )

Scilab code Exa 8.13 Parallel form realization

1 // S c i l a b Code f o r Example 8 . 1 3 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 clear ;
4 clc ;
5 syms z1 ;
6 z = %z ;
7 H = poly (0 , z ) ;
8 H = z *( z +0.5) *( z +0.25) /(( z -0.5) *( z -0.25) *( z -0.125) ) ;
9 H1 = denom ( H ) ;
10 a = roots ( H1 )
11 h1 =( z1 +0.5) *( z1 +0.25) /(( z1 -0.5) *( z1 -0.25) *( z1 -0.125)
) *( z1 - a (1) ) ;
12 h2 =( z1 +0.5) *( z1 +0.25) /(( z1 -0.5) *( z1 -0.25) *( z1 -0.125)
) *( z1 - a (2) ) ;
13 h3 =( z1 +0.5) *( z1 +0.25) /(( z1 -0.5) *( z1 -0.25) *( z1 -0.125)
) *( z1 - a (3) ) ;
14 A = z * limit ( h1 , z1 , a (1) ) /( z - a (1) ) ;
15 B = z * limit ( h2 , z1 , a (2) ) /( z - a (2) ) ;
16 C = z * limit ( h3 , z1 , a (3) ) /( z - a (3) ) ;
17 Z=A+B+C;
18 disp (Z , P a r a l l e l Form R e a l i s a t i o n : H( z ) ) ;

163
Chapter 9

Convolution and Correlation


Continuous Time Signals

Scilab code Exa 9.1 Convolution

1 // S c i l a b Code f o r Example 9 . 1 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;
5 n =1;
6 for t = -10:0.1:10
7 x ( n ) =5* cos ( t ) ;
8 y ( n ) =2* exp ( - abs ( t ) ) ;
9 n = n +1;
10 end
11 z = conv (x , y ) ;
12 t2 = -20:0.1:20;
13 plot2d ( t2 , z ) ;
14 title ( Output s i g n a l ) ;
15 xlabel ( Time t> ) ;

164
Figure 9.1: Convolution

165
Figure 9.2: Convolution

Scilab code Exa 9.3 Convolution

1 // S c i l a b Code f o r Example 9 . 3 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 // C o n v o l u t i o n o f two s i g n a l s
4 clc ;
5 clear ;
6 n =1;
7 for t = -5:0.1:5

166
8 x ( n ) = -2* u (t -0.5) +2* u (t -1.5) ;
9 y ( n ) =( t +1) * u ( t +1) -( t +1) * u (t -2) ;
10 n = n +1;
11 end
12 z = conv (x , y ) ;
13 t = -5:0.1:5;
14 plot2d2 (t ,x ,5) ;
15 title ( x ( t ) ) ;
16 figure (1) ;
17 t = -5:0.1:5;
18 plot2d (t ,y ,2) ;
19 title ( y ( t ) ) ;
20 figure (2) ;
21 t = -10:0.1:10;
22 plot2d (t ,z ,6) ;
23 title ( C o n v o l u t i o n ) ;

Scilab code Exa 9.4 Autocorrelation

1 // S c i l a b Code f o r Example 9 . 4 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 T =1;
6 n =1;
7 for t = - T /2:0.01: T /2;
8 x ( n ) =10* cos ( %pi * t / T ) ;
9 n = n +1;
10 end
11 t = - T /2:0.01: T /2;
12 plot (t , x ) ;
13 title ( x ( t ) ) ;

167
Figure 9.3: Autocorrelation

168
Figure 9.4: Autocorrelation

14 disp ( Rxx ( 0 )=Energy o f s i g n a l ) ;


15 Rxx = integrate ( 50(1+ c o s ( 2 %pi t /T) ) , t ,-T /2 , T /2) ;
16 disp ( Rxx , Rxx ( 0 )= ) ;

Scilab code Exa 9.5 Autocorrelation

1 // S c i l a b Code f o r Example 9 . 5 o f S i g n a l s and s y s t e m s


by
2 //P . Ramakrishna Rao

169
Figure 9.5: Autocorrelation

170
3 clc ;
4 clear ;
5 clear z x y t T ;
6 n =1;
7 for t = -10:0.01:10;
8 x ( n ) = exp ( - t ) * u ( t ) ;
9 n = n +1;
10 end
11 t = -10:0.01:10;
12 plot (t , x ) ;
13 title ( x ( t ) ) ;
14 n =1;
15 for T = -10:0.1:0;
16 z ( n ) = integrate ( exp ( t ) exp (Tt ) , t ,0 ,1000) ;
17 n = n +1;
18 end
19 n =1;
20 for T =0.1:0.1:10;
21 z ( n +101) = integrate ( exp ( t ) exp (Tt ) , t ,T
,1000) ;
22 n = n +1;
23 end
24 figure (1) ;
25 T = -10:0.1:10;
26 plot (T , z ) ;
27 title ( Rxx (T) ) ;
28 xlabel ( t i n s e c o n d s ) ;

Scilab code Exa 9.6 Autocorrelation

1 // S c i l a b Code f o r Example 9 . 6 o f S i g n a l s and s y s t e m s

171
Figure 9.6: Autocorrelation

172
Figure 9.7: Autocorrelation

173
by
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 clear z x y t T ;
6 A =1;
7 n =1;
8 wo =2* %pi ;
9 theta = %pi /2;
10 for t = -5:0.01:5;
11 x ( n ) = A * cos ( wo * t + theta ) ;
12 n = n +1;
13 end
14 t = -5:0.01:5;
15 plot (t , x ) ;
16 title ( x ( t ) ) ;
17 n =1;
18 for T = -5:0.1:5;
19 z ( n ) =( A ^2/2) * cos ( wo * T ) ;
20 n = n +1;
21 end
22 figure (1) ;
23 T = -5:0.1:5;
24 plot (T , z ) ;
25 title ( Rxx (T) ) ;
26 xlabel ( t i n s e c o n d s )

Scilab code Exa 9.7 Autocorrelation

1 // S c i l a b Code f o r Example 9 . 7 o f S i g n a l s and s y s t e m s


by

174
Figure 9.8: Autocorrelation

175
Figure 9.9: Autocorrelation

176
2 //P . Ramakrishna Rao
3 clc ;
4 clear ;
5 clear z x y t T A ;
6 A =4;
7 T0 =2;
8 n =1;
9 for T =0:0.1: T0 ;
10 if T < T0 /2 then
11 x(n)=A;
12 else x ( n ) =0;
13 end
14 n = n +1;
15 end
16 T =0:0.1: T0 ;
17 plot2d2 (T ,x ,6) ;
18 title ( x ( t ) ) ) ;
19 xlabel ( t i n s e c o n d s ) ;
20 n =1;
21 for T =0:0.1: T0 ;
22 z ( n ) =(1/ T0 ) * integrate ( A2 , t ,T , T0 /2) ;
23 n = n +1;
24 end
25 T =0:0.1: T0 ;
26 figure (1) ;
27 plot (T , z ) ;
28 title ( Rxx (T) ) ;
29 xlabel ( T i n s e c o n d s ) ;

Scilab code Exa 9.10 Autocorrelation Function

1 // S c i l a b Code f o r Example 9 . 1 0 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 //Maximum V a l u e o f AutoC o r r e l a t i o n F u n c t i o n

177
Figure 9.10: PSD

4 clc ;
5 clear ;
6 disp ( Maximum V a l u e o f ACF=Rxx ( 0 ) ) ;
7 x =200* integrate ( exp ( 2 t ) , t ,0 ,1000) ;
8 disp (x , Energy i n x ( t )= ) ;

Scilab code Exa 9.11 PSD

1 // S c i l a b Code f o r Example 9 . 1 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao

178
3 // Power S p e c t r a l D e n s i t y
4 clear ;
5 clc ;
6 clear f n ;
7 fo =2;
8 n =1;
9 RC =1/(2* %pi *10^3) ;
10 w =4* %pi *10^3
11 H =1/(1+ %i * w * RC ) ;
12 disp (H , H( f ) ) ;
13 X =( abs ( H ) ) ^2;
14 for f = -5:5
15 Pxx ( n ) =25*[ delta (f - fo ) + delta ( f + fo ) ];
16 Pyy ( n ) = X * Pxx ( n ) ;
17 n = n +1;
18 end
19 disp ( Pxx , Pxx= ) ;
20 disp ( Pyy , Pyy= ) ;
21 f = -5:5;
22 plot2d3 (f , Pyy , -2) ;
23 title ( Power S p e c t r a l D e n s i t y ) ;
24 ylabel ( Pyy ( f ) ) ;
25 xlabel ( f i n Hz ) ;

179
Chapter 10

Discrete Time Convolution and


Correlation

Scilab code Exa 10.1 Cross Correlation

1 // S c i l a b Code f o r Example 1 0 . 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // C r o s s C o r r e l a t i o n
4 clear ;
5 clc ;
6 x =[2 , -1 ,1 ,0 ,2];
7 y =[0 ,1 ,0 , -1 ,2];
8 // c o m p u t a t i o n o f c r o s s c o r r e l a t i o n s e q u e n c e ;
9 n1 = max ( size ( y ) ) -1;
10 n2 = max ( size ( x ) ) -1;
11 r = xcorr (x ,y , n1 ) ;
12 n = -4:4;
13 a = gca () ;
14 a . x_location = o r i g i n ;
15 a . y_location = o r i g i n ;
16 plot2d3 (n ,r , -9) ;

180
Figure 10.1: Cross Correlation

181
Figure 10.2: Cross Correlation Sequence

17 title ( C r o s s C o r r e l a t i o n s e g u e n c e o u t p u t ) ;

Scilab code Exa 10.2 Cross Correlation Sequence

1 // S c i l a b Code f o r Example 1 0 . 2 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // C r o s s C o r r e l a t i o n
4 clear ;
5 clc ;
6 x =[4 , -2 ,2 ,0 ,4];

182
Figure 10.3: Auto Correlation

7 y =[0 ,3 ,0 , -3 ,6];
8 // c o m p u t a t i o n o f c r o s s c o r r e l a t i o n s e q u e n c e ;
9 n1 = max ( size ( y ) ) -1;
10 n2 = max ( size ( x ) ) -1;
11 r = xcorr (x ,y , n1 ) ;
12 n = -4:4;
13 a = gca () ;
14 a . x_location = o r i g i n ;
15 a . y_location = o r i g i n ;
16 plot2d3 (n ,r , -9) ;
17 title ( r x y c r o s s c o r r e l a t i o n ) ;

183
Scilab code Exa 10.4 Auto Correlation

1 // S c i l a b Code f o r Example 1 0 . 4 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // Auto C o r r e l a t i o n
4 clear ;
5 clc ;
6 x =[ -1 ,1 , -1];
7 // c o m p u t a t i o n o f a u t o c o r r e l a t i o n s e q u e n c e ;
8 r = xcorr ( x ) ;
9 n = -2:2;
10 a = gca () ;
11 a . x_location = o r i g i n ;
12 a . y_location = o r i g i n ;
13 plot2d3 (n ,r , -9) ;
14 title ( r x x a u t o c o r r e l a t i o n ) ;

Scilab code Exa 10.5 Auto Correlation

1 // S c i l a b Code f o r Example 1 0 . 5 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // Auto C o r r e l a t i o n
4 clear ;
5 clc ;
6 clear x n a ;
7 k =1;
8 a =0.8;
9 for n = -30:30;
10 x ( k ) = a ^( - n ) * u ( - n ) ;
11 k = k +1;
12 end

184
Figure 10.4: Auto Correlation

185
Figure 10.5: Auto Correlation

13 length ( x )
14 // c o m p u t a t i o n o f a u t o c o r r e l a t i o n s e q u e n c e ;
15 r = xcorr ( x ) ;
16 n = -60:60;
17 a = gca () ;
18 a . x_location = o r i g i n ;
19 a . y_location = o r i g i n ;
20 plot2d3 (n ,r , -4) ;
21 title ( r x x a u t o c o r r e l a t i o n ) ;

Scilab code Exa 10.8 Auto Correlation

186
1 // S c i l a b Code f o r Example 1 0 . 8 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 // Auto C o r r e l a t i o n
4 clear ;
5 clc ;
6 clear x n a ;
7 k =1;
8 a =0.8;
9 for n = -30:30;
10 x ( k ) = a ^( n ) * u ( n ) ;
11 k = k +1;
12 end
13 length ( x )
14 // c o m p u t a t i o n o f a u t o c o r r e l a t i o n s e q u e n c e ;
15 r = xcorr ( x ) ;
16 n = -60:60;
17 a = gca () ;
18 a . x_location = o r i g i n ;
19 a . y_location = o r i g i n ;
20 plot2d3 (n ,r , -4) ;
21 title ( r x x a u t o c o r r e l a t i o n ) ;

Scilab code Exa 10.11 System response

1 // S c i l a b Code f o r Example 1 0 . 1 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // System I d e n t i f i c a t i o n
4 // C r o s s C o r r e l a t i o n
5 clear ;
6 clc ;
7 clear x n a y h z ;

187
Figure 10.6: System response

188
8 x =[1 ,1 ,1 ,1 ,0 ,0];
9 y =[1 ,3 ,6 ,10 ,12 ,12 ,10 ,6 ,3 ,1];
10 h (1) = y (1) / x (1) ;
11 for n =2:7
12 for k =1: n -1
13 z ( k ) =( h ( k ) * x (n - k ) ) ;
14 h ( n ) =( y ( n ) - sum ( z ) ) ;
15 end
16 end
17 disp (h , h ( n ) ) ;
18 n =1:7;
19 a = gca () ;
20 a . x_location = o r i g i n ;
21 a . y_location = o r i g i n ;
22 plot2d3 (n ,h , -4) ;
23 title ( System R e s p o n s e h ( n ) ) ;

189
Chapter 11

Hilbert Transform Continuous


and Discrete

Scilab code Exa 11.1 Hilbert Transform

1 // S c i l a b Code f o r Example 1 1 . 1 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // H i l b e r t T r a n s f o r m
4 clc ;
5 clear ;
6 n =1;
7 for t = -1:0.01:1
8 xr ( n ) = sin (2* %pi * t ) ;
9 n = n +1;
10 end
11 // Computing H i l b e r t b T r a n s f o r m
12 x = hilbert ( xr ) ;
13 t = -1:0.01:1;
14 plot (t , xr ) ;

190
Figure 11.1: Hilbert Transform

191
Figure 11.2: Hilbert Transform

192
Figure 11.3: Hilbert Transform

15 title ( Given S i g n a l x ( t ) ) ;
16 xlabel ( t i m e t> ) ;
17 figure (1) ;
18 t = -1:0.1:1;
19 plot (t , imag ( x ) ) ;
20 title ( H i l b e r t T r a n s f o r m ) ;
21 xlabel ( t i m e t> ) ;

Scilab code Exa 11.2 Hilbert Transform

193
Figure 11.4: Hilbert Transform

194
1 // S c i l a b Code f o r Example 1 1 . 2 o f S i g n a l s and
s y s t e m s by
2 //P . Ramakrishna Rao
3 // H i l b e r t T r a n s f o r m
4 clc ;
5 clear ;
6 n =1;
7 for t = -1:0.01:1
8 xr ( n ) = cos (2* %pi * t ) ;
9 n = n +1;
10 end
11 // Computing H i l b e r t b T r a n s f o r m
12 x = hilbert ( xr ) ;
13 t = -1:0.01:1;
14 plot (t , xr ) ;
15 title ( Given S i g n a l x ( t ) ) ;
16 xlabel ( t i m e t> ) ;
17 figure (1) ;
18 t = -1:0.01:1;
19 plot (t , imag ( x ) ) ;
20 title ( H i l b e r t T r a n s f o r m ) ;
21 xlabel ( t i m e t> ) ;

Scilab code Exa 11.3 Hilbert Transform

1 // S c i l a b Code f o r Example 1 1 . 3 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // H i l b e r t T r a n s f o r m
4 clc ;
5 clear xr n t x1 x2 ;

195
Figure 11.5: Hilbert Transform

196
Figure 11.6: Hilbert Transform

197
6 clear ;
7 n =1;
8 for t = -1:0.01:1
9 xr ( n ) = exp ( %i *2* %pi * t ) ;
10 n = n +1;
11 end
12 // Computing H i l b e r t b T r a n s f o r m
13 x1 = hilbert ( real ( xr ) ) ;
14 x2 = hilbert ( imag ( xr ) ) ;
15 x = x1 + x2 ;
16 t = -1:0.01:1;
17 plot (t , xr ) ;
18 title ( Given S i g n a l x ( t ) ) ;
19 xlabel ( t i m e t> ) ;
20 figure (1) ;
21 t = -1:0.01:1;
22 plot (t , imag ( x ) ) ;
23 title ( H i l b e r t T r a n s f o r m ) ;
24 xlabel ( t i m e t> ) ;

Scilab code Exa 11.6 Hilbert Transform

1 // S c i l a b Code f o r Example 1 1 . 6 o f S i g n a l s and


s y s t e m s by
2 //P . Ramakrishna Rao
3 // H i l b e r t T r a n s f o r m
4 clc ;
5 clear A T t x ;
6 T =2;
7 A =1;
8 n =1;

198
Figure 11.7: Hilbert Transform

199
Figure 11.8: Hilbert Transform

200
9 for t = -10:0.01:10;
10 if t > - T /2 & t < T /2 then
11 x(n)=A;
12 n = n +1;
13 else x ( n ) =0;
14 n = n +1;
15 end
16 end
17 t = -10:0.01:10;
18 // S i g n a l x ( t )
19 plot (t , x ) ;
20 title ( Given S i g n a l x ( t ) ) ;
21 xlabel ( t i m e t> ) ;
22 // Computing H i l b e r t T r a n s f o r m
23 xr = hilbert ( x ) ;
24 xr_imag = imag ( xr ) ;
25 figure (1) ;
26 t = -10:0.01:10;
27 plot (t , xr_imag ) ;
28 title ( H i l b e r t t r a n s f o r m and a s s o c i a t e d s i g n a l ) ;
29 xlabel ( t i m e t> ) ;

201

Scilab Textbook Companion for
Signals And Systems
by P. R. Rao1
Created by
Satyam Agrawal
B.Tech
Instrumentation Engineering
Book Description
Title: Signals And Systems
Author: P. R. Rao
Publisher: TMH Education Pvt. Ltd., New Delhi
Edition: 5
Year:
Scilab numbering policy used in this document and the relation to the
above book.
Exa Example (Solved example)
Eqn Equation (
Contents
List of Scilab Codes
4
1
Signals Continuous and Discrete time
6
2
Laplace and Z Transform
28
3
Fourier Series of Con
List of Scilab Codes
Exa 1.1
Finding Fundamental Period
. . . . . . . . . . . . . .
6
Exa 1.3.a
Periodicity
. . . . . . . . .
Exa 2.39
Inverse Z Transform . . . . . . . . . . . . . . . . . . .
41
Exa 2.40
Inverse Z Transform . . . . . . . . . . . . .
Exa 7.3
System Properties . . . . . . . . . . . . . . . . . . . .
114
Exa 7.4
System Properties . . . . . . . . . . . . . . .
Exa 10.5
Auto Correlation . . . . . . . . . . . . . . . . . . . . .
178
Exa 10.8
Auto Correlation . . . . . . . . . . . . . .
List of Figures
1.1
Finding Fundamental Period . . . . . . . . . . . . . . . . . .
7
1.2
Finding Fundamental Period . . . . .
4.2
Magnitude and Phase Spectra . . . . . . . . . . . . . . . . .
58
4.3
Magnitude and Phase Spectra . . . . . . . . . . . .

You might also like