mirror of
https://github.com/mborgerding/kissfft.git
synced 2025-06-04 01:28:23 -04:00
working towards mixed radix
This commit is contained in:
parent
1330c4b3d4
commit
a2cca1b70e
49
fft.py
49
fft.py
@ -1,26 +1,37 @@
|
|||||||
#!/usr/local/bin/python2.3
|
#!/usr/local/bin/python2.3
|
||||||
import math
|
import math
|
||||||
|
pi=math.pi
|
||||||
|
e=math.e
|
||||||
|
j=complex(0,1)
|
||||||
|
|
||||||
def T(n,i):
|
def T(n,k):
|
||||||
return math.e ** complex( 0,-2*math.pi*i/n )
|
return e ** -2*j*pi*k/n
|
||||||
|
|
||||||
def fft(f):
|
def fft(f):
|
||||||
n=len(f)
|
n=len(f)
|
||||||
if n%2 == 0:
|
if n==1:
|
||||||
np = n/2
|
return f
|
||||||
fe=[0 ] * np
|
|
||||||
fo=[0 ] * np
|
for p in 4,3,2,5:
|
||||||
for i in range(np):
|
if n%p==0:
|
||||||
fe[i] = f[i] + f[i+np]
|
break
|
||||||
fo[i] = (f[i] - f[i+np]) * T(n,i)
|
else:
|
||||||
Fe=fft(fe)
|
raise Exception('%s not factorable ' % n)
|
||||||
Fo=fft(fo)
|
m = n/p
|
||||||
F=[0 ] * n
|
|
||||||
F[::2] = Fe
|
Fm=[]
|
||||||
F[1::2] = Fo
|
for q in range(p): # 0,1
|
||||||
elif n==1:
|
fp = f[q::p]
|
||||||
F=f
|
Fp = fft( fp )
|
||||||
else:
|
Fm.extend( Fp )
|
||||||
raise exceptions.Exception('cannot factor %d by 2' % n)
|
|
||||||
return F
|
Fout=[0]*n
|
||||||
|
for k in range(n):
|
||||||
|
val = 0
|
||||||
|
for q in range(p):
|
||||||
|
t = e ** ( -j*2*pi*k*q/n )
|
||||||
|
val += Fm[ q*m + (k%m) ] * t
|
||||||
|
Fout[k] = val
|
||||||
|
|
||||||
|
return Fout
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user