Unit step signal :

The unit step signal is denoted as $ u[n] $ and is defined as $$ u[n] = \begin{cases} 1 & \mbox{for $n \ge 0$} \\ 0 & \mbox{for $n < 0$} \end{cases} $$

Let’s implement unit step signal by python code

In [1]:
#Code written by: Al Mamun Siddiki
#Roll no: SH-81

import numpy as np 
import matplotlib.pyplot as plt

n = range(-2, 6, 1)
y = []
for i in range(len(n)):
    temp = (1 if n[i]>=0 else 0)
    y.append(temp)
    
print(n)
print(y)

#plotting the graph
plt.stem(n, y)
plt.axis([-2.1, 5.1, -0.1, 1.2])
plt.show()
range(-2, 6)
[0, 0, 1, 1, 1, 1, 1, 1]

Unit ramp signal :

The unit ramp signal is denoted as $ u_r[n] $ and defined as $$ u_r[n] = \begin{cases} n & \mbox{for $n \ge 0$} \\ 0 & \mbox{for $n < 0$} \end{cases} $$

Let’s implement unit ramp signal by python code.

In [2]:
n = range(-2, 6, 1)
y = []
for i in range(len(n)):
    temp = (n[i] if n[i]>=0 else 0)
    y.append(temp)
    
print(list(n))
print(y)

#Plotting the graph
plt.stem(n, y)
plt.axis([-2.1, 5.1, -0.1, 5.2])
plt.xlabel('  n--->  ')
plt.ylabel('Amplitude ----> ')
plt.title('Unit ramp Signal')
plt.grid(True)
plt.show()
[-2, -1, 0, 1, 2, 3, 4, 5]
[0, 0, 0, 1, 2, 3, 4, 5]

Exponential signal :

The exponential signal is a sequence of the form $$ y[n] = a^n \quad for \quad all \quad n $$

Let’s implement exponential signal by python code.

In [3]:
a = 0.9
n = range(0, 26, 1)
y = []

for i in range(len(n)):
    temp = a**n[i]
    y.append(temp)
    

#Plotting the graph
plt.stem(y)
plt.axis([-0.3, 25.1, -0.1, 1.1])
plt.xlabel('  n--->  ')
plt.ylabel('Amplitude ----> ')
plt.title('Exponential signal for 0 < a < 1')
plt.grid(True)
plt.show()
In [ ]: