Generating Basic Discrete Time Signals
Generating basic discrete-time signals for Discrete-Time Signal ProcessingUnit Step, Unit Impulse, Unit Ramp, exponential signals are very commonly used signals in signal processing to perform various operations.
- Unit step signal is given by
- Unit impulse signal is given by
- Unit ramp signal is given by
- Exponential signal is given by
Examples:
Input :
Unit Step Signal u[n-2]
Output :
Input :
Unit Impulse Signal d(4)
Output :
Input :
Unit Ramp Signal
Output:
Input:
Exponential signal for a=2
Output:
Code: Python code implementation to generate the basic discrete time signals
Python3
import numpy as np
import matplotlib.pyplot as plt
def unit_step(a, n):
unit = []
for sample in n:
if sample<a:
unit.append( 0 )
else :
unit.append( 1 )
return (unit)
a = 2
UL = 10
LL = - 10
n = np.arange(LL, UL, 1 )
unit = unit_step(a, n)
plt.stem(n, unit)
plt.xlabel( 'n' )
plt.xticks(np.arange(LL, UL, 1 ))
plt.yticks([ 0 , 1 ])
plt.ylabel( 'u[n]' )
plt.title( 'Unit step u[n-a]' )
plt.savefig( 'UnitStep.png' )
def unit_impulse(a, n):
delta = []
for sample in n:
if sample = = a:
delta.append( 1 )
else :
delta.append( 0 )
return delta
a = 4
UL = 10
LL = - 10
n = np.arange(LL, UL, 1 )
d = unit_impulse(a, n)
plt.stem(n, d)
plt.xlabel( 'n' )
plt.xticks(np.arange(LL, UL, 1 ))
plt.yticks([ 0 , 1 ])
plt.ylabel( 'd[n]' )
plt.title( 'Unit Impulse d[4]' )
plt.savefig("UnitImpulse.png")
def unit_ramp(n):
ramp = []
for sample in n:
if sample< 0 :
ramp.append( 0 )
else :
ramp.append(sample)
return ramp
UL = 10
LL = - 10
n = np.arange(LL, UL, 1 )
r = unit_ramp(n)
plt.stem(n, r)
plt.xlabel( 'n' )
plt.xticks(np.arange(LL, UL, 1 ))
plt.yticks([ 0 , UL, 1 ])
plt.ylabel( 'r[n]' )
plt.title( 'Unit Ramp r[n]' )
plt.savefig("UnitRamp.png")
def exponential(a, n):
expo = []
for sample in n:
expo.append(np.exp(a * sample))
return (expo)
a = 2
UL = 1
LL = - 1
n = np.arange(LL, UL, 0.1 )
x = exponential(a, n)
plt.stem(n, x)
plt.xlabel( 'n' )
plt.xticks(np.arange(LL, UL, 0.2 ))
plt.ylabel( 'x[n]' )
plt.title( 'Exponential Signal e**(an)' )
plt.savefig("Exponential.png")
|
Time Complexity: O(n)
Auxiliary Space: O(n)
Last Updated :
13 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...