import numpy as np
import math
import matplotlib.pyplot as plt
import scipy as sp
a) plot a time series for the sum of two sine waves at 697 and 1209 hz, sampling at 10,000 sps for 0.25s,
t = np.arange(0, 0.25, 0.0001)
y = np.zeros(len(t))
for i in range(len(t)):
y[i] = math.sin(697*t[i]) + math.sin(1209*t[i])
plt.plot(y)
b) calculate and plot the DCT
dct = sp.fft.dct(y)
print(dct)
print(len(dct))
plt.plot(dct[0:250])
c) invert the dct and verify that it matches
idct = sp.fft.idct(dct)
plt.plot(idct)
d) randomly sample and plot a subset of 5% of the points (125)
ts = np.random.choice(t, 125)
ys = np.zeros(125)
ts.sort()
for i in range(len(ts)):
ys[i] = math.sin(697*ts[i]) + math.sin(1209*ts[i])
plt.plot(ts, ys)
plt.scatter(ts, ys)
a) generate pairs of uniform values s1,s2 with each component contained in 0,1, and plot
s1 = np.random.uniform(0, 1, 1000)
s2 = np.random.uniform(0, 1, 1000)
plt.scatter(s1, s2)
s = np.array([s1, s2])
A = np.array([[1,2],[3,1]])
x = A.dot(s)
plt.scatter(x[0],x[1])
x = x - np.mean(x)
covariance = np.cov(x)
evals, evects = np.linalg.eig(covariance)
x = evects.T.dot(x)
#plt.scatter(x[0],x[1])
x = (x.T / np.sqrt(evals)).T
plt.scatter(x[0], x[1])