def test_phasez_1(self):
     # Testcase for return radian form
     fil = FIRDesign.fir1(self.order, self.cut)
     w, h = signal.freqz(fil[0], fil[1], worN=512, fs=2 * np.pi)
     phase = sp.unwrap(sp.angle(h))
     ww, pp = FilterSpec.phasez(fil)
     self.assertTrue(np.all(w == ww) and np.all(pp == phase))
Example #2
0
 def test_grpdelay_1(self):
     # Test case for FIR filter
     fil = FIRDesign.fir1(self.order, self.cut)
     w, gd = signal.group_delay(fil, w=512, fs=2 * np.pi)
     gd = np.round(gd)
     ww, gdgd = FilterSpec.grpdelay(fil)
     self.assertTrue(np.all(w == ww) and np.all(gd == gdgd))
Example #3
0
 def test_freqz_3(self):
     # Testcase for return real form
     fil = FIRDesign.fir1(self.order, self.cut)
     w1, h1 = FilterSpec.freqz(fil, outform='abs')
     w2, h2 = signal.freqz(fil[0], fil[1], worN=512, fs=2*np.pi)
     h2 = np.abs(h2)
     self.assertTrue(np.all(w1 == w2) and np.all(h1 == h2))
Example #4
0
 def test_fir1_5(self):
     # Test for DC-0 filter with hamming window.
     FIR = FIRDesign.fir1(self.n, [self.f1, self.f2, self.f3, self.f4])
     fir = signal.firwin(self.n + 1, [self.f1, self.f2, self.f3, self.f4],
                         window='hamming',
                         pass_zero=False,
                         scale=True)
     self.assertTrue(np.all(FIR[0] == fir))
Example #5
0
 def test_fir1_4(self):
     # Test for bandstop filter with hamming window.
     FIR = FIRDesign.fir1(self.n, [self.f1, self.f2], ftype='stop')
     fir = signal.firwin(self.n + 1, [self.f1, self.f2],
                         window='hamming',
                         pass_zero=True,
                         scale=True)
     self.assertTrue(np.all(FIR[0] == fir))
Example #6
0
 def test_impz_2(self):
     # Test case for FIR filter with n
     fil = FIRDesign.fir1(self.order, self.cut)
     T = np.arange(0, self.n, 1)
     x = np.zeros(len(T))
     x[0] = 1
     yout = signal.lfilter(fil[0], fil[1], x)
     tt, y = FilterSpec.impz(fil, n=self.n)
     self.assertTrue(np.all(tt == T) and np.all(y == yout))
Example #7
0
 def test_fir1_2(self):
     # Test for highpass filter with hamming window.
     FIR = FIRDesign.fir1(self.n, self.f1, ftype='high')
     fir = signal.firwin(self.n + 1,
                         self.f1,
                         window='hamming',
                         pass_zero=False,
                         scale=True)
     self.assertTrue(np.all(FIR[0] == fir))
Example #8
0
 def test_fir1_1(self):
     # Test for lowpass filter with hamming window.
     FIR = FIRDesign.fir1(self.n, self.f1)
     fir = signal.firwin(self.n + 1,
                         self.f1,
                         window='hamming',
                         pass_zero=True,
                         scale=True)
     self.assertTrue(np.all(FIR[0] == fir))
Example #9
0
 def test_freqz_1(self):
     # Testcase for return complex form
     fil = FIRDesign.fir1(self.order, self.cut)
     w1, h1 = FilterSpec.freqz(fil)
     w2, h2 = signal.freqz(fil[0], fil[1], worN=512, fs=2*np.pi)
     self.assertTrue(np.all(w1 == w2) and np.all(h1 == h2))
Example #10
0
 def test_fir1_10(self):
     # test for exception 4
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, [self.f1, self.f2, self.f3, self.f4],
                        ftype='high')
Example #11
0
 def test_fir1_9(self):
     # Test for exception 3
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, [self.f1, self.f2], ftype='low')
Example #12
0
 def test_fir1_8(self):
     # Test for exception 2
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, self.f1, ftype='stop')
Example #13
0
 def test_fir1_7(self):
     # Test for Exception 1
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, self.f1, ftype='x')
Example #14
0
 def test_isminphase_1(self):
     # Test case
     fil = FIRDesign.fir1(self.order, self.cut)
     self.assertTrue(FilterSpec.isminphase(fil) == False)
 def test_isstable_1(self):
     # Test case for FIR filter
     fil = FIRDesign.fir1(self.order, self.cut)
     self.assertTrue(FilterSpec.isstable(fil) == True)
Example #16
0
 def test_freqz_5(self):
     # Test case for exception
     with self.assertRaises(ValueError):
         fil = FIRDesign.fir1(self.order, self.cut)
         FilterSpec.freqz(fil, outform='x')
Example #17
0
 def test_impz_1(self):
     # Test case for FIR filter without n
     fil = FIRDesign.fir1(self.order, self.cut)
     _, yout = FilterSpec.impz(fil)
     self.assertTrue(np.all(yout == fil[0]))