def check_random_odd(self):
     for n in [33,65,55]:
         f=random ((n,))
         af=sum(f,axis=0)/n
         f=f-af
         assert_almost_equal(sum(f,axis=0),0.0)
         assert_array_almost_equal(ihilbert(hilbert(f)),f)
         assert_array_almost_equal(hilbert(ihilbert(f)),f)
 def check_definition(self):
     for n in [16,17,64,127]:
         x = arange(n)*2*pi/n
         y = hilbert(sin(x))
         y1 = direct_hilbert(sin(x))
         assert_array_almost_equal (y,y1)
         assert_array_almost_equal(hilbert(sin(2*x)),
                                   direct_hilbert(sin(2*x)))
 def bench_random(self,level=5):
     print
     print ' Hilbert transform of periodic functions'
     print '========================================='
     print ' size  | optimized |    naive'
     print '-----------------------------------------'
     for size,repeat in [(100,1500),(1000,300),
                         (256,1500),
                         (512,1000),
                         (1024,500),
                         (2048,200),
                         (2048*2,100),
                         (2048*4,50),
                         ]:
         print '%6s' % size,
         sys.stdout.flush()
         x = arange (size)*2*pi/size
         if size<2000:
             f = sin(x)*cos(4*x)+exp(sin(3*x))
         else:
             f = sin(x)*cos(4*x)
         assert_array_almost_equal(hilbert(f),direct_hilbert(f))
         print '| %9.2f' % self.measure('hilbert(f)',repeat),
         sys.stdout.flush()
         print '| %9.2f' % self.measure('direct_hilbert(f)',repeat),
         sys.stdout.flush()
         print ' (secs for %s calls)' % (repeat)
 def check_tilbert_relation(self):
     for n in [16,17,64,127]:
         x = arange(n)*2*pi/n
         f = sin (x)+cos (2*x)*sin(x)
         y = hilbert(f)
         y1 = direct_hilbert(f)
         assert_array_almost_equal (y,y1)
         y2 = tilbert(f,h=10)
         assert_array_almost_equal (y,y2)
 def check_random_even(self):
     for n in [32,64,56]:
         f=random ((n,))
         af=sum(f,axis=0)/n
         f=f-af
         # zeroing Nyquist mode:
         f = diff(diff(f,1),-1)
         assert_almost_equal(sum(f,axis=0),0.0)
         assert_array_almost_equal(direct_hilbert(direct_ihilbert(f)),f)
         assert_array_almost_equal(hilbert(ihilbert(f)),f)