e937db3d8813c8f0651a45e5f3500f9c8921f9c5
[scilab.git] / scilab / modules / cacsd / tests / unit_tests / margins.tst
1 //gain margin
2 //-----------
3 //discrete time case
4 h = syslin(0.1,0.04798*%z+0.0464,%z^2-1.81*%z+0.9048);//pk
5 [g ,f]=g_margin(h);
6 if norm(g - 6.2423793565916954)>1d-5  then pause,end
7 if norm(f - 0.86539118158628991)>1d-5  then pause,end
8
9
10 h=syslin(0.1,0.086-0.161*%z+0.078*%z^2,-0.67+2.286*%z-2.61*%z^2+%z^3);//ok
11 [g ,f]=g_margin(h);
12 if norm(g- 12.3470513198133762)>1d-5  then pause,end
13 if norm(f-0.26109869168929700)>1d-5  then pause,end
14
15 h=syslin(0.1,3*(0.086-0.161*%z+0.078*%z^2),-0.67+2.286*%z-2.61*%z^2+%z^3);//ok
16 [g ,f]=g_margin(h);
17 if norm(g-2.80462622542011131)>1d-5  then pause,end
18 if norm(f-0.26109869168929828)>1d-5  then pause,end
19
20
21 //continuuous time case
22 h=syslin('c',-1+%s,3+2*%s+%s^2);//ok
23 [g,f]=g_margin(h);
24 if norm(g-20*log(3)/log(10))>1d-5  then pause,end
25 if norm(f)>1d-5  then pause,end
26
27
28  h = syslin('c',0.2+0.8*%s+0.3*%s^3,0.0409+0.1827*%s+1.28225*%s^2+3.1909*%s^3+2.56*%s^4+%s^5);
29 [g,f]=g_margin(h);
30 if norm(g + 4.91687406933815385)>1d-5  then pause,end
31 if norm(f-0.07145552582020068)>1d-5  then pause,end
32
33 //phase margin
34 //-----------
35 //discrete time case
36 h = syslin(0.1,0.04798*%z+0.0464,%z^2-1.81*%z+0.9048);//ok
37 [p ,f]=p_margin(h);
38 if norm(p-13.5711556361199754)>1d-5  then pause,end
39 if norm(f-0.69301660031536083)>1d-5  then pause,end
40
41
42 h=syslin(0.1,0.086-0.161*%z+0.078*%z^2,-0.67+2.286*%z-2.61*%z^2+%z^3);//ok
43 [p ,f]=p_margin(h);
44 if p<>%inf  then pause,end
45 if f<>[]  then pause,end
46
47 h=syslin(0.1,3*(0.086-0.161*%z+0.078*%z^2),-0.67+2.286*%z-2.61*%z^2+%z^3);//ok
48 [p ,f]=p_margin(h);
49 if norm(p-52.9496741629204308 )>1d-5  then pause,end
50 if norm(f-0.21233648894721618)>1d-5  then pause,end
51
52
53 //continuous case
54 h=syslin('c',1.1+2.4*%s+0.7*%s^2,3+2*%s+%s^2);
55 [p,f]=p_margin(h);
56 if norm(p-(-148.547076202317413))>1d-5  then pause,end
57 if norm(f-0.18945852512301298)>1d-5  then pause,end
58
59  h = syslin('c',0.2+0.8*%s+0.3*%s^3,0.0409+0.1827*%s+1.28225*%s^2+3.1909*%s^3+2.56*%s^4+%s^5);
60 [p,f]=p_margin(h);
61 if norm(p + 13.1128497150069734 )>1d-5  then pause,end
62 if norm(f-0.09144216563554157  )>1d-5  then pause,end