0% found this document useful (0 votes)
8 views8 pages

Basic Python 409

The document provides a series of Python code snippets that demonstrate the creation and visualization of various signals using NumPy and Matplotlib. It covers continuous-time and discrete-time signals, unit step and impulse signals, signal scaling, time reversal, and the decomposition of signals into even and odd components. Additionally, it illustrates the concept of convolution with examples of input signals and their corresponding outputs.
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)
8 views8 pages

Basic Python 409

The document provides a series of Python code snippets that demonstrate the creation and visualization of various signals using NumPy and Matplotlib. It covers continuous-time and discrete-time signals, unit step and impulse signals, signal scaling, time reversal, and the decomposition of signals into even and odd components. Additionally, it illustrates the concept of convolution with examples of input signals and their corresponding outputs.
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

3/2/26, 2:26 PM basic python_409

In [3]: import numpy as np


import [Link] as plt
t=[Link](-1,1,1000)
x=[Link](2*[Link]*t)
[Link](t,x)
[Link]("continuous-time sine signal")
[Link]("time(t)")
[Link]("amplitude")
[Link](True)
[Link]()

In [7]: n=[Link](-10,11)
x_d=[Link](0.25*[Link]*n)
[Link](n,x_d)
[Link]("discrete-time signal")
[Link]("n")
[Link]("amplitude")
[Link](True)
[Link]()

[Link] python_409 (1).html 1/8


3/2/26, 2:26 PM basic python_409

In [9]: u=[Link](n>=0,1,0)
[Link](n,u)
[Link]("unit step signal")
[Link](True)
[Link]()

[Link] python_409 (1).html 2/8


3/2/26, 2:26 PM basic python_409

In [11]: delta=[Link](n==0,1,0)
[Link](n,delta)
[Link]("unit impulse signal")
[Link](True)
[Link]()

In [13]: x_scaled=2*x_d
[Link](n,x_scaled)
[Link]("amplitude scaled signal(2x[n])")
[Link](True)
[Link]()

[Link] python_409 (1).html 3/8


3/2/26, 2:26 PM basic python_409

In [15]: x_reverse=x_d[::-1]
[Link](n,x_reverse)
[Link]("time reversed signal")
[Link](True)
[Link]()

[Link] python_409 (1).html 4/8


3/2/26, 2:26 PM basic python_409

In [17]: x_even=(x_d+x_reverse)/2
x_odd=(x_d-x_reverse)/2
[Link](2,1,1)
[Link](n,x_even)
[Link]("even component")
[Link](True)
[Link](2,1,2)
[Link](n,x_odd)
[Link]("odd component")
[Link](True)
plt.tight_layout()
[Link]()

In [19]: import numpy as np


import [Link] as plt
t=[Link](-5,5,1000)
x=[Link]([Link](t)<=1,1,0)
shift=2
x_right=[Link]([Link](t-shift)<=1,1,0)
x_left=[Link]([Link](t+shift)<=1,1,0)
[Link](figsize=(8,8))
[Link](3,1,1)
[Link](t,x)
[Link]("original rectangular signal x(t)")
[Link]("time(t)")
[Link]("amplitude")
[Link](True)
[Link](3,1,2)
[Link](t,x_right)
[Link]("right shifted signal x(t-2)")
[Link]("time(t)")
[Link]("amplitude")
[Link](True)

[Link] python_409 (1).html 5/8


3/2/26, 2:26 PM basic python_409

[Link](3,1,3)
[Link](t,x_left)
[Link]("left shifted signal x(t+2)")
[Link]("time(t)")
[Link]("amplitude")
[Link](True)
plt.tight_layout()
[Link]()

In [21]: x=[Link]([1,2,3,4])
h=[Link]([1,1])
y=[Link](x,h)
print("the convolution of x and h is :")
print(y)
[Link](y)
[Link]("output of system using covolution")
[Link](True)
[Link]()

the convolution of x and h is :


[1 3 5 7 4]

[Link] python_409 (1).html 6/8


3/2/26, 2:26 PM basic python_409

In [23]: x=[Link]([1,2,1])
h=[Link]([1,1,1])
y=[Link](x,h)
n_y=[Link](0,len(y))
[Link](figsize=(10,5))
[Link](3,1,1)
[Link]([Link](len(x)),x)
[Link]("input signal x[n]")
[Link](True)
[Link](3,1,2)
[Link]([Link](len(h)),h)
[Link]("impluse response h[n]")
[Link](True)
[Link](3,1,3)
[Link](n_y,y)
[Link]("covolution output y[n]=x[n]*h[n]")
[Link](True)
plt.tight_layout()
[Link]()

[Link] python_409 (1).html 7/8


3/2/26, 2:26 PM basic python_409

In [ ]:

[Link] python_409 (1).html 8/8

You might also like