Esempio n. 1
0
 def test_2(self):
     k2 = self.k2
     p2 = self.p2
     filt2b = ctrl.Filter(
         lambda ss: k2/((ss + 2*np.pi*p2[0])*(ss + 2*np.pi*p2[1])))
     data1 = self.filt2a.computeFilter(self.ff)
     # data2 = self.filt2b.computeFilter(self.ff)
     data2 = filt2b.computeFilter(self.ff)
     assert close.allclose(data1, data2)
Esempio n. 2
0
 def test_cat3(self):
     k2 = self.k2
     p2 = self.p2
     filt2b = ctrl.Filter(
         lambda ss: k2/((ss + 2*np.pi*p2[0])*(ss + 2*np.pi*p2[1])))
     filt3d = ctrl.catfilt(self.filt1a, filt2b)
     data1 = self.filt3a.computeFilter(self.ff)
     # data2 = self.filt3d.computeFilter(self.ff)
     data2 = filt3d.computeFilter(self.ff)
     assert close.allclose(data1, data2)
Esempio n. 3
0
def define_filt(zpk):
    return ctrl.Filter(zpk.zeros, zpk.poles, zpk.gain, Hz=False)
Esempio n. 4
0
# Define the probes that will be used to sense each DOF.
DARM = dict(EX=1 / 2, EY=-1 / 2)
CARM = dict(EX=1 / 2, EY=1 / 2)

probesDARM = {'AS_Q': 1 / np.abs(katFR.getTF('AS_Q', DARM)[0])}
probesCARM = {'REFL_I': 1 / np.abs(katFR.getTF('REFL_I', CARM)[0])}
probesBS = {'REFL_Q': 1 / np.abs(katFR.getTF('REFL_Q', 'BS')[0])}

##############################################################################
# define control system
##############################################################################

# define the DOF filters
filtDARM = ctrl.Filter(
    ctrl.catzp(ctrl.resRoots(2, 1), ctrl.resRoots(5, 1)),
    ctrl.catzp(0, 0, 0, ctrl.resRoots(0.5, 1), ctrl.resRoots(110, 1)), -1, 20)

filtCARM = filtDARM

filtBS = ctrl.Filter(
    ctrl.catzp(ctrl.resRoots(1, 1), ctrl.resRoots(3, 1)),
    ctrl.catzp(0, 0, 0, ctrl.resRoots(0.3, 1), ctrl.resRoots(90, 1)), -1, 15)

# simple constant feedforward filter
filtFF = ctrl.Filter([], [], -4.98e-3)

# Define control system
cs = ctrl.ControlSystem()

