Package gmisclib :: Module hilbert_xform
[frames] | no frames]

Source Code for Module gmisclib.hilbert_xform

 1  import Num 
 2   
 3   
4 -def nextpow2(i):
5 j = 1 6 while j <= i: 7 j *= 2 8 return j
9 10
11 -def hilbert(x, cutoff):
12 """This is a Hilbert transform when cutoff=0.""" 13 14 xx = Num.asarray(x, Num.Float) 15 np2 = nextpow2(x.shape[0]) 16 x = Num.zeros((np2,), Num.Float) 17 x[:xx.shape[0]] = xx 18 assert len(x.shape) == 1 19 n = x.shape[0] 20 xt = Num.FFT.fft(x) 21 tmp = Num.arrayrange(n) 22 f = Num.minimum(tmp, n-tmp) * (1 - 2*Num.greater(tmp, n-tmp)) 23 window = 1.0 + Num.tanh(f/cutoff) 24 Num.multiply(xt, window, xt) 25 return Num.FFT.inverse_fft(xt)
26 27 28 29 if __name__ == '__main__': 30 import gpkimgclass 31 x = gpkimgclass.read('/home/gpk/voicing/mimic.1.1.d') 32 print "0" 33 DT = 0.030 34 y = hilbert(x.d[:,0], DT/x.dt()) 35 print "F", y.shape 36 tmp = gpkimgclass.gpk_img({'CDELT2': x.dt(), 'HILBERT_CUTOFF': DT, 37 'BITPIX': -32, 38 'CRPIX2': 0, 'CRVAL2': 0.0}, 39 Num.absolute(y)) 40 tmp.write("foo.d") 41