Skip to content

Instantly share code, notes, and snippets.

@serdardalgic
Created September 19, 2014 08:50
Show Gist options
  • Save serdardalgic/0f78c041ba4ee88ad8c5 to your computer and use it in GitHub Desktop.
Save serdardalgic/0f78c041ba4ee88ad8c5 to your computer and use it in GitHub Desktop.
Haypat Fourier Transformation Rewrite
#!/usr/bin/python
import sys
import cmath
from math import pi
N = 100
c01 = [0.0] * N
cN1 = [0.0] * N
c02 = [0.0] * N
cN2 = [0.0] * N
g1 = [0.0] * N
g2 = [0.0] * N
def readFile(filename):
"""
Given a filename, yields the lines of the file.
"""
with open(filename, 'r') as f:
for line in f:
yield line
def initialize_cArrays(a):
global c01, c02, cN1, cN2
if a[0] == 0:
c01[int(a[3])] = a[1]
c02[int(a[3])] = a[2]
elif a[0] == (N - 1):
cN1[int(a[3])] = a[1]
cN2[int(a[3])] = a[2]
def print_results():
for i in xrange(N-1):
print i, g1[i], g2[i], "\n\n"
if __name__ == "__main__":
global g1, g2
for line in readFile(sys.argv[1]):
a = [float(x) for x in line.strip()]
initialize_cArrays(a)
coeff = (
cmath.exp(-2j * pi / N * k * a[0]) /
(N * 100))
g1[int(a[3])] = (
g1[int(a[3])] +
(a[1] -
c01[int(a[3])] -
((a[0]-1) *
(cN1[int(a[3])] - c01[int(a[3])]) /
(N-1))) *
coeff)
g2[int(a[3])] = (
g2[int(a[3])] +
(a[2] -
c02[int(a[3])] -
((a[0]-1) *
(cN2[int(a[3])] - c02[int(a[3])]) /
(N-1))) *
coeff)
print_results()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment