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)

Signal Processing

Scope

Signal processing today:

  • Communication,
  • Sensors,
  • Images,
  • Video,
  • ...

Analog vs. Digital signals

Analog signal

Analog signal is a continuous function of time:

$$ x : t \mapsto x(t) $$

Digital signal

Digital signal is a discrete function of time: $$ t_n = t_0 + n \times \delta t $$

$$ x_n = x(t_n) $$

Sampling rate $f_s = 1/\delta t$.

Example


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()


Digital signals

Effect of the sampling rate


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()


  • Higher sampling rate means better signal description,
  • Lower sampling rate means loss of information,

Aliasing


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 [ ]: