Module fit_ortho
[frames] | no frames]

Source Code for Module fit_ortho

 1  #!/usr/bin/env python 
 2   
 3  """This program fits a f0 curve with a set of orthogonal 
 4  polynomials, then returns the coefficients. 
 5  Input is a single column, and zero frequency points are 
 6  given zero weight. 
 7  """ 
 8   
 9   
10  import sys 
11  import ortho_fit 
12  from gmisclib import Num 
13   
14   
15  if __name__ == '__main__': 
16          N = int(sys.argv[1]) 
17          assert N>0, "First argument is the number of Legendre polynomials." 
18           
19          wt = [] 
20          y = [] 
21          for line in sys.stdin.readlines(): 
22                  line = line.strip() 
23                  if line.startswith('#'): 
24                          continue 
25                  elif line == '': 
26                          continue 
27                  f = float(line) 
28                  y.append( f ) 
29                  if f < 1.0: 
30                          wt.append( 0.0 ) 
31                  else: 
32                          wt.append( 1.0 ) 
33   
34          n = len(y) 
35          x = 2*(Num.arrayrange(n)+0.5)/float(n) - 1 
36          y = Num.array(y) 
37   
38          soln, sumwt, svr = ortho_fit.ortho_fit(x, y, 
39                                                  wt, N, 
40                                                  name='Legendre') 
41   
42          print "Solution:" 
43          print "\tCoefficients:", ' '.join(['%g' % cc for cc in soln.c]) 
44          print "\tError:", soln.e 
45