In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from IPython.display import Math
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()
In [3]:
plt.savefig('aliasing-example.pdf')
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 [ ]: