Examples of the aliasing effect when sampling signals

Example 1 - Two sinusoids giving the same sampled signal


In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import Math


/home/kjartan/anaconda2/lib/python2.7/site-packages/matplotlib/__init__.py:872: UserWarning: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(self.msg_depr % (key, alt_key))

In [2]:
h = 0.001 # Sampling time
ws = 2*np.pi/h
wN = ws/2
w1 = 1800*np.pi
w1Alias = np.abs( (w1+wN) % ws - wN)  # 200*np.pi
print w1Alias

T = 2*np.pi/w1 # Period of sinusoid

t = np.linspace(0,7.6*T, 600)
y1 = np.sin(w1*t)
ya = -np.sin(w1Alias*t)

ts = np.arange(9)*h
y1Sampled = np.sin(w1*ts)
yaSampled = -np.sin(w1Alias*ts)

plt.figure(figsize=(14,6))
plt.plot(t, y1, linewidth=2)
plt.plot(t, ya)
plt.plot(ts, y1Sampled, 'bo', markersize=10)
plt.stem(ts, yaSampled, linefmt='r--', markerfmt='ro', basefmt = 'r-')
plt.xlabel('t [seconds]')

plt.show()


628.318530718

Example 2 - The alias of a high frequency signal cancels a low frequency signal


In [3]:
plt.savefig('aliasing-example.pdf')


<matplotlib.figure.Figure at 0x7eff4c688f90>

In [ ]:
y3 = np.sin(w1*t) + np.sin(w1Alias*t)
y3Sampled = np.sin(w1*ts) + np.sin(w1Alias*ts)

plt.figure(figsize=(14,6))
plt.plot(t, y3, linewidth=2)
plt.stem(ts, y3Sampled, linefmt='r--', markerfmt='ro', basefmt = 'r-')
plt.xlabel('t [seconds]')

In [ ]: