import math
from pyclimate.LanczosFilter import *

twopi = 2. * math.pi
def f(x):
  return sin(twopi*0.01*x)+0.75*sin(twopi*0.05*x)+0.5*sin(twopi*0.2*x)

a = arrayrange(1000)  # [0 1 ... 999]
a = f(a)              # [f(0) f(1) ... f(999)]
a.shape = (1000,1)  

file = open("ejemplo3.in.xy","w")
for i in range(len(a)):
  file.write("%d %f\n"%(i, a[i,0]))
file.close()

npoints = 50
file = open("ejemplo3.out.xyy", "w")
lp = LanczosFilter('lp', 0.025, 0.025, npoints)
bp = LanczosFilter('bp', 0.025, 0.08, npoints)
hp = LanczosFilter('hp', 0.18, 0.18, npoints)
for i in range(len(a)):
  lfa = lp.getfiltered(a[i])
  bfa = bp.getfiltered(a[i])
  hfa = hp.getfiltered(a[i])
  if lfa:
    file.write("%d %f %f %f\n"%(i-npoints, lfa[0], bfa[0], hfa[0]))
file.close()

