Chapter2 : Introduction to signals

Page no 17 Prob 2.1 b

In [1]:
from mpmath import quad

t0=-1
t1=1
y=quad(lambda t:t**2,[t0,t1])
print 'power of signal: %0.3f'%(y/2),"Watt"
power of signal: 0.333 Watt

page no.26 Exa no.2.3b

In [2]:
%matplotlib inline
from matplotlib.pyplot import plot,subplot,show,title

from numpy import arange

t=arange(-3,1.0082,.0082)
m1=(0-1)/(-3-(-1))##slope for -3<t<-1
c1=(0-m1*(-3))##intercept for pt(-3,0)
u=[]
for tt in t:
    if tt<=-1:
        u.append(((m1*tt)+c1))
    else:
        break
m2=(1-0)/(-1-1)##slope for -1<t<1
c2=(0-m2*1)#intercept for pt(1,0)

for tt in t:
    if tt>-1:
        u.append(((m2*tt)+c2))
subplot(221)
plot(t,u)
title('original signal')
subplot(222)
plot([2*tt for tt in t],u)
title('expansion of signal')
show()

Page27 Problem 2.4

In [3]:
from math import exp
%matplotlib inline
from matplotlib.pyplot import plot,subplot,show,title,xlabel,ylabel

t=range(-5,0)#
y=[]
for tt in t:y.append(exp(tt/2))
subplot(221)
plot(t,y)
title ( " Original signal " )
xlabel( " Time ")
ylabel("g(t) " )
show()
t_inv=[]
for tt in t:t_inv.append(-tt)
y=[]    
for tt in t_inv:y.append(exp(-tt/2))    
subplot(222)
plot(t,y)#
title ( " Time inverted signal")
xlabel( " time ")
ylabel("g(-t)" )
show()

Page no 33 Exa 2.5a

In [4]:
from numpy import arange,pi
from mpmath import quad,sin

#Assuming SI units for all quantities

#approximation of square signal to sine signal with minimum energy
t=arange(0,2*pi+.1,0.1)
t0=0#
t1=2*pi#
y=quad(lambda t:(sin(t))**2,[t0,t1])
print 'energy of sine signal= %.2f Joule'%y
#to calculate value of c
t2=0#
t3=pi#
g=quad(lambda t:sin(t),[t2,t3])
t4=pi#
t5=2*pi#
h=quad(lambda t:-sin(t),[t4,t5])
print "value of c= %0.2f "%((g+h)/pi)
energy of sine signal= 3.14 Joule
value of c= 1.27 

Page no 33 Exa 2.6a

In [5]:
from __future__ import division
from numpy import arange,pi,sqrt
from mpmath import quad,sin
#Assuming SI units for all quantities
#given signal is x(t)=1
#energy of signal x(t)
t0=0#
t1=5
x=1
y=quad(lambda t:x**2,[t0,t1])
print 'energy of signal x(t)=%.2f J'%y
#to find correlation coefficient we have to calculate the energies of different given signals
#1st signal g1(t)=1
g1=1
e1=quad(lambda t:g1**2,[t0,t1])
print 'energy of signal=%.2f J'%e1
#correltion coefficient 
c1=quad(lambda t:g1*x,[t0,t1])
print 'correlation coefficient=%.f'%(c1/sqrt(y*e1))
energy of signal x(t)=5.00 J
energy of signal=5.00 J
correlation coefficient=1

Page no 33 Exa 2.6b

In [6]:
from __future__ import division
from numpy import arange,pi,sqrt
from mpmath import quad,sin

#Assuming SI units for all quantities
#given signal is x(t)=1
#energy of signal x(t)
t0=0#
t1=5
x=1
y=quad(lambda t:x**2,[t0,t1])
print 'energy of signal x(t)=%.2f J'%y
#to find correlation coefficient we have to calculate the energies of different given signals
g2=.5
e2=quad(lambda t:g2**2,[t0,t1])
print 'energy of signal=%.2f J'%e2
#correltion coefficient 
c2=quad(lambda t:g2*x,[t0,t1])
print 'correlation coefficient=%.2f'%(c2/sqrt(y*e2))
energy of signal x(t)=5.00 J
energy of signal=1.25 J
correlation coefficient=1.00

Page no 33 Exa 2.6c

In [7]:
from __future__ import division
from numpy import arange,pi,sqrt
from mpmath import quad,sin

#Assuming SI units for all quantities
#given signal is x(t)=1
#energy of signal x(t)
t0=0#
t1=5
x=1
y=quad(lambda t:x**2,[t0,t1])
print 'energy of signal x(t)=%.2f J'%y
#to find correlation coefficient we have to calculate the energies of different given signals
g3=-1
e3=quad(lambda t:g3**2,[t0,t1])
print 'energy of signal=%0.2f J'%e3
#correltion coefficient 
c3=quad(lambda t:g3*x,[t0,t1])
print 'correlation coefficient=%.2f'%(c3/sqrt(y*e3))
energy of signal x(t)=5.00 J
energy of signal=5.00 J
correlation coefficient=-1.00

Page no 33 Exa 2.6d

In [8]:
from __future__ import division
from numpy import arange,pi,sqrt
from mpmath import quad,sin,exp

#Assuming SI units for all quantities
#given signal is x(t)=1
#energy of signal x(t)
t0=0#
t1=5
x=1
y=quad(lambda t:x**2,[t0,t1])
print 'energy of signal x(t)=%.2f J'%y
#to find correlation coefficient we have to calculate the energies of different given signals
e4=quad(lambda t:(exp(-t/5))**2,[t0,t1])
print 'energy of signal=%.2f J'%e4

#correltion coefficient 
c4=quad(lambda t:(exp(-t/5))*x,[t0,t1])
print 'correlation coefficient=%.2f'%(c4/sqrt(y*e4))
energy of signal x(t)=5.00 J
energy of signal=2.16 J
correlation coefficient=0.96

Page no 33 Exa 2.6e

In [9]:
from __future__ import division
from numpy import arange,pi,sqrt
from mpmath import quad,sin,exp

#Assuming  SI units for all quantities
#given signal is x(t)=1
#energy of signal x(t)
t0=0#
t1=5
x=1
y=quad(lambda t:x**2,[t0,t1])
print 'energy of signal x(t)=%.2f J'%y
#to find correlation coefficient we have to calculate the energies of different given signals
e5=quad(lambda t:(exp(-t))**2,[t0,t1])
print 'energy of signal=%.2f J'%e5
#correltion coefficient 
c5=quad(lambda t:(exp(-t))*x,[t0,t1])
print 'correlation coefficient=%.2f'%(c5/sqrt(y*e5))
energy of signal x(t)=5.00 J
energy of signal=0.50 J
correlation coefficient=0.63

Page no 33 Exa 2.6f

In [1]:
from __future__ import division
from numpy import arange,pi,sqrt
from mpmath import quad,sin,exp

#Assuming SI units for all quantities
#given signal is x(t)=1
#energy of signal x(t)
t0=0#
t1=5
x=1
y=quad(lambda t:x**2,[t0,t1])
print 'energy of signal x(t)=%.2f J'%y
#to find correlation coefficient we have to calculate the energies of different given signals
e6=quad(lambda t:(sin(2*pi*t))**2,[t0,t1])
print 'energy of signal=%.2f J'%e6
#correltion coefficient 
c6=quad(lambda t:((sin(2*pi*t))**2)*x,[t0,t1])
print 'correlation coefficient=%.2f'%(c6/sqrt(y*e6))
energy of signal x(t)=5.00 J
energy of signal=2.50 J
correlation coefficient=0.71