Purpose

The purpose of this document is to experiment with the DFT calculations from chapter 3 in the book Unterstanding digital signal processing third edition by Richard G. Lyons.

Input signal

The input signal is:


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


x(0) = 0.3536
x(1) = 0.3536
x(2) = 0.6464
x(3) = 1.0607
x(4) = 0.3536
x(5) = -1.0607
x(6) = -1.3536
x(7) = -0.3536

In [ ]: