import matplotlib.pyplot as plt
import numpy as np
import seaborn
seaborn.set(style='ticks',rc={'figure.figsize':(9,5)})
(a)
def dtmf(t_):
tone1 = np.sin(2*np.pi*697*t_)
tone2 = np.sin(2*np.pi*1209*t_)
return(tone1+tone2)
n = 2500
t = np.linspace(0,0.25,n)
plt.xlim(0,0.25)
plt.plot(t,dtmf(t),'blue',lw=1)
plt.show()
plt.xlim(0,0.02)
plt.plot(t,dtmf(t),'blue',lw=1)
plt.show()
(b)
D = np.zeros([n,n])
f = np.zeros([n])
for i in range(n):
for j in range(n):
if (i==0): D[i][j]=np.sqrt(1/n)
else: D[i][j]=np.sqrt(2/n)*np.cos(np.pi*(2*j+1)*i/2/n)
f = np.dot(D,time_series)
plt.xlim(0,0.25)
plt.plot(t,f,'blue',lw=1)
plt.show()
(c)
time_series_rev = np.dot(np.linalg.inv(D),f)
plt.xlim(0,0.02)
plt.plot(t,time_series_rev,'blue',lw=1)
plt.show()
(d)
m = int(n*0.05)
t_samp = 0.25*np.sort(np.random.choice(n, m))/n
dtmf_samp = dtmf(t_samp)
fig, ax=plt.subplots()
plt.xlim(0.02,0.04)
plt.plot(t,dtmf(t),'black',lw=1,alpha=0.5)
ax = plt.scatter(t_samp,dtmf_samp,50,'red')