📄 bddemo.m
字号:
## Copyright (C) 1996, 2000, 2004, 2005, 2007## Auburn University. All rights reserved.#### This file is part of Octave.#### Octave is free software; you can redistribute it and/or modify it## under the terms of the GNU General Public License as published by## the Free Software Foundation; either version 3 of the License, or (at## your option) any later version.#### Octave is distributed in the hope that it will be useful, but## WITHOUT ANY WARRANTY; without even the implied warranty of## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU## General Public License for more details.#### You should have received a copy of the GNU General Public License## along with Octave; see the file COPYING. If not, see## <http://www.gnu.org/licenses/>.## -*- texinfo -*-## @deftypefn {Function File} {} bddemo (@var{inputs})## Octave Controls toolbox demo: Block Diagram Manipulations demo.## @end deftypefn## Author: David Clem## Created: August 15, 1994## Modified by A S Hodel Summer-Fall 1996function bddemo () sav_page = page_screen_output (); page_screen_output (1); while (1) clc k=0; while(k > 14 || k < 1) k = menu("Octave Block Diagram Manipulations Demo", ... "sysadd/syssub: F(s) = G(s) +/- H(s)", ... "sysappend: add new inputs/outputs", ... "syssetsignals: change names of inputs, outputs, and/or states", ... "sysconnect: connect specified system inputs/outputs", ... "syscont/sysdisc: extract the continuous (discrete) part of a system", ... "sysdup: duplicate specified inputs/outputs", ... "sysgroup: group two systems into a single system,", ... "sysmult: F(s) = G(s)*H(s) (series connection)", ... "sysprune: keep only specified inputs/outputs", ... "sysscale: scale inputs/outputs by specified gain matrices", ... "parallel: parallel connection of two systems", ... "buildssic: the combination of all", ... "Design examples:", ... "Return to main demo menu"); endwhile if (k == 1) clc disp("sysadd: add two systems together") disp("syssub: subtract F = G - H") prompt help sysadd prompt help syssub prompt disp("Example #1, \n") cmd = "sys1 = tf([1 -1],[1 2 1]);"; run_cmd cmd = "sys2 = tf([1 -1],[1 2 3]);"; run_cmd disp("sys1=") sysout(sys1); prompt disp("sys2=") sysout(sys2); cmd = "sys_sum1 = sysadd(sys1,sys1);"; run_cmd disp("This example adds sys1 to itself.") cmd = "sysout(sys_sum1)"; run_cmd disp("Notice that the numerator is twice what it used to be.") prompt disp("Example 2:") cmd = "sys_sub1 = syssub(sys1,sys2);"; run_cmd disp("Notice that sysadd (actually sysgroup, called by sysadd) lets you") disp("know that your two systems had identical names for their states,") disp("inputs and outputs. The warning message is perfectly harmless,") disp("and is provided for user information only.") disp("sys_sub1=") sysout(sys_sub1) disp("Notice that, since the two transfer functions had different") disp("denominators, syssub converted the primary system type to ") disp("state space. This is the typical behavior unless the") disp("the two systems are both SISO, they both have the same poles,") disp("and at least one of them has tf for its primary system type."); prompt elseif (k == 2) disp("sysappend: add new inputs and/or outputs to a system") help sysappend prompt disp("Consider a double-integrator system:") sys = tf(1, [1, 0, 0]); sys=sysupdate(sys,"ss"); sysout(sys,"ss"); disp("We add a velocity disturbance input as follows:") cmd = "sys1=sysappend(sys,[1;0]);"; run_cmd sysout(sys1,"ss"); disp("Names of inputs can be included as follows:") cmd = "sys1=sysappend(sys,[1;0], [],[],[],\"Disturb\");"; run_cmd disp("Notice that empty matrices can be listed for the D matrix if") disp("all entries are zeros.") disp(" ") disp("sys1 is thus:") sysout(sys1); prompt elseif (k == 3) disp("syssetsignals:") help syssetsignals disp("Example system"); a = rand(3,3); b = rand(3,2); c = rand(2,3); sys = ss(a,b,c); sysout(sys); prompt disp("Change state names to larry, moe, and curly as follows:") cmd = 'sys = syssetsignals(sys,"st",{"larry","moe" , "curly"});'; run_cmd disp("Indicate that output 2 is discrete-time:") cmd = 'sys = syssetsignals(sys,"yd",1,2);'; run_cmd disp("Change output 2 name to \"Vir\""); cmd = "sys = syssetsignals(sys,\"out\",\"Vir\",2);"; run_cmd disp("Resulting system is:") sysout(sys); prompt elseif (k == 4) help sysconnect prompt disp("********* N O T E *********") disp("sysconnect is demonstrated fully in the design examples (option 13)"); prompt elseif (k == 5) disp("syscont and sysdisc: ") disp("Example block diagram 1:") disp(" ------------------ ---------------------"); disp(" u_in ->| Discrete system |--->| Continuous system | ---> y_out"); disp(" ------------------ ---------------------"); sys1 = tf([1, 2],[1, 2, 1], 1,"u_in","y_disc"); sys2 = tf([1, 0],[1, -3, -2],0,"c_in","y_out"); sys = sysmult(sys2,sys1); disp("Consider the hybrid system") sysout(sys); prompt help syscont disp("The continuous part of the system can be extracted with syscont") cmd = "[csys,Acd,Ccd] = syscont(sys);"; run_cmd disp("The resulting csys is") sysout(csys); disp("Notice that B is 0; there is no purely continuous path from the") disp("input to the output"); prompt help sysdisc disp("The discrete part of the system can be extracted with sysdisc") cmd = "[dsys,Adc,Cdc] = sysdisc(sys)"; run_cmd disp("The resulting dsys is") sysout(dsys); disp("sysdisc returns dsys=empty since sys has no discrete outputs."); prompt disp("Example block diagram 2:") sys1 = tf([1, 2],[1, 2, 1], 1,"u_in","y_disc"); sys2 = tf([1, 0],[1, -3, -2],0,"c_in","y_out"); disp(" ---------------------") disp(" u_in -->o-->| Discrete system | --------> y_disc") disp(" ^ --------------------- |") disp(" | | "); disp(" -----------------------------|---") disp(" | |") disp(" ------------------------------ |") disp(" | |") disp(" v --------------------- |") disp(" c_in -->o-->| continuous system | --------> y_out") disp(" ---------------------") disp("repeat the above example with sys=") sys = sysgroup(sys1, sys2); sysout(sys) prompt sys = sysconnect(sys,[1, 2],[2, 1]); sysout(sys); cmd = "[csys,Acd,Bcd] = syscont(sys);"; run_cmd cmd = "[dsys,Acd,Bcd] = sysdisc(sys);"; run_cmd disp("csys is now") sysout(csys) disp("dsys is now") sysout(dsys); prompt elseif (k == 6) help sysdup prompt disp("********* N O T E *********") disp("sysdup is fully demonstrated in the design examples (option 13)") prompt elseif (k == 7) help sysgroup disp(" ") prompt disp("Example: combine two SISO systems together:") cmd = "sys_a=tf([1, 2],[3, 4]);"; run_cmd cmd = "sys_b=tf([5, 6],[7, 8],1);"; run_cmd cmd = "sys_g=sysgroup(sys_a,sys_b);"; run_cmd disp("Notice that sysgroup warns you when you join a purely continuous") disp("system to a purely discrete system. sysgroup also warns when") disp("you join two systems that have common state, input, or output names.") cmd = "sysout(sys_g)"; run_cmd disp("Since the grouped system is a multiple-input multiple-output system,") disp("the output system is by default in state-space format.") disp(" ") disp("********* N O T E *********") disp("sysgroup is further demonstrated in the design examples (option 13)") prompt elseif (k == 8) help sysmult disp("sysmult performs a series connection of two systems.") disp("Example 1") disp(" ") disp(" ---------- ----------") disp(" u --->| Bsys |---->| Asys |---> y") disp(" ---------- ----------") disp(" ") Asys = tf(1,[1, 2, 1],0,"a_in","a_out"); Bsys = tf([2, 3],[1, 3, 2],0,"b_in","b_out"); disp("Asys=") sysout(Asys); disp("Bsys="); sysout(Bsys); cmd = "sys = sysmult(Asys,Bsys);"; run_cmd disp("sys =") sysout(sys); disp("Notice that sysmult automatically transforms to state space") disp("internal representation. This is to avoid numerical problems") disp("when multiplying polynomials"); prompt disp("Example 2: same system, except that Bsys is discrete-time"); Bsys = tf([2, 3],[1, 3, 2],1e-2,"b_in","b_out"); sysout(Bsys); cmd = "sys = sysmult(Asys,Bsys);"; run_cmd disp("sys =") sysout(sys); prompt elseif (k == 9) help sysprune prompt disp("********* N O T E *********") disp("sysprune is demonstrated in the design examples (option 13)"); prompt elseif (k == 10) help sysscale disp(" ") prompt disp("********* N O T E *********") disp("See the design examples (option 13) for use of sysscale.") prompt elseif ( k == 11) help parallel disp("parallel operates by making a call to sysgroup and sysscale.") disp("Example:") sys1 = tf(1,[1, 1],0,"in1","out1"); sys2 = tf(2,[1, 2],0,"in2","out2"); disp("sys1=") sysout(sys1); disp("sys2=") sysout(sys2); cmd = "sysp = parallel(sys1,sys2);"; run_cmd disp("sysp=") sysout(sysp); prompt disp("parallel can be used for multiple input systems as well:") in1 = {"u1.1","u1.2"}; in2 = {"u2.1","u2.2"}; out1 = {"y1.1","y1.2"}; out2 = {"y2.1","y2.2"}; sys1 = ss([-1, 0; 0, -2],eye(2),eye(2),[]); sys2 = ss([-2, 0; 0, -4],eye(2),eye(2),[]); sys1 = syssetsignals(sys1,"in",in1); sys1 = syssetsignals(sys1,"out",out1); sys2 = syssetsignals(sys2,"in",in2); sys2 = syssetsignals(sys2,"out",out2); disp("sys1=") sysout(sys1); disp("sys2=")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -