mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-05-27 21:20:27 -04:00
python code for prototyping
This commit is contained in:
parent
502211bc6a
commit
1330c4b3d4
26
fft.py
Normal file
26
fft.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/local/bin/python2.3
|
||||
import math
|
||||
|
||||
def T(n,i):
|
||||
return math.e ** complex( 0,-2*math.pi*i/n )
|
||||
|
||||
def fft(f):
|
||||
n=len(f)
|
||||
if n%2 == 0:
|
||||
np = n/2
|
||||
fe=[0 ] * np
|
||||
fo=[0 ] * np
|
||||
for i in range(np):
|
||||
fe[i] = f[i] + f[i+np]
|
||||
fo[i] = (f[i] - f[i+np]) * T(n,i)
|
||||
Fe=fft(fe)
|
||||
Fo=fft(fo)
|
||||
F=[0 ] * n
|
||||
F[::2] = Fe
|
||||
F[1::2] = Fo
|
||||
elif n==1:
|
||||
F=f
|
||||
else:
|
||||
raise exceptions.Exception('cannot factor %d by 2' % n)
|
||||
return F
|
||||
|
Loading…
Reference in New Issue
Block a user