In [38]:
# Setup
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
params = {'font.size' : 14,
'figure.figsize':(12.0, 8.0),
'lines.linewidth': 2.,
'lines.markersize': 8,}
matplotlib.rcParams.update(params)
In [41]:
import numpy as np
import matplotlib.pyplot as plt
def signal(t, f = 1.):
return np.cos(2. * np.pi * f * t)
D = 3.2 # duration
t = np.linspace(0., D, 1000)
x = signal(t)
fs = 10. # sampling rate
tn = np.linspace(0., D, fs * D)
xn = signal(tn)
plt.plot(t, x, "k-", label = "Analog")
plt.plot(tn, xn, "bo--", label = "Digital")
plt.grid()
plt.xlabel("Time, $t$")
plt.ylabel("Amplitude, $x$")
plt.legend()
plt.show()
In [42]:
t = np.linspace(0., D, 1000)
x = signal(t)
Fs = [1., 2., 10.] # sampling rate
plt.plot(t, x, "k-", label = "Analog")
for fs in Fs:
tn = np.linspace(0., D, fs * D)
xn = signal(tn)
plt.plot(tn, xn, "o--", label = "fs = {0}".format(fs))
plt.grid()
plt.xlabel("Time, $t$")
plt.ylabel("Amplitude, $x$")
plt.legend()
plt.show()
In [51]:
D = 1.5 # duration
t = np.linspace(0., D, 1000)
fs = 2.5 # sampling rate
tn = np.linspace(0., D, fs * D)
xn = signal(tn)
F = .5 + np.arange(3) * fs # sampling rate
tn = np.linspace(0., D, fs * D)
xn = signal(tn, f = F[0])
plt.plot(tn, xn, "ok", label = "Samples")
for f in F:
x = signal(t, f = f)
plt.plot(t, x, "-")
plt.grid()
plt.xlabel("Time, $t$")
plt.ylabel("Amplitude, $x$")
plt.legend()
plt.show()
In [ ]: