0% found this document useful (0 votes)
11 views7 pages

Exp 5 Python

Uploaded by

jappisardar1
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)
11 views7 pages

Exp 5 Python

Uploaded by

jappisardar1
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
You are on page 1/ 7

9/30/22, 10:27 AM Exp5Python

EXPERIMENT-5
AIM- Writiing Python codes for generating various signal operation.

In [1]:

import matplotlib.pyplot as plt


import numpy as np
t = np.arange(0,2,0.01)
x1 = np.sin(6*(np.pi)*t)
plt.figure(figsize = (8,2))
plt.plot(t,x1, label = 'sin(6pit)');
plt.ylabel('x1(t) = sin(6pit)')
plt.title('Abhay Sharma 19102086 A2');
plt.legend();
plt.xlabel('t');
plt.show()

In [2]:

import matplotlib.pyplot as plt


import numpy as np
t = np.arange(0,2,0.01)
x2 = 2*(np.cos(3*(np.pi)*t + (np.pi)/4 ));
plt.figure(figsize = (8,2))
plt.plot(t,x2, label = '2cos(3pit + pi/4)');
plt.ylabel('x2(t) = 2cos(3pit + pi/4)');
plt.title('Abhay Sharma 19102086 A2');
plt.legend();
plt.xlabel('t');
plt.show()

file:///C:/Users/Dell/Downloads/Exp5Python.html 1/7
9/30/22, 10:27 AM Exp5Python

In [3]:

import matplotlib.pyplot as plt


import numpy as np
t = np.arange(-2,6,0.01)
x3 = 3*np.exp(0.5*t);
x4 = np.exp(-0.9*t);

plt.figure(figsize = (8,2))
plt.plot(t,x3, label = '3*np.exp(0.5*t)');
plt.plot(t,x4, label = 'np.exp(-0.9*t)');
plt.ylabel('Exponential signal')
plt.title('Abhay Sharma 19102086 A2');
plt.legend();
plt.xlabel('t');
plt.show()

In [5]:

import matplotlib.pyplot as plt


import numpy as np
n= np.arange(-12, 13)
g=5*(n<=0)+(5-3*n)*((4>=n)*(n>0)) + (-23+pow(n, 2)) * ((8>=n)*(n>4)) + 41*(n>8)
plt.figure(figsize = (8,2))
plt.stem(n, g, use_line_collection=True);
plt.xlabel('n');
plt.ylabel('g[n]')
plt.title('Abhay Sharma 19102086 A2')
plt.legend();
plt.show()

WARNING:matplotlib.legend:No handles with labels found to put in legend.

file:///C:/Users/Dell/Downloads/Exp5Python.html 2/7
9/30/22, 10:27 AM Exp5Python

In [6]:

import matplotlib.pyplot as plt


import numpy as np
t=np.arange(-1, 3, 0.05)
x1 = np.sin(6*(np.pi)*t);
x2 = 2*(np.cos(3*(np.pi)*t + (np.pi)/4 ));
x5=x1+x2;
plt.figure(figsize=(8,2));
plt.ylabel('addition of two signals');
plt.xlabel('t')
plt.title('Abhay Sharma 19102086 A2')
plt.plot(t, x5);
plt.show();

file:///C:/Users/Dell/Downloads/Exp5Python.html 3/7
9/30/22, 10:27 AM Exp5Python

In [7]:

import matplotlib.pyplot as plt


import numpy as np
def x3(t):
return 3*np.exp(0.5*t)
t=np.arange(-2, 3, 0.05)
plt.plot(t, x3(t), label='x3(t)')
x3_even=0.5*(x3(t)+x3(-t));
x3_odd=0.5*(x3(t)-x3(-t));
plt.plot(t, x3_even, label='Even signal of x3(t)')
plt.plot(t, x3_odd, label='Odd signal of x3(t)')
plt.plot(t, x3_even+x3_odd, 'r*', label = 'reconstructed x3(t)')
plt.ylabel('Even and odd decomposition of a signal and its reconstruction ')
plt.xlabel(''); plt.title('Abhay Sharma 19102086 A2')
plt.legend(); plt.show();

file:///C:/Users/Dell/Downloads/Exp5Python.html 4/7
9/30/22, 10:27 AM Exp5Python

In [8]:

import matplotlib.pyplot as plt


import numpy as np
t=np.arange(0,7,0.001)
x1=20*np.e**(-2*(t))*(t<=2)*(t>=0)
x2=-10*(t==2)
x3=10*(t-3)*(t<=3)*(t>=2)
x4=20*(t==3)
x5=-10*(t-5)*(t<=5)*(t>=3)
x6=-20*(t==5)
x7=10*(t-7)*(t<=7)*(t>=5)
plt.figure(figsize=(14,10))
plt.title('Abhay Sharma 19102086 A2')
plt.xlabel("t(s)")
plt.ylabel("v(t)")
plt.plot(t,x1,"red")
plt.plot(t,x2,"green")
plt.plot(t,x3,"blue")
plt.plot(t,x4,"orange")
plt.plot(t,x5,"violet")
plt.plot(t,x6,"red")
plt.plot(t,x7,"blue")
plt.show()

file:///C:/Users/Dell/Downloads/Exp5Python.html 5/7
9/30/22, 10:27 AM Exp5Python

In [10]:

import matplotlib.pyplot as plt


import numpy as np
t= np.arange(-1,1,.01)
v=t*np.exp(-t)
plt.figure(figsize=(9,3))
plt.subplot(221)
plt.ylabel('v(t)')
plt.title('Abhay Sharma 19102086 A2')
plt.plot(t,v)
plt.subplot(222)
plt.title('Abhay Sharma 19102086 A2')
plt.ylabel('v(-t)')
plt.plot(-t,v)
plt.xlabel('t')
plt.show()

In [12]:

import matplotlib.pyplot as plt


import numpy as np
t= np.arange(-1,1,.01)
v=t*np.exp(-t)
plt.figure(figsize=(9,3))
plt.subplot(221)
plt.ylabel('v(t)')
plt.title('Abhay Sharma 19102086 A2')
plt.plot(t,v)
plt.grid()
plt.subplot(222)
plt.title('Abhay Sharma 19102086 A2')
plt.ylabel('3v(t+3)')
plt.plot(t-3/3,v)
plt.xlabel('t')
plt.grid()
plt.show()

file:///C:/Users/Dell/Downloads/Exp5Python.html 6/7
9/30/22, 10:27 AM Exp5Python

In [14]:

import matplotlib.pyplot as plt


import numpy as np
t= np.arange(-1,3,.01)
v=t*np.exp(-t)
plt.figure(figsize=(9,3))
plt.subplot(221)
plt.ylabel('v(t)')
plt.title('Abhay Sharma 19102086 A2')
plt.plot(t,v)
plt.grid()
plt.subplot(222)
plt.title('Abhay Sharma 19102086 A2')
plt.ylabel('v(4t)')
plt.plot(t/4,v)
plt.xlabel('t')
plt.grid()
plt.show()

In [16]:

import matplotlib.pyplot as plt


import numpy as np
t= np.arange(-1,1,.01)
v=t*np.exp(-t)
plt.figure(figsize=(9,3))
plt.subplot(221)
plt.ylabel('v(t)')
plt.title('Abhay Sharma 19102086 A2')
plt.plot(t,v)
plt.grid()
plt.subplot(222)
plt.title('Abhay Sharma 19102086 A2')
plt.ylabel('-2v(t-1)')
plt.plot(t+1/2,v)
plt.xlabel('t')
plt.grid()
plt.show()

file:///C:/Users/Dell/Downloads/Exp5Python.html 7/7

You might also like