-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdft.py
More file actions
33 lines (22 loc) · 656 Bytes
/
dft.py
File metadata and controls
33 lines (22 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# Author Dario Clavijo 2017
import math
# Example slow DFT
# 1HZ signal over 8HZ sampling
signal = [0, 0.707, 1, 0.707, 0, -0.707, -1, -0.707]
def dft_slow(signal):
N = len(signal)
def Fk(signal, k):
Freq = 0.0
for n in range(0, N):
coef = math.exp((-2 * math.pi * k * n) / N)
Freq += signal[n] * coef
return Freq
histogram = []
for k in range(0, N):
histogram.append(Fk(signal, k))
return histogram
def nyquist_norm(histogram):
N = len(histogram)
return [histogram[n] * 2 for n in range(0, N / 2)]
print((nyquist_norm(dft_slow(signal))))