コード例 #1
0
 def test_find_band_dc(self):
     frame_rate,T,ftest,bandwidth = 1000,1,100,20
     t = linspace(0,T,T*frame_rate)
     m = ones_like(t) + sin(2*pi*bandwidth//2)
     low,high,filtered = loudest_band(m,frame_rate,bandwidth)
     self.assertEqual(m.shape,filtered.shape)
     self.assertEqual(high,bandwidth)
     self.assertEqual(low,0)
     self.assertLess(match(filtered,m),0.1,msg="filtered signal incorrect")
コード例 #2
0
 def test_bach(self):
     start = time.time()
     low,high,filtered = loudest_band(music,frame_rate,75)
     duration = time.time() - start
     if duration > 1.0:
             print("WARNING: my analysis of bach10sec takes 0.3 s, yours took {:.3f} s".format(duration))
             print('the actual checker will fail you on this test. Passing this is extra credit.')
     self.assertEqual(music.shape,filtered.shape)        
     self.assertAlmostEqual(low/823.5,1.0,2)
     self.assertAlmostEqual(high/898.3,1.0,2)
コード例 #3
0
 def test_find_band(self):
     frame_rate,T,ftest,bandwidth = 1000,1,100,10
     m = sin(2*pi*ftest * linspace(0,T,T*frame_rate))
     low,high,filtered = loudest_band(m,frame_rate,bandwidth)
     self.assertEqual(m.shape,filtered.shape)
     self.assertLess(low,ftest,msg="low of band incorrect")
     self.assertLess(ftest,high,msg="high of band incorrect")
     self.assertEqual(bandwidth,high-low,msg="high-low must match bandwidth")
     error=match(filtered,m)
     self.assertLess(error,0.1,msg="filtered signal incorrect")
コード例 #4
0
 def test_find_energy(self):
     frame_rate, T, ftest, bandwidth = 10000, 1, 100, 10
     t = linspace(0, T, T * frame_rate)
     m = zeros_like(t)
     for a, f in [(1, 10), (1, 11), (1, 12), (2, 30)]:
         m += a * cos(2 * pi * f * t)
     low, high, filtered = loudest_band(m, frame_rate, bandwidth)
     self.assertEqual(m.shape, filtered.shape)
     self.assertLessEqual(low, 30, msg="low of band incorrect")
     self.assertLessEqual(30, high, msg="high of band incorrect")
     self.assertEqual(bandwidth, high - low)
コード例 #5
0
 def test_find_band_split(self):
     frame_rate,T,ftest,bandwidth = 10000,1,100,10
     t = linspace(0,T,T*frame_rate)
     m = sin(2*pi*ftest*t)+sin(2*pi*(ftest+0.8*bandwidth)*t)
     low,high,filtered = loudest_band(m,frame_rate,bandwidth)
     self.assertEqual(m.shape,filtered.shape)
     self.assertLessEqual(low,ftest,msg="low of band incorrect")
     self.assertLessEqual(ftest+.8*bandwidth,high,msg="high of band incorrect")
     self.assertEqual(bandwidth,high-low)
     error=match(filtered,m)
     self.assertLess(error,0.1,msg="filtered signal incorrect")