def test_kaiserord_4(self):
     # Test case for bandstop filter
     ORD = FIRDesign.kaiserord([self.f1, self.f2, self.f3, self.f4],
                               [self.m1, self.m2, self.m1], self.dev2)
     self.assertTrue((ORD[0] == 46) and np.all(ORD[1] == [0.25, 0.45])
                     and (ORD[2] == 3.3953210522614574)
                     and (ORD[3] == 'stop'))
示例#2
0
 def test_firpm_1(self):
     x = [i for i in range(len(self.f1))]
     ipf = ip.interp1d(x, self.f1)
     f1_new = ipf(np.linspace(x[0], x[-1], 2 * len(x)))
     FIR = FIRDesign.firpm(self.n1, self.f1, self.a1)
     fir = signal.remez(self.n1 + 1, f1_new, self.a1, fs=2)
     self.assertTrue(np.all(FIR[0] == fir))
 def test_kaiserord_1(self):
     # Test case for lowapass filter
     self.assertTrue(
         np.all(
             FIRDesign.kaiserord([self.f1, self.f2], [self.m1, self.m2],
                                 self.dev2) == (45, 0.25,
                                                3.3953210522614574, 'low')))
示例#4
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))
 def test_kaiserord_2(self):
     # Test case for highpass filter
     self.assertTrue(
         np.all(
             FIRDesign.kaiserord([self.f1, self.f2], [self.m2, self.m1],
                                 self.dev1) == (26, 0.25, 1.509869637041394,
                                                'high')))
示例#6
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))
示例#7
0
 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))
示例#8
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))
示例#9
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))
示例#10
0
 def test_fir2_2(self):
     # Lowpass filter
     FIR = FIRDesign.fir2(self.nlo, self.flo, self.mlo)
     fir = signal.firwin2(31,
                          self.flo,
                          self.mlo,
                          nfreqs=1024,
                          window='hamming')
     self.assertTrue(np.all(FIR[0] == fir))
示例#11
0
 def test_fir2_1(self):
     # Highpass filter with bad filter order.
     FIR = FIRDesign.fir2(self.nhi, self.fhi, self.mhi)
     fir = signal.firwin2(35,
                          self.fhi,
                          self.mhi,
                          nfreqs=1024,
                          window='hamming')
     self.assertTrue(np.all(FIR[0] == fir))
 def test_kaiserord_6(self):
     # Test case for 'DC-0' filter
     ORD = FIRDesign.kaiserord(
         [self.f1, self.f2, self.f3, self.f4, self.f5, self.f6],
         [self.m2, self.m1, self.m2, self.m1], self.dev2)
     self.assertTrue((ORD[0] == 46)
                     and np.all(ORD[1] == [0.25, 0.45, 0.6499999999999999])
                     and (ORD[2] == 3.3953210522614574)
                     and (ORD[3] == 'DC-0'))
示例#13
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))
示例#14
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))
示例#15
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))
示例#16
0
 def test_firpm_2(self):
     f2_2 = self.f2 / (self.fs / 2)
     f2_2[0] = 0
     f2_2[-1] = 1
     x = [i for i in range(len(f2_2))]
     ipf = ip.interp1d(x, f2_2)
     f2_new = ipf(np.linspace(x[0], x[-1], 2 * len(x)))
     x_w = [i for i in range(len(self.w))]
     ipw = ip.interp1d(x_w, self.w)
     w_new = ipw(np.linspace(x_w[0], x_w[-1], 2 * len(x_w)))
     FIR = FIRDesign.firpm(self.n2, f2_2, self.a2, self.w)
     fir = signal.remez(self.n2 + 1, f2_new, self.a2, w_new, fs=2)
     self.assertTrue(np.all(FIR[0] == fir))
示例#17
0
 def test_fir2_3(self):
     # Arbitrary Magnitude filter
     F1 = np.arange(0, 0.181, 0.01)
     A1 = 0.5 + np.sin(2 * np.pi * 7.5 * F1) / 4
     F2 = [0.2, 0.38, 0.4, 0.55, 0.562, 0.585, 0.6, 0.78]
     A2 = [0.5, 2.3, 1, 1, -0.2, -0.2, 1, 1]
     F3 = np.arange(0.79, 1.01, 0.01)
     A3 = 0.2 + 18 * (1 - F3)**2
     FA = np.hstack((F1, F2, F3))
     FA[0] = 0
     FA[-1] = 1
     AA = np.hstack((A1, A2, A3))
     FIR = FIRDesign.fir2(self.nA, FA, AA)
     fir = signal.firwin2(51, FA, AA, nfreqs=1024, window='hamming')
     self.assertTrue(np.all(FIR[0] == fir))
示例#18
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))
示例#19
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')
示例#20
0
 def test_fir1_9(self):
     # Test for exception 3
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, [self.f1, self.f2], ftype='low')
示例#21
0
 def test_fir1_8(self):
     # Test for exception 2
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, self.f1, ftype='stop')
示例#22
0
 def test_fir1_7(self):
     # Test for Exception 1
     with self.assertRaises(ValueError):
         FIRDesign.fir1(self.n, self.f1, ftype='x')
示例#23
0
 def test_firls_1(self):
     # Test for least square method
     FIR = FIRDesign.firls(self.n, self.f, self.a)
     fir = signal.firls(101, self.f, self.a)
     self.assertTrue(np.all(FIR[0] == fir))
 def test_kaiserord_9(self):
     # Test case for Exception 3
     with self.assertRaises(ValueError):
         FIRDesign.kaiserord([self.f1, self.f2, self.f3, self.f4],
                             [self.m1, self.m2, self.m1], [self.dev1, -0.2])
 def test_kaiserord_7(self):
     # Test case for Exception 1
     with self.assertRaises(ValueError):
         FIRDesign.kaiserord([self.f1, self.f2],
                             [self.m1, self.m2, self.m1], self.dev2)
示例#26
0
 def test_isstable_1(self):
     # Test case for FIR filter
     fil = FIRDesign.fir1(self.order, self.cut)
     self.assertTrue(FilterSpec.isstable(fil) == True)
示例#27
0
 def test_isminphase_1(self):
     # Test case
     fil = FIRDesign.fir1(self.order, self.cut)
     self.assertTrue(FilterSpec.isminphase(fil) == False)
示例#28
0
 def test_fir2_4(self):
     # Test case for exception
     with self.assertRaises(ValueError):
         FIRDesign.fir2(self.nhi, self.fhi, self.mhi, npt=self.nhi / 4)
示例#29
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')
示例#30
0
 def test_firls_2(self):
     # Test for least square method with odd order
     FIR = FIRDesign.firls(self.n2, self.f, self.a)
     fir = signal.firls(103, self.f, self.a)
     self.assertTrue(np.all(FIR[0] == fir))