In [34]:
import numpy as np
from numpy import sin, cos
import matplotlib.pyplot as plt
from math import pi
def s1(t):
return sin(2 * pi * 1000. * t)
def s2(t):
return 0.5 * sin(2 * pi * 2000. * t + 3 * pi / 4)
def s(t):
return s1(t) + s2(t)
t = np.arange(0., 10./10000, 1./1000000)
plt.plot(t, s1(t), t, s2(t), t, s(t))
plt.show()
The digitalized signal assumes a sampling frequency fs.
In [52]:
def x(fs, n):
return s(n/fs)
def x8000(n):
return(x(8000, n))
n = np.arange(0, 8, 1)
plt.plot(n, x8000(n), 'o')
plt.show()
print('\n'.join('x({}) = {:.4f}'.format(i, x8000(i)) for i in range(8)))
In [ ]: