Exemplo n.º 1
0
    def test_eq(self):
        # Check that linear filters are equal iff. they share a numerator and
        # denominator.
        lpf = LowpassFilter(0, False, 0.1)
        lf1 = LinearFilter(0, False, [1.0], [0.1, 0.2])
        lf2 = LinearFilter(0, False, [1.0], [0.1, 0.3])
        lf3 = LinearFilter(0, False, [1.0], [0.1, 0.2])

        assert lf1 != lpf
        assert lf2 != lf1
        assert lf3 != lf2
        assert lf3 == lf1
Exemplo n.º 2
0
    def test_from_parameters_force_width(self):
        # Create the mock signal and connection
        signal = SignalParameters(latching=True)
        rps = ReceptionParameters(nengo.LinearFilter([1.0], [0.5, 1.0]), 1)

        # Create the filter
        lpf = LinearFilter.from_parameters(signal, rps, width=2)
        assert lpf == LinearFilter(2, True, [1.0], [0.5, 1.0])
Exemplo n.º 3
0
    def test_pack_data(self, num, den, dt, order):
        # Create the filter
        lf = LinearFilter(0, False, num, den)

        # Create a buffer to pack data into
        data = bytearray((order * 2 + 1) * 4)

        # Pack the parameters
        lf.pack_data(dt, data, 0)

        # Generate what we expect the data to look like
        numd, dend, _ = cont2discrete((num, den), dt)
        numd = numd.flatten()
        exp = list()
        for a, b in zip(dend[1:], numd[1:]):
            exp.append(-a)
            exp.append(b)
        expected_data = tp.np_to_fix(np.array(exp)).tostring()

        # Check that's what we get
        assert struct.unpack_from("<I", data, 0)[0] == order
        assert data[4:] == expected_data
Exemplo n.º 4
0
 def test_size_words(self, num, den, size_words):
     lf = LinearFilter(0, False, num, den)
     assert lf.size_words() == size_words
Exemplo n.º 5
0
 def test_method_index(self):
     lf = LinearFilter(0, False, [1.0], [1.0, 0.5])
     assert lf.method_index() == 2