Discrete Signals

By Prof. Seungchul Lee
http://iai.postech.ac.kr/
Industrial AI Lab at POSTECH

# 1. Discrete Time SignalsÂ¶

A signal $x[n]$ is a function that maps an independent variable to a dependent variable.

In this course, we will focus on discrete-time signals $x[n]$:

• Independent variable is an integer: $n \in \mathbb{Z}$
• Dependent variable is a real or complex number: $x[n] \in \mathbb{R}$ or $\mathbb{C}$

## 1.1. Plot Real SignalsÂ¶

• plot for continuous signals in Python

• stem for discrete signals in Python

$$x(t) = \sin(2\pi t)$$
InÂ [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

InÂ [2]:
t = np.linspace(0,2,200)
x = np.sin(2*np.pi*t)

# plot
plt.figure(figsize = (10,4))
plt.plot(t, x)
plt.xlim([np.min(t), np.max(t)])
plt.xlabel('t [sec]')
plt.ylabel('x(t)')
plt.show()

$$x[n] = \sin \left(\frac{2 \pi}{N}n \right)$$
InÂ [3]:
N = 20
n = np.arange(0, N)
x = np.sin(2*np.pi/N*n)

# plot
plt.figure(figsize = (10, 8))
plt.subplot(2,1,1)
plt.plot(n, x, 'o')
plt.xlim([np.min(n), np.max(n)])
plt.title('plot')

plt.subplot(2,1,2)
plt.stem(n, x)
plt.xlim([np.min(n), np.max(n)])
plt.title('stem')
plt.show()


## 1.2. Signal SoundsÂ¶

InÂ [4]:
from scipy.io import wavfile
from IPython.display import Audio


InÂ [5]:
# signal: 'ALas, Poor Yorick!'

plt.figure(figsize = (10, 4))
plt.plot(data)
plt.show()

InÂ [6]:
Audio('./data_files/hamlet.wav')

Out[6]:
$$x[n] = \cos \left(\frac{2 \pi}{N}k n \right)$$
InÂ [7]:
# cosine wave

N = 44100
n = np.arange(0, 2*N)
k = 40 # frequancy
coswave = np.cos(2*np.pi/N*k*n)

# plot
plt.figure(figsize = (10, 4))
plt.plot(n/fs, coswave)
plt.show()

InÂ [8]:
Audio(coswave, rate = fs)

Out[8]: