# Generating Basic Discrete Time Signals

• Difficulty Level : Easy
• Last Updated : 02 Sep, 2020

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

 `# importing libraries ` `import` `numpy as np ` `import` `matplotlib.pyplot as plt ` ` `  `# function to generate unit step u[n-a] ` `# LL and UL are lower and upper limits of discrete time line ` `def` `unit_step(a, n): ` `    ``unit ``=``[] ` `    ``for` `sample ``in` `n: ` `        ``if` `sample= 0, r(n)= 0 otherwise ` `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"``) ` ` `  `# Function to generate exponential signals e**(at) ` `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.yticks([0, UL, 1]) ` `plt.ylabel(``'x[n]'``) ` `plt.title(``'Exponential Signal e**(an)'``) ` `plt.savefig(``"Exponential.png"``) `

My Personal Notes arrow_drop_up
Recommended Articles
Page :