File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change 55
55
__version__ = "0.0.0-auto.0"
56
56
__repo__ = "https://github.com/tschucker/Teaandtechtime_CircuitPython_FFT.git"
57
57
58
-
59
- def cpy_fft (x ):
58
+ def fft (x ):
60
59
N = len (x )
61
60
if N <= 1 : return x
62
- even = cpy_fft (list (islice (x ,0 ,N ,2 )))
63
- odd = cpy_fft (list (islice (x ,1 ,N ,2 )))
61
+ even = fft (list (islice (x ,0 ,N ,2 )))
62
+ odd = fft (list (islice (x ,1 ,N ,2 )))
64
63
T = [cos (2 * pi * k / N )* odd [k ].real + sin (2 * pi * k / N )* odd [k ].imag + (cos (2 * pi * k / N )* odd [k ].imag - sin (2 * pi * k / N )* odd [k ].real )* 1j for k in range (N // 2 )]
65
64
return [even [k ].real + T [k ].real + (even [k ].imag + T [k ].imag )* 1j for k in range (N // 2 )] + \
66
65
[even [k ].real - T [k ].real + (even [k ].imag - T [k ].imag )* 1j for k in range (N // 2 )]
67
66
68
- def cpy_abs (x ):
67
+ def cmplx_abs (x ):
69
68
return sqrt (pow (x .real ,2 ) + pow (x .imag ,2 ))
70
69
71
- def spectro (x ):
72
- freq = cpy_fft (x )
70
+ def spectrogram (x ):
71
+ freq = fft (x )
73
72
temp_list = []
74
73
for f in freq :
75
- abs_val = cpy_abs (f )
74
+ abs_val = cmplx_abs (f )
76
75
if abs_val != 0.0 :
77
76
temp_list .append (int (log (abs_val )))
78
77
else :
79
78
temp_list .append (0 )
80
-
81
79
return temp_list
80
+
81
+ def ifft (x ):
82
+ for s in x :
83
+ s = (s .imag + s .real * 1j )
84
+ temp = fft (x )
85
+ for s in temp :
86
+ s = (s .imag + s .real * 1j )/ float (len (x ))
87
+ return temp
88
+
You can’t perform that action at this time.
0 commit comments