DARM_dof = ctrl.DegreeOfFreedom(DARM, 'pos', probesDARM, 'DARM')
Esempio n. 5
0
class TestFilters:

    z1 = np.array([1, 2 + 3j, 2 - 3j])
    p1 = np.array([8, 3 + 2j, 3 - 2j])
    k1 = 4
    z2 = []
    p2 = ctrl.resRoots(42, 238)
    k2 = 6
    f4 = 10  # reference frequency
    g4 = 3  # gain at reference frequency
    ff = np.logspace(0, 4, 500)

    filt1a = ctrl.Filter(z1, p1, k1)
    filt1b = ctrl.Filter(-2*np.pi*z1, -2*np.pi*p1, k1, Hz=False)
    filt1c = ctrl.Filter(dict(zs=z1, ps=p1, k=k1))
    filt1d = ctrl.Filter(dict(zs=-2*np.pi*z1, ps=-2*np.pi*p1, k=k1), Hz=False)
    filt2a = ctrl.Filter(z2, p2, k2)
    # filt2b = ctrl.Filter(
    #     lambda ss: k2/((ss + 2*np.pi*p2[0])*(ss + 2*np.pi*p2[1])))
    filt3a = ctrl.Filter(
        ctrl.catzp(z1, z2), ctrl.catzp(p1, p2), k1*k2)
    filt3b = ctrl.catfilt(filt1a, filt2a)
    filt3c = ctrl.catfilt(filt1b, filt2a)
    # filt3d = ctrl.catfilt(filt1a, filt2b)
    filt4 = ctrl.Filter(z2, p2, g4, f4)

    data1 = h5py.File('test_filters.hdf5', 'w')
    filt1a.to_hdf5('filt1', data1)
    filt2a.to_hdf5('filt2', data1)
    data1.close()
    data2 = h5py.File('test_filters.hdf5', 'r')
    filt1r = ctrl.filt_from_hdf5('filt1', data2)
    filt2r = ctrl.filt_from_hdf5('filt2', data2)
    data2.close()
    os.remove('test_filters.hdf5')

    def test_1a(self):
        zpk1 = self.filt1a.get_zpk(Hz=True)
        assert np.all(check_zpk_equality(zpk1, (self.z1, self.p1, self.k1)))

    def test_1freq(self):
        zpk1 = self.filt1a.get_zpk(Hz=True)
        zpk2 = self.filt1b.get_zpk(Hz=True)
        assert np.all(check_zpk_equality(zpk1, zpk2))

    def test_1s(self):
        zpk1 = self.filt1a.get_zpk()
        zpk2 = self.filt1b.get_zpk()
        assert np.all(check_zpk_equality(zpk1, zpk2))

    def test_1c(self):
        zpk1 = self.filt1a.get_zpk()
        zpk2 = self.filt1c.get_zpk()
        assert np.all(check_zpk_equality(zpk1, zpk2))

    def test_1d(self):
        zpk1 = self.filt1a.get_zpk()
        zpk2 = self.filt1d.get_zpk()
        assert np.all(check_zpk_equality(zpk1, zpk2))

    def test_2(self):
        k2 = self.k2
        p2 = self.p2
        filt2b = ctrl.Filter(
            lambda ss: k2/((ss + 2*np.pi*p2[0])*(ss + 2*np.pi*p2[1])))
        data1 = self.filt2a.computeFilter(self.ff)
        # data2 = self.filt2b.computeFilter(self.ff)
        data2 = filt2b.computeFilter(self.ff)
        assert close.allclose(data1, data2)

    def test_cat1(self):
        assert check_filter_equality(self.filt3a, self.filt3b)

    def test_cat2(self):
        assert check_filter_equality(self.filt3a, self.filt3c)

    def test_cat3(self):
        k2 = self.k2
        p2 = self.p2
        filt2b = ctrl.Filter(
            lambda ss: k2/((ss + 2*np.pi*p2[0])*(ss + 2*np.pi*p2[1])))
        filt3d = ctrl.catfilt(self.filt1a, filt2b)
        data1 = self.filt3a.computeFilter(self.ff)
        # data2 = self.filt3d.computeFilter(self.ff)
        data2 = filt3d.computeFilter(self.ff)
        assert close.allclose(data1, data2)

    def test_gain(self):
        mag = np.abs(self.filt4.computeFilter(self.f4))
        assert close.isclose(mag, self.g4)

    def test_ss1(self):
        ss = self.filt1a.get_state_space()
        data1 = self.filt1a.computeFilter(self.ff)
        _, data2 = sig.freqresp(ss, 2*np.pi*self.ff)
        assert close.allclose(data1, data2)

    def test_ss2(self):
        ss = self.filt2a.get_state_space()
        data1 = self.filt2a.computeFilter(self.ff)
        _, data2 = sig.freqresp(ss, 2*np.pi*self.ff)
        assert close.allclose(data1, data2)

    def test_ss3(self):
        ss = self.filt3a.get_state_space()
        data1 = self.filt3a.computeFilter(self.ff)
        _, data2 = sig.freqresp(ss, 2*np.pi*self.ff)
        assert close.allclose(data1, data2)

    def test_1r(self):
        zpk1 = self.filt1a.get_zpk()
        zpk2 = self.filt1r.get_zpk()
        assert np.all(check_zpk_equality(zpk1, zpk2))

    def test_2r(self):
        zpk1 = self.filt2a.get_zpk()
        zpk2 = self.filt2r.get_zpk()
        assert np.all(check_zpk_equality(zpk1, zpk2))
Esempio n. 6
0
eng.eval("par = struct;", nargout=0)
eng.eval("par = paramCE1;", nargout=0)
eng.eval("par.PR.Thr = 0.01;", nargout=0)
eng.eval("opt = optCE_homo(par, 1);", nargout=0)
eng.eval("probesCE_homo(opt, par, 1);", nargout=0)
opt.loadMatModel()

ff = np.logspace(np.log10(3), np.log10(7e3), 300)
opt.run(ff)

DARM = {'EX': 1, 'EY': -1}
MICH = {'BS': 1, 'SR': 1 / np.sqrt(2), 'PR': -1 / np.sqrt(2)}

filtDARM = ctrl.Filter(ctrl.catzp(-2 * np.pi * 20, -2 * np.pi * 800),
                       ctrl.catzp(0, 0, -2 * np.pi * 300 * (1 + 1j / 2),
                                  -2 * np.pi * 300 * (1 - 1j / 2)),
                       -1e-8 * (2 * np.pi * 300)**2 / (2 * np.pi * 800),
                       Hz=False)

filtPRCL = ctrl.Filter(-2 * np.pi * 10,
                       ctrl.catzp(0, -2 * np.pi * (20 + 10j),
                                  -2 * np.pi * (20 - 10j)),
                       -1e-5,
                       Hz=False)

filtSRCL = ctrl.Filter([], ctrl.catzp(0, -2 * np.pi * 20), -4e-5, Hz=False)

filtMICH = ctrl.Filter(-2 * np.pi * 10,
                       ctrl.catzp(0, -2 * np.pi * (10 + 10j),
                                  -2 * np.pi * (10 - 10j), -2 * np.pi * 300),
                       0.25,