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"
%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()
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()
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)
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))
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))
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))
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))
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))
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))