python - fast fourier transform with complex numbers from a file -


my code let user introduce array of numbers transformed fourier. want read array file . how can this? started learn python ..

import cmath scipy.fftpack import fft f=open("complex.txt","r+") c=[] line in f:     line=line.split()     if line:         line=[complex(i.replace('i','j')) in line]         c.append(line)  def omega(p, q):     return cmath.exp((2.0 * cmath.pi * 1j * q) / p)  def fft(signal):     n = len(signal)     if n == 1:         return signal     else:         feven = fft([signal[i] in xrange(0, n, 2)])         fodd = fft([signal[i] in xrange(1, n, 2)])         combined = [0] * n         m in xrange(n/2):             combined[m] = feven[m] + omega(n, -m) * fodd[m]             combined[m + n/2] = feven[m] - omega(n, -m) * fodd[m]      return combined 

it turns out (see comments above) mady's actual difficulty in calling function in python, rather in reading data file or fourier-transforming it. so:

to apply function f arguments a,b,c, say

f(a,b,c) 

and if want put result in variable called d, say

d = f(a,b,c) 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -