-
Notifications
You must be signed in to change notification settings - Fork 0
/
fft.py
63 lines (56 loc) · 1.75 KB
/
fft.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#-------------------------------------------------------------------------------
# Name: module1
# Purpose:
#
# Author: Basilius Sauter
#
# Created: 11.05.2015
# Copyright: (c) Basilius Sauter 2015
# Licence: <your licence>
#-------------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
try:
from . import transform
except SystemError:
try:
import transform
except SystemError:
pass
class FFT:
points = []
fft = []
def __init__(self, points):
self.points = points
def getFFT(self):
return self.fft
def transform(self, bins = 37, includeFirst = True):
binWidth = 360/bins
n = len(self.points)
# Get coordinates
con_r, con_p = transform.cartesian2radian(self.points)
#con_x = np.array([i[0] for i in self.points])
#con_y = np.array([i[1] for i in self.points])
# Convert to polar coordinates
#con_r = np.sqrt(con_x**2 + con_y**2)
#con_p = np.arctan2(con_x, con_y) * (-180/np.pi) + 180
con_b = con_p//binWidth
# Prepare bin
bin_arr = [[] for i in range(0, bins)]
# Bin into bins
for i in range(0, n):
b = int(con_b[i])
bin_arr[b].append(con_r[i])
for i in range(0, bins):
if len(bin_arr[i]) > 0:
bin_arr[i] = sum(bin_arr[i])/len(bin_arr[i])
else:
bin_arr[i] = 0
# Actual Fourier-Transformation
f = (np.fft.fft(bin_arr))
if includeFirst:
self.fft = [f[0].real,]
else:
self.fft = []
for i in range(0, len(f)//2):
self.fft.append(abs(((f[i+1] + f[-(i+1)]).real)))