About... Prerequisites Examples Home Bugs Download Manual Links

Example 3


Python code that generates a function with three frequencies and then separates them whit a Lanczos filter:

    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()
    

get the code in a file





This graph has been generated by GNUPlot, using the shell script:
    #! /bin/bash
    gnuplot << EOF
    set term gif
    set output "ejemplo3.gif"
    set xrange [50:150]
    plot "ejemplo3.in.xy" w l lw 4, "ejemplo3.out.xyy" t 'lp          0.025' w l lt 3 lw 3, "ejemplo3.out.xyy" using 1:3 t 'bp 0.025-0.08' w l lt 4 lw 3, "ejemplo3.out.xyy" using 1:4 t 'hp           0.18' w l lt 7 lw 3
    EOF
    

get the script in a file



Contact the
Webmaster