├── src ├── Makefile.conf.in ├── bootstrap ├── undef-ah-octave.h ├── slicot │ └── README.md ├── __control_helper_functions__.cc ├── configure.ac ├── is_matrix.cc ├── is_real_matrix.cc ├── is_real_scalar.cc ├── is_real_vector.cc └── is_real_square_matrix.cc ├── doc ├── control.png ├── octave_forge_specific_api.txt ├── documentation.html ├── SLICOT │ └── README.md └── references.txt ├── post_install.m ├── DESCRIPTION ├── inst ├── optiPIDctrl.m ├── @tfpoly │ ├── roots.m │ ├── display.m │ ├── numel.m │ ├── uminus.m │ ├── uplus.m │ ├── length.m │ ├── get.m │ ├── is_zero.m │ ├── conj_dt.m │ ├── eq.m │ ├── ne.m │ ├── mtimes.m │ ├── conj_ct.m │ ├── __make_equally_long__.m │ ├── plus.m │ ├── __remove_leading_zeros__.m │ ├── minus.m │ ├── subsref.m │ ├── mpower.m │ └── tfpoly.m ├── @frd │ ├── __pole__.m │ ├── __sys_data__.m │ ├── __zero__.m │ ├── __minreal__.m │ ├── __times__.m │ ├── __sys2ss__.m │ ├── __c2d__.m │ ├── __d2c__.m │ ├── __sys_inverse__.m │ ├── __transpose__.m │ ├── __ctranspose__.m │ ├── __sys2tf__.m │ ├── __get__.m │ ├── __sys_prune__.m │ ├── __set__.m │ ├── __sys_keys__.m │ ├── __freqresp__.m │ └── __sys_connect__.m ├── @tf │ ├── __transpose__.m │ ├── __sys_data__.m │ ├── __pole__.m │ ├── __sys2frd__.m │ ├── __sys_prune__.m │ ├── __make_tf_polys_equally_long__.m │ ├── __zero__.m │ ├── __freqresp__.m │ ├── __sys_inverse__.m │ ├── __times__.m │ ├── __get__.m │ ├── __ctranspose__.m │ ├── __sys_keys__.m │ ├── vertcat.m │ └── horzcat.m ├── tfpolyones.m ├── @lti │ ├── eig.m │ ├── __lti_data__.m │ ├── __sys_keys__.m │ ├── issiso.m │ ├── uplus.m │ ├── blkdiag.m │ ├── uminus.m │ ├── size_equal.m │ ├── end.m │ ├── isct.m │ ├── transpose.m │ ├── lti.m │ ├── vertcat.m │ ├── isdt.m │ ├── mldivide.m │ ├── mrdivide.m │ ├── minus.m │ ├── display.m │ ├── parallel.m │ ├── __numeric_to_lti__.m │ ├── freqresp.m │ ├── isstable.m │ └── times.m ├── tfpolyzeros.m ├── @ss │ ├── __times__.m │ ├── __sys_data__.m │ ├── __transpose__.m │ ├── __sys2frd__.m │ ├── __pole__.m │ ├── __freqresp__.m │ ├── __get__.m │ ├── isstaticgain.m │ ├── __ctranspose__.m │ ├── __prescale__.m │ ├── __sys_inverse__.m │ ├── __zero__.m │ ├── __sys_keys__.m │ ├── __minreal__.m │ └── __set__.m ├── __modred_check_tol__.m ├── __modred_default_alpha__.m ├── __modred_check_equil__.m ├── __adjust_iddata__.m ├── append.m ├── __modred_check_alpha_gram__.m ├── __opt2cell__.m ├── __remove_leading_zeros__.m ├── __tf_dim__.m ├── __is_stable__.m ├── __modred_check_order__.m ├── __conred_check_feedback_sign__.m ├── __remove_trailing_zeros__.m ├── @iddata │ ├── merge.m │ ├── vertcat.m │ ├── horzcat.m │ ├── diff.m │ └── end.m ├── __labels__.m ├── __modred_check_gram__.m ├── __modred_check_alpha__.m ├── __str2idx__.m ├── strseq.m ├── db2mag.m ├── __modred_check_weight__.m ├── repsys.m ├── mag2db.m ├── __frd_dim__.m ├── __adjust_iddata_tsam__.m ├── __tito_dim__.m ├── optiPIDfun.m ├── __adjust_labels__.m ├── __adjust_ss_data__.m ├── __adjust_frd_data__.m ├── augstate.m └── __axis_margin__.m └── io.github.gnu_octave.pkg-control.metainfo.xml /src/Makefile.conf.in: -------------------------------------------------------------------------------- 1 | MKOCTFILE ?= @MKOCTFILE@ 2 | 3 | -------------------------------------------------------------------------------- /doc/control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gnu-octave/pkg-control/HEAD/doc/control.png -------------------------------------------------------------------------------- /src/bootstrap: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | aclocal 4 | 5 | autoconf 6 | 7 | autoheader -f 8 | -------------------------------------------------------------------------------- /post_install.m: -------------------------------------------------------------------------------- 1 | function post_install (d) 2 | 3 | fprintf ('\n'); 4 | fprintf ('The control package was installed into the directory\n'); 5 | fprintf ('%s.\n', d.dir); 6 | fprintf ('License and copyright information can be found in '); 7 | fprintf ('\"packinfo/COPYING\".\n'); 8 | 9 | fprintf ('\n'); 10 | fprintf ('If the control package was updated in this Octave\n'); 11 | fprintf ('session, you might have to restart Octave.\n'); 12 | fprintf ('\n'); 13 | 14 | end 15 | -------------------------------------------------------------------------------- /src/undef-ah-octave.h: -------------------------------------------------------------------------------- 1 | /* To be included at the top of config.h (by autoheader). Avoid 2 | warnings for redefining AH-generated preprocessor symbols of 3 | Octave. */ 4 | 5 | #ifdef PACKAGE_BUGREPORT 6 | #undef PACKAGE_BUGREPORT 7 | #endif 8 | 9 | #ifdef PACKAGE_NAME 10 | #undef PACKAGE_NAME 11 | #endif 12 | 13 | #ifdef PACKAGE_STRING 14 | #undef PACKAGE_STRING 15 | #endif 16 | 17 | #ifdef PACKAGE_TARNAME 18 | #undef PACKAGE_TARNAME 19 | #endif 20 | 21 | #ifdef PACKAGE_URL 22 | #undef PACKAGE_URL 23 | #endif 24 | 25 | #ifdef PACKAGE_VERSION 26 | #undef PACKAGE_VERSION 27 | #endif 28 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Name: control 2 | Version: 4.1.3 3 | Date: 2025-09-10 4 | Author: Lukas Reichlin 5 | Maintainer: Doug Stewart , Torsten Lilge 6 | Title: Control Package 7 | Description: Control package for GNU Octave including system analysis and 8 | control synthesis. The package uses routines of the SLICOT-Reference library. 9 | Depends: octave (>= 5.2.0) 10 | Autoload: no 11 | License: GPLv3-or-later, BSD 3-Clause License (SLICOT files) 12 | Url: https://github.com/gnu-octave/pkg-control 13 | Tracker: https://github.com/gnu-octave/pkg-control/issues 14 | -------------------------------------------------------------------------------- /src/slicot/README.md: -------------------------------------------------------------------------------- 1 | In the distributed control package archive `control-x.y.z.tar.gz`, this directory contains some source files of the [SLICOT-Reference library](https://github.com/SLICOT/SLICOT-Reference), which are compiled for the target system while installing the control package for Octave. The SLICOT files are available under the *BSD 3-Clause License* which can be found in the file `LICENSE` in the distributed version of this directory or [in the SLICOT repository](https://github.com/SLICOT/SLICOT-Reference/blob/main/LICENSE). 2 | 3 | The original `README.md` is available as `README-SLICOT.md` in the distributed version of the directory or also [in the SLICOT repository](https://github.com/SLICOT/SLICOT-Reference/blob/main/README.md). 4 | -------------------------------------------------------------------------------- /inst/optiPIDctrl.m: -------------------------------------------------------------------------------- 1 | % =============================================================================== 2 | % optiPIDctrl Lukas Reichlin February 2012 3 | % =============================================================================== 4 | % Return PID controller with roll-off for given parameters Kp, Ti and Td. 5 | % =============================================================================== 6 | 7 | function C = optiPIDctrl (Kp, Ti, Td) 8 | 9 | tau = Td / 10; % roll-off 10 | 11 | num = Kp * [Ti*Td, Ti, 1]; 12 | den = conv ([Ti, 0], [tau^2, 2*tau, 1]); 13 | 14 | C = tf (num, den); 15 | 16 | end 17 | 18 | % =============================================================================== 19 | -------------------------------------------------------------------------------- /src/__control_helper_functions__.cc: -------------------------------------------------------------------------------- 1 | #include "is_real_scalar.cc" 2 | #include "is_real_vector.cc" 3 | #include "is_real_matrix.cc" 4 | #include "is_real_square_matrix.cc" 5 | #include "is_matrix.cc" 6 | #include "is_zp_vector.cc" 7 | #include "lti_input_idx.cc" 8 | 9 | 10 | // stub function to avoid gen_doc_cache warning upon package installation 11 | DEFUN_DLD (__control_helper_functions__, args, nargout, 12 | "-*- texinfo -*-\n" 13 | "@deftypefn {} __control_helper_functions__ (@dots{})\n" 14 | "Helper functions for the control package.@*\n" 15 | "For internal use only.\n" 16 | "@end deftypefn") 17 | { 18 | octave_value_list retval; 19 | error ("__control_helper_functions__: for internal use only"); 20 | return retval; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /doc/octave_forge_specific_api.txt: -------------------------------------------------------------------------------- 1 | isstable (sys, tol) # 2 | 3 | feedback (sys) # equivalent to feedback (sys, eye (size (sys))) 4 | feedback (sys, "+") # equivalent to feedback (sys, eye (size (sys)), +1) 5 | 6 | H = sys(w) # equivalent to H = freqresp (sys, w) where w is a frequency vector 7 | 8 | place (sys, p, alpha) # If parameter alpha is specified, poles with real parts 9 | place (a, b, p, alpha) # (continuous time) or moduli (discrete time) below alpha 10 | # are left untouched. 11 | 12 | sminreal (sys, tol) # Optional tolerance for controllability and observability. 13 | # Entries of the state-space matrices whose moduli are less or 14 | # equal to TOL are assumed to be zero. Default value is 0. 15 | 16 | frd (sys) # calculate interesting frequency range by the zeros and poles of SYS. -------------------------------------------------------------------------------- /src/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ([2.71]) 5 | AC_INIT([control],[4.1.3]) 6 | AC_CONFIG_SRCDIR([sl_ab01od.cc]) 7 | AC_CONFIG_HEADERS([config.h]) 8 | 9 | # Avoid warnings for redefining AH-generated preprocessor symbols of 10 | # Octave. 11 | AH_TOP([#include "undef-ah-octave.h"]) 12 | 13 | AC_CONFIG_MACRO_DIRS([m4]) 14 | 15 | # Checks for programs. 16 | AC_CHECK_PROG(MKOCTFILE, mkoctfile, mkoctfile) 17 | if test -z "$MKOCTFILE"; then 18 | AC_MSG_ERROR([mkoctfile not found], 1); 19 | fi 20 | AC_CHECK_PROG(OCTAVE_CONFIG, octave-config, octave-config) 21 | if test -z "$OCTAVE_CONFIG"; then 22 | AC_MSG_ERROR([octave-config not found], 1); 23 | fi 24 | 25 | AC_PROG_CXX 26 | AC_PROG_F77 27 | 28 | # Output results and subst variables in Makefile.conf.in 29 | AC_CONFIG_FILES([Makefile.conf]) 30 | AC_OUTPUT 31 | 32 | -------------------------------------------------------------------------------- /doc/documentation.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Computer-Aided Control System Design: Documentation 5 | 6 | 7 | 8 |

Control Package for GNU Octave

9 | 10 |

Links to documentation and license information:

11 | 12 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /inst/@tfpoly/roots.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Compute the roots of a TFPOLY object. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.1 24 | 25 | function r = roots (p) 26 | 27 | r = roots (p.poly); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/display.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Display routine. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function display (p) 26 | 27 | tfpoly2str (p, "s") 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@frd/__pole__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Poles of FRD object. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function pol = __pole__ (sys) 26 | 27 | error ("frd: pole: this is not possible"); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/numel.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Number of coefficients. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function n = numel (p) 26 | 27 | n = numel (p.poly); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/uminus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Unitary minus operator. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function a = uminus (a) 26 | 27 | a.poly = -a.poly; 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/uplus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Unitary plus operator. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function a = uplus (a) 26 | 27 | a.poly = +a.poly; 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/length.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Number of coefficients. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function l = length (p) 26 | 27 | l = length (p.poly); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/get.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Return coefficients as a row vector. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.1 24 | 25 | function coeffs = get (p) 26 | 27 | coeffs = p.poly; 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/is_zero.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Check whether tfpoly is zero. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2013 23 | ## Version: 0.1 24 | 25 | function bool = is_zero (p) 26 | 27 | bool = ! any (p.poly); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@frd/__sys_data__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Used by frdata instead of multiple get calls. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function [H, w] = __sys_data__ (sys) 26 | 27 | H = sys.H; 28 | w = sys.w; 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /inst/@frd/__zero__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Transmission zeros of FRD object. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function [zer, gain, info] = __zero__ (sys, ~) 26 | 27 | error ("frd: zero: this is not possible"); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tfpoly/conj_dt.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Conjugate of discrete-time polynomial. Replace z by 1/z. 20 | ## For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: May 2012 24 | ## Version: 0.1 25 | 26 | function p = conj_dt (p) 27 | 28 | p.poly = fliplr (p.poly); 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /inst/@frd/__minreal__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Minimal realization of FRD objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function sys = __minreal__ (sys, tol) 26 | 27 | warning ("frd: minreal: frequency responses are always minimal\n"); 28 | 29 | endfunction 30 | -------------------------------------------------------------------------------- /inst/@tf/__transpose__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Transpose of TF models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: February 2010 23 | ## Version: 0.1 24 | 25 | function sys = __transpose__ (sys) 26 | 27 | num = sys.num; 28 | den = sys.den; 29 | 30 | sys.num = num.'; 31 | sys.den = den.'; 32 | 33 | endfunction 34 | -------------------------------------------------------------------------------- /inst/@tf/__sys_data__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Used by tfdata instead of multiple get calls. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.1 24 | 25 | function [num, den, tfvar] = __sys_data__ (sys) 26 | 27 | num = sys.num; 28 | den = sys.den; 29 | tfvar = sys.tfvar; 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/tfpolyones.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Return (pxm) cell of tfpoly([1]). For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function ret = tfpolyones (p, m) 26 | 27 | ret = cell (p, m); 28 | 29 | one = tfpoly ([1]); 30 | 31 | ret(:) = {one}; 32 | 33 | endfunction 34 | -------------------------------------------------------------------------------- /inst/@lti/eig.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{p} =} eig (@var{sys}) 20 | ## Compute poles of @acronym{LTI} system. 21 | ## @end deftypefn 22 | 23 | ## Author: Lukas Reichlin 24 | ## Created: October 2009 25 | ## Version: 0.1 26 | 27 | function pol = eig (varargin) 28 | 29 | pol = pole (varargin{:}); 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/tfpolyzeros.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Return (pxm) cell of tfpoly([0]). For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function ret = tfpolyzeros (p, m) 26 | 27 | ret = cell (p, m); 28 | 29 | zero = tfpoly ([0]); 30 | 31 | ret(:) = {zero}; 32 | 33 | endfunction 34 | -------------------------------------------------------------------------------- /inst/@lti/__lti_data__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Used by display routines instead of multiple get calls. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2010 23 | ## Version: 0.1 24 | 25 | function [inname, outname, tsam] = __lti_data__ (sys) 26 | 27 | inname = sys.inname; 28 | outname = sys.outname; 29 | tsam = sys.tsam; 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/@tfpoly/eq.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Test for equal coefficients. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function bool = eq (a, b) 26 | 27 | a = tfpoly (a); 28 | b = tfpoly (b); 29 | 30 | bool = (length (a) == length (b)) && all (a.poly == b.poly); 31 | 32 | endfunction 33 | -------------------------------------------------------------------------------- /inst/@tfpoly/ne.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Return true if polynomials are not equal. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function bool = ne (a, b) 26 | 27 | a = tfpoly (a); 28 | b = tfpoly (b); 29 | 30 | bool = (length (a) != length (b)) || any (a.poly != b.poly); 31 | 32 | endfunction 33 | -------------------------------------------------------------------------------- /inst/@frd/__times__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Hadamard/Schur product of @acronym{FRD} objects. 20 | ## Used by Octave for "sys1 .* sys2". 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: May 2014 24 | ## Version: 0.1 25 | 26 | function sys = __times__ (sys1, sys2) 27 | 28 | error ("frd: times: Hadamard/Schur product is not implemented for FRD objects"); 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /inst/@ss/__times__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Hadamard/Schur product of @acronym{SS} objects. 20 | ## Used by Octave for "sys1 .* sys2". 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: May 2014 24 | ## Version: 0.1 25 | 26 | function sys = __times__ (sys1, sys2) 27 | 28 | error ("ss: times: Hadamard/Schur product is only supported for transfer functions"); 29 | 30 | endfunction 31 | -------------------------------------------------------------------------------- /inst/__modred_check_tol__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check tolerance for model reduction commands 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: November 2011 23 | ## Version: 0.1 24 | 25 | function tol = __modred_check_tol__ (tol, str = "") 26 | 27 | if (! is_real_scalar (tol)) 28 | error ("modred: argument %s must be a real scalar", str); 29 | endif 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/@frd/__sys2ss__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## FRD to SS conversion. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function [retsys, retlti] = __sys2ss__ (sys) 26 | 27 | error ("frd: frd2ss: system identification not implemented yet"); 28 | 29 | retsys = dss (a, b, c, d, e); 30 | retlti = sys.lti; # preserve lti properties 31 | 32 | endfunction 33 | -------------------------------------------------------------------------------- /inst/@frd/__c2d__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Convert the continuous FRD object into its discrete-time equivalent. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function sys = __c2d__ (sys, tsam, method = "zoh") 26 | 27 | error ("frd: c2d: conversion not possible"); 28 | 29 | ## NOTE: changing just the sampling time wouldn't make sense here 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/@frd/__d2c__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Convert the discrete FRD object into its continuous-time equivalent. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2011 23 | ## Version: 0.1 24 | 25 | function sys = __d2c__ (sys, tsam, method = "zoh") 26 | 27 | error ("frd: d2c: conversion not possible"); 28 | 29 | ## NOTE: changing just the sampling time wouldn't make sense here 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/@frd/__sys_inverse__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Inversion of FRD objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function sys = __sys_inverse__ (sys) 26 | 27 | [p, m, l] = size (sys.H); 28 | 29 | H = mat2cell (sys.H, p, m, ones (1, l))(:); 30 | 31 | H = cellfun (@inv, H, "uniformoutput", false); 32 | 33 | sys.H = cat (3, H{:}); 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@frd/__transpose__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Transpose of FRD objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function sys = __transpose__ (sys) 26 | 27 | [p, m, l] = size (sys.H); 28 | 29 | H = mat2cell (sys.H, p, m, ones (1, l))(:); 30 | 31 | H = cellfun (@transpose, H, "uniformoutput", false); 32 | 33 | sys.H = cat (3, H{:}); 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@ss/__sys_data__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Used by ssdata instead of multiple get calls. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.3 24 | 25 | function [a, b, c, d, e, stname, scaled] = __sys_data__ (sys) 26 | 27 | a = sys.a; 28 | b = sys.b; 29 | c = sys.c; 30 | d = sys.d; 31 | e = sys.e; 32 | stname = sys.stname; 33 | scaled = sys.scaled; 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@tf/__pole__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Poles of TF object. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.2 24 | 25 | function pol = __pole__ (sys) 26 | 27 | if (issiso (sys)) 28 | pol = roots (sys.den{1}); 29 | else 30 | warning ("tf: pole: converting to minimal state-space for pole computation of mimo tf\n"); 31 | pol = pole (ss (sys)); 32 | endif 33 | 34 | endfunction 35 | -------------------------------------------------------------------------------- /inst/__modred_default_alpha__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## default alpha for model reduction commands 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: November 2011 23 | ## Version: 0.1 24 | 25 | function alpha = __modred_default_alpha__ (dt) 26 | 27 | if (dt) # discrete-time 28 | alpha = 1; # ALPHA <= 0 29 | else # continuous-time 30 | alpha = 0; # 0 <= ALPHA <= 1 31 | endif 32 | 33 | endfunction 34 | -------------------------------------------------------------------------------- /inst/@frd/__ctranspose__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Conjugate transpose of FRD objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: May 2012 23 | ## Version: 0.1 24 | 25 | function sys = __ctranspose__ (sys) 26 | 27 | [p, m, l] = size (sys.H); 28 | 29 | H = mat2cell (sys.H, p, m, ones (1, l))(:); 30 | 31 | H = cellfun (@ctranspose, H, "uniformoutput", false); 32 | 33 | sys.H = cat (3, H{:}); 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/__modred_check_equil__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check equilibration for model reduction commands 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: November 2011 23 | ## Version: 0.1 24 | 25 | function scaled = __modred_check_equil__ (equil) 26 | 27 | if (isscalar (equil)) 28 | scaled = ! logical (equil); 29 | else 30 | error ("modred: property 'equil' must be a logical value"); 31 | endif 32 | 33 | endfunction 34 | -------------------------------------------------------------------------------- /inst/@tfpoly/mtimes.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Multiplication of two polynomials. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function a = mtimes (a, b) 26 | 27 | if (! isa (a, "tfpoly")) 28 | a = tfpoly (a); 29 | endif 30 | 31 | if (! isa (b, "tfpoly")) 32 | b = tfpoly (b); 33 | endif 34 | 35 | a.poly = conv (a.poly, b.poly); 36 | 37 | endfunction 38 | -------------------------------------------------------------------------------- /inst/__adjust_iddata__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## Author: Lukas Reichlin 19 | ## Created: February 2012 20 | ## Version: 0.1 21 | 22 | function [y, u] = __adjust_iddata__ (y, u) 23 | 24 | if (iscell (y)) 25 | y = reshape (y, [], 1); 26 | else 27 | y = {y}; 28 | endif 29 | 30 | if (isempty (u)) 31 | u = {}; # avoid [](nx0) and the like 32 | elseif (iscell (u)) 33 | u = reshape (u, [], 1); 34 | else 35 | u = {u}; 36 | endif 37 | 38 | endfunction 39 | -------------------------------------------------------------------------------- /inst/@lti/__sys_keys__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Stub function whose sole purpose is that function __lti_keys__ 20 | ## terminates correctly for pure LTI objects. This is needed in 21 | ## LTI subclasses for calls like @code{sys.lti.tsam}. For internal use only. 22 | 23 | ## Author: Lukas Reichlin 24 | ## Created: October 2015 25 | ## Version: 0.1 26 | 27 | function [keys, vals] = __sys_keys__ (sys) 28 | 29 | keys = vals = cell (0, 1); 30 | 31 | endfunction 32 | -------------------------------------------------------------------------------- /inst/@tfpoly/conj_ct.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Conjugate of continuous-time polynomial. Replace s by -s. 20 | ## For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: May 2012 24 | ## Version: 0.1 25 | 26 | function p = conj_ct (p) 27 | 28 | if (mod(numel(p.poly),2) == 0) 29 | #even powers of s 30 | p.poly(2:2:end) = -p.poly(2:2:end); 31 | else #odd 32 | p.poly(1:2:end) = -p.poly(1:2:end); 33 | endif 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /doc/SLICOT/README.md: -------------------------------------------------------------------------------- 1 | In the distributed control package archive `control-x.y.z.tar.gz`, this directory contains the license of the [SLICOT-Reference library](https://github.com/SLICOT/SLICOT-Reference), which is used by the control package. The SLICOT files are available under the *BSD 3-Clause License* which can be found in the file `LICENSE` in this directory or [in the SLICOT repository](https://github.com/SLICOT/SLICOT-Reference/blob/main/LICENSE). 2 | 3 | The original slicot `README.md` is available as `README-SLICOT.md` or [in the SLICOT repository](https://github.com/SLICOT/SLICOT-Reference/blob/main/README.md) as well. 4 | 5 | If you encounter any bugs in the octave control package, please 6 | DON'T bother the great people behind SLICOT. Most likely it's a 7 | problem of the control package, not the proven SLICOT library. 8 | Therefore, please send any reports to the [Octave bug tracker](https://savannah.gnu.org/projects/octave/) or the 9 | [Octave discourse platform](https://octave.discourse.group/). 10 | 11 | **Note**: The file `TG04BX.f` does not belong to SLICOT. It is a slightly extended version of the original SLICOT file `TB04BX.f`. The extension allows to handle descriptor system with `E` not being the identity matrix. The original SLICOT file is included as `TB04BX.f.orig` 12 | -------------------------------------------------------------------------------- /inst/@lti/issiso.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{bool} =} issiso (@var{sys}) 20 | ## Determine whether @acronym{LTI} model is single-input/single-output (SISO). 21 | ## 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: September 2009 26 | ## Version: 0.1 27 | 28 | function bool = issiso (sys) 29 | 30 | if (nargin != 1) 31 | print_usage (); 32 | endif 33 | 34 | bool = all (size (sys) == 1); 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/@lti/uplus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} uplus 20 | ## Unary plus of @acronym{LTI} object. Used by Octave for "+sys". 21 | ## 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: June 2012 26 | ## Version: 0.1 27 | 28 | function sys = uplus (sys) 29 | 30 | if (nargin != 1) # prevent sys = uplus (sys1, sys2, sys3, ...) 31 | error ("lti: uplus: this is an unary operator"); 32 | endif 33 | 34 | endfunction 35 | -------------------------------------------------------------------------------- /inst/@frd/__sys2tf__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## FRD to TF conversion. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function [retsys, retlti] = __sys2tf__ (sys) 26 | 27 | error ("frd: frd2tf: system identification not implemented yet"); 28 | 29 | retsys = tf (num, den, get (sys, "tsam")); # tsam needed to set appropriate tfvar 30 | retlti = sys.lti; # preserve lti properties 31 | 32 | endfunction 33 | -------------------------------------------------------------------------------- /inst/@ss/__transpose__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Transpose of SS models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: February 2010 23 | ## Version: 0.2 24 | 25 | function sys = __transpose__ (sys) 26 | 27 | a = sys.a; 28 | b = sys.b; 29 | c = sys.c; 30 | d = sys.d; 31 | e = sys.e; 32 | 33 | sys.stname = repmat ({""}, rows (a), 1); 34 | 35 | sys.a = a.'; 36 | sys.b = c.'; 37 | sys.c = b.'; 38 | sys.d = d.'; 39 | sys.e = e.'; 40 | 41 | endfunction 42 | -------------------------------------------------------------------------------- /inst/@frd/__get__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Access key values of FRD objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.2 24 | 25 | function val = __get__ (sys, key) 26 | 27 | switch (key) # {, } 28 | case {"h", "response"} 29 | val = sys.H; 30 | case {"w", "frequency"} 31 | val = sys.w; 32 | otherwise 33 | error ("frd: get: invalid key name '%s'", key); 34 | endswitch 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/@ss/__sys2frd__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## SS to FRD conversion. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function [retsys, retlti] = __sys2frd__ (sys, w = []) 26 | 27 | if (isempty (w)) # case sys = frd (sys) 28 | w = __frequency_vector__ (sys); 29 | endif 30 | 31 | H = freqresp (sys, w); 32 | 33 | retsys = frd (H, w); # tsam is set below 34 | retlti = sys.lti; # preserve lti properties 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/@tf/__sys2frd__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## TF to FRD conversion. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.1 24 | 25 | function [retsys, retlti] = __sys2frd__ (sys, w = []) 26 | 27 | if (isempty (w)) # case sys = frd (sys) 28 | w = __frequency_vector__ (sys); 29 | endif 30 | 31 | H = freqresp (sys, w); 32 | 33 | retsys = frd (H, w); # tsam is set below 34 | retlti = sys.lti; # preserve lti properties 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/append.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{sys} =} append (@var{sys1}, @var{sys2}, @dots{}, @var{sysN}) 20 | ## Group @acronym{LTI} models by appending their inputs and outputs. 21 | ## 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: September 2009 26 | ## Version: 0.2 27 | 28 | function sys = append (varargin) 29 | 30 | if (nargin == 0) 31 | print_usage (); 32 | endif 33 | 34 | sys = blkdiag (varargin{:}); 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/@lti/blkdiag.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{sys} =} blkdiag (@var{sys1}, @var{sys2}, @dots{}, @var{sysN}) 20 | ## Block-diagonal concatenation of @acronym{LTI} models. 21 | ## 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: September 2009 26 | ## Version: 0.2 27 | 28 | function sys = blkdiag (varargin) 29 | 30 | sys = varargin{1}; 31 | 32 | for k = 2 : nargin 33 | sys = __sys_group__ (sys, varargin{k}); 34 | endfor 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/__modred_check_alpha_gram__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check alpha for combination methods of grammians 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: December 2011 23 | ## Version: 0.1 24 | 25 | function alpha = __modred_check_alpha_gram__ (alpha, key) 26 | 27 | if (! is_real_scalar (alpha)) 28 | error ("modred: argument '%s' must be a real scalar", key); 29 | endif 30 | 31 | if (abs (alpha) > 1) 32 | error ("modred: require -1 <= %s <= 1", key); 33 | endif 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@tfpoly/__make_equally_long__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Make two polynomials equally long by adding leading zeros 20 | ## to the shorter one. For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: September 2009 24 | ## Version: 0.1 25 | 26 | function [a, b] = __make_equally_long__ (a, b) 27 | 28 | la = length (a.poly); 29 | lb = length (b.poly); 30 | lmax = max (la, lb); 31 | 32 | a.poly = [zeros(1, lmax-la), a.poly]; 33 | b.poly = [zeros(1, lmax-lb), b.poly]; 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@tf/__sys_prune__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Submodel extraction and reordering for TF objects. 20 | ## This file is part of the Model Abstraction Layer. 21 | ## For internal use only. 22 | 23 | ## Author: Lukas Reichlin 24 | ## Created: October 2009 25 | ## Version: 0.1 26 | 27 | function sys = __sys_prune__ (sys, out_idx, in_idx) 28 | 29 | [sys.lti, out_idx, in_idx] = __lti_prune__ (sys.lti, out_idx, in_idx); 30 | 31 | sys.num = sys.num(out_idx, in_idx); 32 | sys.den = sys.den(out_idx, in_idx); 33 | 34 | endfunction 35 | -------------------------------------------------------------------------------- /inst/@tfpoly/plus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Addition of two polynomials. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function a = plus (a, b) 26 | 27 | if (! isa (a, "tfpoly")) 28 | a = tfpoly (a); 29 | endif 30 | 31 | if (! isa (b, "tfpoly")) 32 | b = tfpoly (b); 33 | endif 34 | 35 | [a, b] = __make_equally_long__ (a, b); 36 | 37 | a.poly = a.poly + b.poly; 38 | 39 | a = __remove_leading_zeros__ (a); 40 | 41 | endfunction 42 | -------------------------------------------------------------------------------- /inst/@tf/__make_tf_polys_equally_long__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2021 Torsten Lilge 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Make all corresponding num and den polynomials of a transfer function 20 | ## equally long by adding leading zeros to the shorter one. 21 | ## For internal use only. 22 | 23 | 24 | function [num, den] = __make_tf_polys_equally_long__ (sys) 25 | 26 | num = sys.num; 27 | den = sys.den; 28 | 29 | for i = 1:size (num,1) 30 | for j = 1:size (num,2) 31 | [num{i,j},den{i,j}] = __make_equally_long__ (num{i,j},den{i,j}); 32 | endfor 33 | endfor 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@tfpoly/__remove_leading_zeros__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Remove leading zeros from a polynomial, except for polynomials 20 | ## which are of length 1. For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: September 2009 24 | ## Version: 0.2 25 | 26 | function p = __remove_leading_zeros__ (p) 27 | 28 | idx = find (p.poly != 0); 29 | 30 | if (isempty (idx)) 31 | p.poly = 0; 32 | else 33 | p.poly = p.poly(idx(1) : end); # p.poly(idx) would remove all zeros 34 | endif 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/@tfpoly/minus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Subtraction of two polynomials. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function a = minus (a, b) 26 | 27 | if (! isa (a, "tfpoly")) 28 | a = tfpoly (a); 29 | endif 30 | 31 | if (! isa (b, "tfpoly")) 32 | b = tfpoly (b); 33 | endif 34 | 35 | [a, b] = __make_equally_long__ (a, b); 36 | 37 | a.poly = a.poly - b.poly; 38 | 39 | a = __remove_leading_zeros__ (a); 40 | 41 | endfunction 42 | -------------------------------------------------------------------------------- /inst/__opt2cell__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Convert option struct to a cell with field names as keys and 20 | ## field values as values. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: November 2011 24 | ## Version: 0.1 25 | 26 | function c = __opt2cell__ (opt) 27 | 28 | if (! isstruct (opt)) 29 | error ("opt2cell: argument must be a struct"); 30 | endif 31 | 32 | key = fieldnames (opt); 33 | val = struct2cell (opt); 34 | 35 | c = [key.'; val.'](:).'; # reshape to {key1, val1, key2, val2, ...} 36 | 37 | endfunction 38 | -------------------------------------------------------------------------------- /inst/@frd/__sys_prune__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Submodel extraction and reordering for FRD objects. 20 | ## This file is part of the Model Abstraction Layer. 21 | ## For internal use only. 22 | 23 | ## Author: Lukas Reichlin 24 | ## Created: October 2010 25 | ## Version: 0.2 26 | 27 | function sys = __sys_prune__ (sys, out_idx, in_idx, w_idx = ":") 28 | 29 | [sys.lti, out_idx, in_idx] = __lti_prune__ (sys.lti, out_idx, in_idx); 30 | 31 | sys.H = sys.H(out_idx, in_idx, w_idx); 32 | 33 | sys.w = sys.w(w_idx); 34 | 35 | endfunction 36 | -------------------------------------------------------------------------------- /inst/@lti/uminus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} uminus 20 | ## Unary minus of @acronym{LTI} object. Used by Octave for "-sys". 21 | ## 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: September 2009 26 | ## Version: 0.1 27 | 28 | function sys = uminus (sys) 29 | 30 | if (nargin != 1) # prevent sys = uminus (sys1, sys2, sys3, ...) 31 | error ("lti: uminus: this is an unary operator"); 32 | endif 33 | 34 | [p, m] = size (sys); 35 | 36 | out_scl = - eye (p); 37 | 38 | sys = out_scl * sys; 39 | 40 | endfunction 41 | -------------------------------------------------------------------------------- /inst/__remove_leading_zeros__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2024 Torsten Lilge 2 | ## 3 | ## This file is part of GNU Octave's Control Package. 4 | ## 5 | ## This file free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## This file is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Remove leading zeros from a polynomial or a cell array of polynomials. 20 | ## polynomials of length one are not changed. For internal use only. 21 | 22 | ## Author: Torsten Lilge 23 | 24 | function p = __remove_leading_zeros__ (p) 25 | 26 | if (isa (p, "cell")) 27 | p = cellfun (@__remove_leading_zeros__, p, "uniformoutput", false); 28 | return; 29 | endif 30 | 31 | idx = find (p != 0); 32 | 33 | if (isempty (idx)) 34 | return; 35 | else 36 | p = p(idx(1):end); 37 | endif 38 | 39 | endfunction 40 | -------------------------------------------------------------------------------- /inst/@tf/__zero__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Transmission zeros of TF object. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.3 24 | 25 | function [zer, gain, info] = __zero__ (sys, ~) 26 | 27 | if (issiso (sys)) 28 | num = get (sys.num{1}); 29 | den = get (sys.den{1}); 30 | zer = roots (num); 31 | gain = num(1) / den(1); 32 | info = []; 33 | else 34 | warning ("tf: zero: converting to minimal state-space for zero computation of mimo tf\n"); 35 | [zer, gain, info] = zero (ss (sys)); 36 | endif 37 | 38 | endfunction 39 | -------------------------------------------------------------------------------- /inst/__tf_dim__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Number of outputs and inputs of transfer function numerator and 20 | ## denominator. For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2009 24 | ## Version: 0.3 25 | 26 | function [nrows, ncols] = __tf_dim__ (num, den) 27 | 28 | [nrows, ncols] = size (num); 29 | [drows, dcols] = size (den); 30 | 31 | if (nrows != drows || ncols != dcols) 32 | error ("tf: arguments 'num' (%dx%d) and 'den' (%dx%d) must have equal dimensions", 33 | nrows, ncols, drows, dcols); 34 | endif 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/__is_stable__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Determine whether all poles in a vector are stable. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: December 2010 23 | ## Version: 0.2 24 | 25 | function bool = __is_stable__ (pol, ct = true, tol = 0) 26 | 27 | if (! is_real_scalar (tol) || tol < 0) 28 | error ("isstable: tolerance must be a real-valued, non-negative scalar"); 29 | endif 30 | 31 | if (ct) # continuous-time 32 | bool = all (real (pol) < -tol*(1 + abs (pol))); 33 | else # discrete-time 34 | bool = all (abs (pol) < 1 - tol); 35 | endif 36 | 37 | endfunction 38 | -------------------------------------------------------------------------------- /inst/__modred_check_order__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check order for model reduction commands 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: November 2011 23 | ## Version: 0.1 24 | 25 | function [nr, ordsel] = __modred_check_order__ (nr, n) 26 | 27 | if (! issample (nr, 0) || nr != round (nr)) 28 | error ("modred: order of reduced model must be an integer >= 0"); 29 | endif 30 | 31 | if (nr > n) 32 | error ("modred: order of reduced model (%d) can't be larger than the original one (%d)", ... 33 | nr, n); 34 | endif 35 | 36 | ordsel = 0; 37 | 38 | endfunction 39 | -------------------------------------------------------------------------------- /inst/__conred_check_feedback_sign__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check the feedback sign. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: December 2011 23 | ## Version: 0.1 24 | 25 | function negfb = __conred_check_feedback_sign__ (fbsign, key = "feedback") 26 | 27 | if (! ischar (fbsign)) 28 | error ("conred: key '%s' requires string value", key); 29 | endif 30 | 31 | switch (fbsign) 32 | case "+" 33 | negfb = false; 34 | case "-" 35 | negfb = true; 36 | otherwise 37 | error ("conred: key '%s' has an invalid value", key); 38 | endswitch 39 | 40 | endfunction 41 | -------------------------------------------------------------------------------- /inst/__remove_trailing_zeros__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Remove trailing zeros from a polynomial, except for polynomials 20 | ## which are of length 1. For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: April 2012 24 | ## Version: 0.1 25 | 26 | function p = __remove_trailing_zeros__ (p) 27 | 28 | if (isa (p, "cell")) 29 | p = cellfun (@__remove_trailing_zeros__, p, "uniformoutput", false); 30 | return; 31 | endif 32 | 33 | idx = find (p != 0); 34 | 35 | if (isempty (idx)) 36 | p = 0; 37 | else 38 | p = p(1 : idx(end)); 39 | endif 40 | 41 | endfunction 42 | -------------------------------------------------------------------------------- /inst/@ss/__pole__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Poles of SS object. 20 | 21 | ## Special thanks to Peter Benner for his advice. 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2009 24 | ## Version: 0.4 25 | 26 | function pol = __pole__ (sys) 27 | 28 | if (isempty (sys.e)) 29 | pol = eig (sys.a); 30 | else 31 | ## pol = eig (sys.a, sys.e); 32 | ## tol = norm ([sys.a, sys.e], 2); 33 | ## idx = find (abs (pol) < tol/eps); 34 | ## pol = pol(idx); 35 | ## do not scale, matrices B, C & D missing 36 | pol = __sl_ag08bd__ (sys.a, sys.e, [], [], [], true); 37 | endif 38 | 39 | endfunction 40 | -------------------------------------------------------------------------------- /inst/@iddata/merge.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{dat} =} merge (@var{dat1}, @var{dat2}, @dots{}) 20 | ## Concatenate experiments of iddata datasets. 21 | ## The experiments are concatenated in the following way: 22 | ## @code{dat.y = [dat1.y; dat2.y; @dots{}]} 23 | ## @code{dat.u = [dat1.u; dat2.u; @dots{}]} 24 | ## The number of outputs and inputs must be equal for all datasets. 25 | ## 26 | ## @end deftypefn 27 | 28 | ## Author: Lukas Reichlin 29 | ## Created: March 2012 30 | ## Version: 0.1 31 | 32 | function dat = merge (varargin) 33 | 34 | dat = cat (3, varargin{:}); 35 | 36 | endfunction 37 | -------------------------------------------------------------------------------- /inst/__labels__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Return default labels if cell "name" contains only empty strings. 20 | ## If not, check whether individual strings of the cell "name" are 21 | ## empty and mark them with "?". Used by display routines. 22 | 23 | ## Author: Lukas Reichlin 24 | ## Created: October 2009 25 | ## Version: 0.3 26 | 27 | function [name, n] = __labels__ (name, variable = "x") 28 | 29 | n = numel (name); 30 | 31 | if (n == 0 || isequal ("", name{:})) 32 | name = strseq (variable, 1:n); 33 | else 34 | idx = cellfun (@isempty, name); 35 | name(idx) = "?"; 36 | endif 37 | 38 | endfunction 39 | -------------------------------------------------------------------------------- /inst/__modred_check_gram__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check choice of frequency-weighted grammians. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: December 2011 23 | ## Version: 0.1 24 | 25 | function job = __modred_check_gram__ (choice, key) 26 | 27 | if (! ischar (choice)) 28 | error ("modred: key '%s' requires string value", key); 29 | endif 30 | 31 | switch (tolower (choice (1))) 32 | case "s" # standard 33 | job = 0; 34 | case "e" # enhanced 35 | job = 1; 36 | otherwise 37 | error ("modred: key '%s' has an invalid value", key); 38 | endswitch 39 | 40 | endfunction 41 | -------------------------------------------------------------------------------- /doc/references.txt: -------------------------------------------------------------------------------- 1 | REFERENCES 2 | ********** 3 | 4 | German 5 | ****** 6 | 7 | Geering, H.P. 8 | Regelungstechnik 9 | Springer 10 | 2004 11 | 12 | Meyer, M. 13 | Signalverarbeitung 14 | Vieweg & Teubner 15 | 2009 16 | 17 | 18 | English 19 | ******* 20 | 21 | Anderson, B.D.O. and Moore, J.B. 22 | Optimal Control 23 | Linear Quadratic Methods 24 | Dover Publications 25 | 1990 26 | 27 | Åström, K. and Hägglund, T. 28 | PID Controllers 29 | Theory, Design and Tuning 30 | Second Edition 31 | Instrument Society of America 32 | 1995 33 | 34 | Doyle, J.C., Francis, B.A. and Tannenbaum, A.R. 35 | Feedback Control Theory 36 | Dover Publications 37 | 1992 38 | 39 | Geering, H.P. 40 | Optimal Control with Engineering Applications 41 | Springer 42 | 2007 43 | 44 | Gu, D.W., Petkov, P.Hr. and Konstantinov, M.M. 45 | Robust Control with MATLAB 46 | Springer 47 | 2005 48 | 49 | Guzzella, L. 50 | Analysis and Design of SISO Control Systems 51 | VDF Hochschulverlag ETH Zurich 52 | 2007 53 | 54 | Kailath, T. 55 | Linear Systems 56 | Prentice Hall 57 | 1980 58 | 59 | Leigh, J.R. 60 | Applied Digital Control 61 | Theory, Design and Implementation 62 | Second Edition 63 | Dover Publications 64 | 1992 65 | 66 | Ljung, L. 67 | System Identification 68 | Theory for the User 69 | Second Edition 70 | Prentice Hall 71 | 1999 72 | 73 | Skogestad, S. and Postlethwaite, I. 74 | Multivariable Feedback Control 75 | Analysis and Design 76 | Second Edition 77 | Wiley 78 | 2005 79 | -------------------------------------------------------------------------------- /inst/@lti/size_equal.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{bool} =} size_equal (@var{a}, @var{b}, @dots{}) 20 | ## Return true if @acronym{LTI} models (and matrices) @var{a}, @var{b}, @dots{} 21 | ## are of equal size and false otherwise. 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: October 2012 26 | ## Version: 0.1 27 | 28 | function bool = size_equal (varargin) 29 | 30 | s = cellfun (@size, varargin, "uniformoutput", false); 31 | 32 | bool = (nargin == 1 || isequal (s{:})); # isequal errors out with only 1 argument, nargin==0 handled by built-in size_equal 33 | 34 | endfunction 35 | -------------------------------------------------------------------------------- /inst/__modred_check_alpha__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check alpha for model reduction commands 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: November 2011 23 | ## Version: 0.1 24 | 25 | function alpha = __modred_check_alpha__ (alpha, dt) 26 | 27 | if (! is_real_scalar (alpha)) 28 | error ("modred: argument alpha must be a real scalar"); 29 | endif 30 | if (dt) # discrete-time 31 | if (alpha < 0 || alpha > 1) 32 | error ("modred: require 0 <= ALPHA <= 1"); 33 | endif 34 | else # continuous-time 35 | if (alpha > 0) 36 | error ("modred: require ALPHA <= 0"); 37 | endif 38 | endif 39 | 40 | endfunction 41 | -------------------------------------------------------------------------------- /inst/@tfpoly/subsref.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Evaluate polynomial. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function b = subsref (a, s) 26 | 27 | if (isempty (s)) 28 | error ("tfpoly: missing index"); 29 | endif 30 | 31 | switch (s(1).type) 32 | case "()" 33 | idx = s(1).subs; 34 | if (numel (idx) == 1) 35 | b = polyval (a.poly, idx{1}); 36 | else 37 | error ("tfpoly: need exactly one index"); 38 | endif 39 | 40 | otherwise 41 | error ("tfpoly: invalid subscript type"); 42 | 43 | endswitch 44 | 45 | endfunction 46 | -------------------------------------------------------------------------------- /inst/@frd/__set__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Set or modify keys of FRD objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.2 24 | 25 | function sys = __set__ (sys, key, val) 26 | 27 | switch (key) # {, } 28 | case {"h", "response"} 29 | val = __adjust_frd_data__ (val, sys.w); 30 | __frd_dim__ (val, sys.w); 31 | sys.H = val; 32 | case {"w", "frequency"} 33 | [~, val] = __adjust_frd_data__ (sys.H, val); 34 | __frd_dim__ (sys.H, val); 35 | sys.w = val; 36 | otherwise 37 | error ("frd: set: invalid key name '%s'", key); 38 | endswitch 39 | 40 | endfunction 41 | -------------------------------------------------------------------------------- /inst/@lti/end.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} end 20 | ## End indexing for @acronym{LTI} objects. 21 | ## Used by Octave for "sys(1:end, end-1)". 22 | ## 23 | ## @end deftypefn 24 | 25 | ## Author: Lukas Reichlin 26 | ## Created: December 2013 27 | ## Version: 0.1 28 | 29 | function ret = end (sys, k, n) 30 | 31 | if (n != 2) 32 | error ("lti: end: require 2 indices in the expression"); 33 | endif 34 | 35 | [p, m] = size (sys); 36 | 37 | switch (k) 38 | case 1 39 | ret = p; 40 | case 2 41 | ret = m; 42 | otherwise 43 | error ("lti: end: invalid expression index k = %d", k); 44 | endswitch 45 | 46 | endfunction 47 | -------------------------------------------------------------------------------- /inst/@ss/__freqresp__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Frequency response of SS models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.6 24 | 25 | function H = __freqresp__ (sys, w, cellflag = false) 26 | 27 | if (sys.scaled == false) 28 | sys = prescale (sys); 29 | endif 30 | 31 | [a, b, c, d, e, tsam] = dssdata (sys); 32 | 33 | if (isct (sys)) # continuous system 34 | s = i * w; 35 | else # discrete system 36 | s = exp (i * w * abs (tsam)); 37 | endif 38 | 39 | H = arrayfun (@(x) c/(x*e - a)*b + d, s, "uniformoutput", false); 40 | 41 | if (! cellflag) 42 | H = cat (3, H{:}); 43 | endif 44 | 45 | endfunction 46 | -------------------------------------------------------------------------------- /inst/@tfpoly/mpower.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Power of a polynomial. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.1 24 | 25 | function p = mpower (a, b) 26 | 27 | if (! isa (b, "double") && ! is_real_scalar (b)) 28 | error ("tfpoly: mpower: power must be a natural number"); 29 | endif 30 | 31 | c = uint64 (b); 32 | 33 | if (c != b) 34 | error ("tfpoly: mpower: power must be a positive integer"); 35 | endif 36 | 37 | if (c == 0) 38 | p = tfpoly (1); 39 | return; 40 | endif 41 | 42 | p = a; 43 | 44 | for k = 1 : (c-1) 45 | p.poly = conv (p.poly, a.poly); 46 | endfor 47 | 48 | endfunction 49 | -------------------------------------------------------------------------------- /inst/@ss/__get__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Access key values of SS objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.3 24 | 25 | function val = __get__ (sys, key) 26 | 27 | switch (key) # {, } 28 | case "a" 29 | val = sys.a; 30 | case "b" 31 | val = sys.b; 32 | case "c" 33 | val = sys.c; 34 | case "d" 35 | val = sys.d; 36 | case "e" 37 | val = sys.e; 38 | case {"stname", "statename"} 39 | val = sys.stname; 40 | case "scaled" 41 | val = sys.scaled; 42 | otherwise 43 | error ("ss: get: invalid key name '%s'", key); 44 | endswitch 45 | 46 | endfunction 47 | -------------------------------------------------------------------------------- /inst/@iddata/vertcat.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{dat} =} vertcat (@var{dat1}, @var{dat2}, @dots{}) 20 | ## Vertical concatenation of iddata datasets. 21 | ## The samples are concatenated in the following way: 22 | ## @code{dat.y@{e@} = [dat1.y@{e@}; dat2.y@{e@}; @dots{}]} 23 | ## @code{dat.u@{e@} = [dat1.u@{e@}; dat2.u@{e@}; @dots{}]} 24 | ## where @var{e} denotes the experiment. 25 | ## The number of experiments, outputs and inputs must be equal for all datasets. 26 | ## 27 | ## @end deftypefn 28 | 29 | ## Author: Lukas Reichlin 30 | ## Created: March 2012 31 | ## Version: 0.1 32 | 33 | function dat = vertcat (varargin) 34 | 35 | dat = cat (1, varargin{:}); 36 | 37 | endfunction 38 | -------------------------------------------------------------------------------- /inst/@iddata/horzcat.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{dat} =} horzcat (@var{dat1}, @var{dat2}, @dots{}) 20 | ## Horizontal concatenation of iddata datasets. 21 | ## 22 | ## The outputs and inputs are concatenated in the following way: 23 | ## @code{dat.y@{e@} = [dat1.y@{e@}, dat2.y@{e@}, @dots{}]} 24 | ## @code{dat.u@{e@} = [dat1.u@{e@}, dat2.u@{e@}, @dots{}]} 25 | ## where @var{e} denotes the experiment. 26 | ## The number of experiments and samples must be equal for all datasets. 27 | ## 28 | ## @end deftypefn 29 | 30 | ## Author: Lukas Reichlin 31 | ## Created: March 2012 32 | ## Version: 0.1 33 | 34 | function dat = horzcat (varargin) 35 | 36 | dat = cat (2, varargin{:}); 37 | 38 | endfunction 39 | -------------------------------------------------------------------------------- /inst/__str2idx__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Get input/output indices from in/outgroup and in/outname. 20 | ## For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2013 24 | ## Version: 0.1 25 | 26 | function idx = __str2idx__ (group, name, str, id) 27 | 28 | if (isfield (group, str)) 29 | idx = group.(str)(:); 30 | else 31 | tmp = strcmp (name, str)(:); 32 | switch (nnz (tmp)) 33 | case 1 34 | idx = find (tmp); 35 | case 0 36 | error ("lti: %sgroup or %sname '%s' not found", id, id, str); 37 | otherwise 38 | error ("lti: %sname '%s' is ambiguous", id, str); 39 | ## FIXME: error for structure arrays 40 | endswitch 41 | endif 42 | 43 | endfunction 44 | -------------------------------------------------------------------------------- /inst/strseq.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{strvec} =} strseq (@var{str}, @var{idx}) 20 | ## Return a cell vector of indexed strings by appending the indices @var{idx} 21 | ## to the string @var{str}. 22 | ## 23 | ## @example 24 | ## strseq ("x", 1:3) = @{"x1"; "x2"; "x3"@} 25 | ## strseq ("u", [1, 2, 5]) = @{"u1"; "u2"; "u5"@} 26 | ## @end example 27 | ## @end deftypefn 28 | 29 | ## Author: Lukas Reichlin 30 | ## Created: September 2009 31 | ## Version: 0.3 32 | 33 | function strvec = strseq (str, idx) 34 | 35 | if (nargin != 2 || ! ischar (str) || ! isnumeric (idx)) 36 | print_usage (); 37 | endif 38 | 39 | strvec = arrayfun (@(x) sprintf ("%s%d", str, x), idx(:), "uniformoutput", false); 40 | 41 | endfunction 42 | -------------------------------------------------------------------------------- /inst/@ss/isstaticgain.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2022 Torsten Lilge 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{bool} =} isstaticgain (@var{sys}) 20 | ## Determine whether @acronym{LTI} model is a static gain. 21 | ## 22 | ## @strong{Inputs} 23 | ## @table @var 24 | ## @item sys 25 | ## @acronym{LTI} system. 26 | ## @end table 27 | ## 28 | ## @strong{Outputs} 29 | ## @table @var 30 | ## @item bool = 0 31 | ## @var{sys} is a dynamical system 32 | ## @item bool = 1 33 | ## @var{sys} is a static gain 34 | ## @end table 35 | ## @end deftypefn 36 | 37 | ## Author: Torsten Lilge 38 | ## Created: October 2022 39 | ## Version: 0.1 40 | 41 | function static_gain = isstaticgain (ltisys) 42 | 43 | if (nargin == 0) 44 | print_usage (); 45 | endif 46 | 47 | static_gain = isempty (ltisys.a); 48 | 49 | endfunction 50 | -------------------------------------------------------------------------------- /inst/@iddata/diff.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{dat} =} diff (@var{dat}) 20 | ## @deftypefnx {Function File} {@var{dat} =} diff (@var{dat}, @var{k}) 21 | ## Return @var{k}-th difference of outputs and inputs of dataset @var{dat}. 22 | ## If @var{k} is not specified, default value 1 is taken. 23 | ## 24 | ## @end deftypefn 25 | 26 | ## Author: Lukas Reichlin 27 | ## Created: March 2012 28 | ## Version: 0.1 29 | 30 | function dat = diff (dat, k = 1) 31 | 32 | if (nargin > 2) # no need to test nargin == 0, this is handled by built-in diff 33 | print_usage (); 34 | endif 35 | 36 | dat.y = cellfun (@diff, dat.y, {k}, {1}, "uniformoutput", false); 37 | dat.u = cellfun (@diff, dat.u, {k}, {1}, "uniformoutput", false); 38 | 39 | endfunction 40 | -------------------------------------------------------------------------------- /inst/@lti/isct.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{bool} =} isct (@var{sys}) 20 | ## Determine whether @acronym{LTI} model is a continuous-time system. 21 | ## 22 | ## @strong{Inputs} 23 | ## @table @var 24 | ## @item sys 25 | ## @acronym{LTI} system. 26 | ## @end table 27 | ## 28 | ## @strong{Outputs} 29 | ## @table @var 30 | ## @item bool = 0 31 | ## @var{sys} is a discrete-time system. 32 | ## @item bool = 1 33 | ## @var{sys} is a continuous-time system or a static gain. 34 | ## @end table 35 | ## @end deftypefn 36 | 37 | ## Author: Lukas Reichlin 38 | ## Created: September 2009 39 | ## Version: 0.1 40 | 41 | function bool = isct (ltisys) 42 | 43 | if (nargin != 1) 44 | print_usage (); 45 | endif 46 | 47 | bool = (ltisys.tsam == 0); 48 | 49 | endfunction 50 | -------------------------------------------------------------------------------- /inst/@tfpoly/tfpoly.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Class constructor. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.2 24 | 25 | function p = tfpoly (a) 26 | 27 | superiorto ("double"); 28 | 29 | switch (nargin) 30 | case 0 31 | p = struct ("poly", []); 32 | p = class (p, "tfpoly"); 33 | 34 | case 1 35 | if (isa (a, "tfpoly")) 36 | p = a; 37 | return; 38 | elseif (is_real_vector (a)) 39 | p.poly = reshape (a, 1, []); 40 | p = class (p, "tfpoly"); 41 | p = __remove_leading_zeros__ (p); 42 | else 43 | error ("tfpoly: argument must be a real-valued vector"); 44 | endif 45 | 46 | otherwise 47 | print_usage (); 48 | 49 | endswitch 50 | 51 | endfunction 52 | -------------------------------------------------------------------------------- /inst/db2mag.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{mag} =} db2mag (@var{db}) 20 | ## Convert Decibels (dB) to Magnitude. 21 | ## 22 | ## @strong{Inputs} 23 | ## @table @var 24 | ## @item db 25 | ## Decibel (dB) value(s). Both real-valued scalars and matrices are accepted. 26 | ## @end table 27 | ## 28 | ## @strong{Outputs} 29 | ## @table @var 30 | ## @item mag 31 | ## Magnitude value(s). 32 | ## @end table 33 | ## 34 | ## @seealso{mag2db} 35 | ## @end deftypefn 36 | 37 | ## Author: Lukas Reichlin 38 | ## Created: November 2012 39 | ## Version: 0.1 40 | 41 | function mag = db2mag (db) 42 | 43 | if (nargin != 1 || ! is_real_matrix (db)) 44 | print_usage (); 45 | endif 46 | 47 | mag = 10.^(db./20); 48 | 49 | endfunction 50 | 51 | 52 | %!assert (db2mag (40), 100); 53 | %!assert (db2mag (-20), 0.1); 54 | -------------------------------------------------------------------------------- /inst/__modred_check_weight__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## check weightings for model reduction commands 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: November 2011 23 | ## Version: 0.1 24 | 25 | function [a, b, c, d, job] = __modred_check_weight__ (sys, dt, p = [], m = []) 26 | 27 | sys = ss (sys); # could be non-lti, therefore ssdata would fail 28 | 29 | if (dt != isdt (sys)) 30 | error ("modred: ct/dt"); # TODO: error message 31 | endif 32 | 33 | [pw, mw] = size (sys); 34 | 35 | if (! isempty (p) && mw != p) 36 | error ("modred: left weight requires %d inputs", p); 37 | endif 38 | 39 | if (! isempty (m) && pw != m) 40 | error ("modred: right weight requires %d outputs", m); 41 | endif 42 | 43 | [a, b, c, d] = ssdata (sys); 44 | 45 | job = 1; 46 | 47 | ## TODO: check system size 48 | 49 | endfunction 50 | -------------------------------------------------------------------------------- /inst/repsys.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{rsys} =} repsys (@var{sys}, @var{m}, @var{n}) 20 | ## @deftypefnx {Function File} {@var{rsys} =} repsys (@var{sys}, [@var{m}, @var{n}]) 21 | ## @deftypefnx {Function File} {@var{rsys} =} repsys (@var{sys}, @var{m}) 22 | ## Form a block transfer matrix of @var{sys} with @var{m} copies vertically 23 | ## and @var{n} copies horizontally. If @var{n} is not specified, it is set to @var{m}. 24 | ## @code{repsys (sys, 2, 3)} is equivalent to @code{[sys, sys, sys; sys, sys, sys]}. 25 | ## @end deftypefn 26 | 27 | ## Author: Lukas Reichlin 28 | ## Created: May 2014 29 | ## Version: 0.1 30 | 31 | function sys = repsys (varargin) 32 | 33 | if (nargin == 0) 34 | print_usage (); 35 | endif 36 | 37 | sys = repmat (varargin{:}); # repmat is overloaded for LTI systems 38 | 39 | endfunction 40 | -------------------------------------------------------------------------------- /inst/mag2db.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{db} =} mag2db (@var{mag}) 20 | ## Convert Magnitude to Decibels (dB). 21 | ## 22 | ## @strong{Inputs} 23 | ## @table @var 24 | ## @item mag 25 | ## Magnitude value(s). Both real-valued scalars and matrices are accepted. 26 | ## @end table 27 | ## 28 | ## @strong{Outputs} 29 | ## @table @var 30 | ## @item db 31 | ## Decibel (dB) value(s). 32 | ## @end table 33 | ## 34 | ## @seealso{db2mag} 35 | ## @end deftypefn 36 | 37 | ## Author: Lukas Reichlin 38 | ## Created: November 2012 39 | ## Version: 0.1 40 | 41 | function db = mag2db (mag) 42 | 43 | if (nargin != 1 || ! is_real_matrix (mag)) 44 | print_usage (); 45 | endif 46 | 47 | db = 20 .* log10 (mag); 48 | db(mag < 0) = NaN; 49 | 50 | endfunction 51 | 52 | 53 | %!assert (mag2db (100), 40); 54 | %!assert (mag2db (0.1), -20); 55 | -------------------------------------------------------------------------------- /inst/@lti/transpose.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} transpose 20 | ## Transpose of @acronym{LTI} objects. Used by Octave for "sys.'". 21 | ## Useful for dual problems, i.e. controllability and observability 22 | ## or designing estimator gains with @command{lqr} and @command{place}. 23 | ## 24 | ## @end deftypefn 25 | 26 | ## Author: Lukas Reichlin 27 | ## Created: February 2010 28 | ## Version: 0.2 29 | 30 | function sys = transpose (sys) 31 | 32 | if (nargin != 1) # prevent sys = transpose (sys1, sys2, sys3, ...) 33 | error ("lti: transpose: this is an unary operator"); 34 | endif 35 | 36 | [p, m] = size (sys); 37 | 38 | sys = __transpose__ (sys); 39 | 40 | sys.inname = repmat ({""}, p, 1); 41 | sys.outname = repmat ({""}, m, 1); 42 | sys.ingroup = struct (); 43 | sys.outgroup = struct (); 44 | 45 | endfunction 46 | -------------------------------------------------------------------------------- /inst/@frd/__sys_keys__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This program is free software: you can redistribute it and/or modify 4 | ## it under the terms of the GNU General Public License as published by 5 | ## the Free Software Foundation, either version 3 of the License, or 6 | ## (at your option) any later version. 7 | ## 8 | ## This program is distributed in the hope that it will be useful, 9 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | ## GNU General Public License for more details. 12 | ## 13 | ## You should have received a copy of the GNU General Public License 14 | ## along with this program. If not, see . 15 | 16 | ## -*- texinfo -*- 17 | ## @deftypefn {Function File} {[@var{keys}, @var{vals}] =} __sys_keys__ (@var{sys}) 18 | ## @deftypefnx {Function File} {[@var{keys}, @var{vals}] =} __sys_keys__ (@var{sys}, @var{aliases}) 19 | ## Return the list of keys as well as the assignable values for a frd object sys. 20 | ## @end deftypefn 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2010 24 | ## Version: 0.3 25 | 26 | function [keys, vals] = __sys_keys__ (sys, aliases = false) 27 | 28 | ## cell vector of frd-specific keys 29 | keys = {"H"; 30 | "w"}; 31 | 32 | ## cell vector of frd-specific assignable values 33 | vals = {"p-by-m-by-l array of complex frequency responses"; 34 | "l-by-1 vector of real frequencies (l = length (w))"}; 35 | 36 | if (aliases) 37 | ka = {"response"; 38 | "frequency"}; 39 | keys = [keys; ka]; 40 | endif 41 | 42 | endfunction 43 | -------------------------------------------------------------------------------- /inst/@lti/lti.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Constructor for LTI objects. For internal use only. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.2 24 | 25 | function ltisys = lti (p = 0, m = 0, tsam = -1) 26 | 27 | if (nargin != 3 || ! is_real_scalar (p, m, tsam)) 28 | error ("lti: constructor for 'lti' class, intended for internal use only"); 29 | endif 30 | 31 | inname = repmat ({""}, m, 1); 32 | outname = repmat ({""}, p, 1); 33 | 34 | ltisys = struct ("tsam", tsam, 35 | "inname", {inname}, 36 | "outname", {outname}, 37 | "ingroup", struct (), 38 | "outgroup", struct (), 39 | "name", "", 40 | "notes", {{}}, 41 | "userdata", []); 42 | 43 | ltisys = class (ltisys, "lti"); 44 | 45 | endfunction 46 | -------------------------------------------------------------------------------- /inst/@tf/__freqresp__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Frequency response of TF models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.5 24 | 25 | function H = __freqresp__ (sys, w, cellflag = false) 26 | 27 | [num, den, tsam] = tfdata (sys, "vector"); 28 | 29 | if (isct (sys)) # continuous system 30 | s = i * w; 31 | else # discrete system 32 | s = exp (i * w * abs (tsam)); 33 | endif 34 | 35 | s = reshape (s, 1, 1, []); 36 | 37 | if (issiso (sys)) 38 | H = polyval (num, s) ./ polyval (den, s); 39 | else 40 | H = cellfun (@(x, y) polyval (x, s) ./ polyval (y, s), num, den, "uniformoutput", false); 41 | H = cell2mat (H); 42 | endif 43 | 44 | if (cellflag) 45 | [p, m] = size (sys); 46 | l = length (s); 47 | H = mat2cell (H, p, m, ones (1, l))(:); 48 | endif 49 | 50 | endfunction 51 | -------------------------------------------------------------------------------- /inst/@tf/__sys_inverse__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Inversion of TF models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.4 24 | 25 | function sys = __sys_inverse__ (sys) 26 | 27 | if (issiso (sys)) # SISO 28 | num = sys.num; 29 | den = sys.den; 30 | if (num{1,1} == 0) # catch case num = 0 31 | sys.num(1,1) = tfpoly (0); 32 | sys.den(1,1) = tfpoly (1); 33 | else 34 | sys.num = den; 35 | sys.den = num; 36 | endif 37 | else # MIMO 38 | ## I've calculated TF inversion of 2x2 and 3x3 systems with Sage CAS, 39 | ## but the formulae give systems with very high orders, therefore 40 | ## I always use the conversion to state-space and back. 41 | [num, den] = tfdata (inv (ss (sys)), "tfpoly"); 42 | sys.num = num; 43 | sys.den = den; 44 | endif 45 | 46 | endfunction 47 | -------------------------------------------------------------------------------- /inst/@lti/vertcat.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} vertcat 20 | ## Vertical concatenation of @acronym{LTI} objects. If necessary, object conversion 21 | ## is done by sys_group. Used by Octave for "[sys1; sys2]". 22 | ## 23 | ## @end deftypefn 24 | 25 | ## Author: Lukas Reichlin 26 | ## Created: September 2009 27 | ## Version: 0.1 28 | 29 | function sys = vertcat (sys, varargin) 30 | 31 | for k = 1 : (nargin-1) 32 | 33 | sys1 = sys; 34 | sys2 = varargin{k}; 35 | 36 | [p1, m1] = size (sys1); 37 | [p2, m2] = size (sys2); 38 | 39 | if (m1 != m2) 40 | error ("lti: vertcat: number of system inputs incompatible: [(%dx%d); (%dx%d)]", 41 | p1, m1, p2, m2); 42 | endif 43 | 44 | sys = __sys_group__ (sys1, sys2); 45 | 46 | in_scl = [eye(m1); eye(m2)]; 47 | 48 | sys = sys * in_scl; 49 | 50 | endfor 51 | 52 | endfunction 53 | -------------------------------------------------------------------------------- /inst/@ss/__ctranspose__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Conjugate transpose of SS models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: May 2012 23 | ## Version: 0.1 24 | 25 | function sys = __ctranspose__ (sys, ct) 26 | 27 | a = sys.a; 28 | b = sys.b; 29 | c = sys.c; 30 | d = sys.d; 31 | e = sys.e; 32 | 33 | if (ct) # continuous-time 34 | sys.a = -a.'; 35 | sys.b = -c.'; 36 | sys.c = b.'; 37 | sys.d = d.'; 38 | sys.e = e.'; 39 | sys.stname = repmat ({""}, rows (a), 1); 40 | else # discrete-time 41 | [n, m] = size (b); 42 | p = rows (c); 43 | if (isempty (e)) 44 | e = eye (n); 45 | endif 46 | sys.a = blkdiag (e.', eye (p)); 47 | sys.b = [zeros(n, p); -eye(p)]; 48 | sys.c = [b.', zeros(m, p)]; 49 | sys.d = d.'; 50 | sys.e = [a.', c.'; zeros(p, n+p)]; 51 | sys.stname = repmat ({""}, n+p, 1); 52 | endif 53 | 54 | endfunction 55 | -------------------------------------------------------------------------------- /inst/@lti/isdt.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{bool} =} isdt (@var{sys}) 20 | ## Determine whether @acronym{LTI} model is a discrete-time system. 21 | ## 22 | ## @strong{Inputs} 23 | ## @table @var 24 | ## @item sys 25 | ## @acronym{LTI} system. 26 | ## @end table 27 | ## 28 | ## @strong{Outputs} 29 | ## @table @var 30 | ## @item bool = 0 31 | ## @var{sys} is a continuous-time system. 32 | ## @item bool = 1 33 | ## @var{sys} is a discrete-time system or a static gain. 34 | ## @end table 35 | ## @end deftypefn 36 | 37 | ## Author: Lukas Reichlin 38 | ## Created: September 2009 39 | ## Version: 0.1 40 | 41 | function bool = isdt (ltisys) 42 | 43 | if (nargin != 1) 44 | print_usage (); 45 | endif 46 | 47 | # Treat static gains (tsam = -2) as ct systems since there is 48 | # no more information on its sampling time 49 | bool = ((ltisys.tsam != 0) && (ltisys.tsam != -2)); 50 | 51 | endfunction 52 | -------------------------------------------------------------------------------- /inst/@lti/mldivide.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} mldivide 20 | ## Matrix left division of @acronym{LTI} objects. If necessary, object conversion 21 | ## is done by sys_group in mtimes. Used by Octave for "sys1 \\ sys2". 22 | ## 23 | ## @end deftypefn 24 | 25 | ## Author: Lukas Reichlin 26 | ## Created: October 2009 27 | ## Version: 0.2 28 | 29 | function sys = mldivide (sys1, sys2) 30 | 31 | if (nargin != 2) # prevent sys = mldivide (sys1, sys2, sys3, ...) 32 | error ("lti: mldivide: this is a binary operator"); 33 | endif 34 | 35 | sys1 = inv (sys1); # let octave decide which inv() it uses 36 | 37 | ## [p1, m1] = size (sys1); 38 | ## [p2, m2] = size (sys2); 39 | ## 40 | ## if (m1 != p2) 41 | ## error ("lti: mldivide: system dimensions incompatible: (%dx%d) \\ (%dx%d)", 42 | ## p1, m1, p2, m2); 43 | ## endif 44 | 45 | sys = sys1 * sys2; 46 | 47 | endfunction 48 | -------------------------------------------------------------------------------- /inst/@lti/mrdivide.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} mrdivide 20 | ## Matrix right division of @acronym{LTI} objects. If necessary, object conversion 21 | ## is done by sys_group in mtimes. Used by Octave for "sys1 / sys2". 22 | ## 23 | ## @end deftypefn 24 | 25 | ## Author: Lukas Reichlin 26 | ## Created: October 2009 27 | ## Version: 0.2 28 | 29 | function sys = mrdivide (sys1, sys2) 30 | 31 | if (nargin != 2) # prevent sys = mrdivide (sys1, sys2, sys3, ...) 32 | error ("lti: mrdivide: this is a binary operator"); 33 | endif 34 | 35 | sys2 = inv (sys2); # let octave decide which inv() it uses 36 | 37 | ## [p1, m1] = size (sys1); 38 | ## [p2, m2] = size (sys2); 39 | ## 40 | ## if (m1 != p2) 41 | ## error ("lti: mrdivide: system dimensions incompatible: (%dx%d) / (%dx%d)", 42 | ## p1, m1, p2, m2); 43 | ## endif 44 | 45 | sys = sys1 * sys2; 46 | 47 | endfunction 48 | -------------------------------------------------------------------------------- /inst/__frd_dim__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Number of outputs and inputs of transfer function numerator and 20 | ## denominator. For internal use only. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: February 2010 24 | ## Version: 0.2 25 | 26 | function [p, m, l] = __frd_dim__ (H, w) 27 | 28 | if (! isnumeric (H)) 29 | error ("frd: argument 'H' must be a 3-dimensional numeric array"); 30 | endif 31 | 32 | lw = length (w); 33 | 34 | if (! isempty (w) && (! is_real_vector (w) || any (w < 0) ... 35 | || ! issorted (w) || w(1) > w(end) ... 36 | || length (unique (w)) != lw)) 37 | error ("frd: argument 'w' must be a vector of positive real numbers in ascending order"); 38 | endif 39 | 40 | [p, m, l] = size (H); 41 | 42 | if (l != lw) 43 | error ("frd: arguments 'H' (%dx%dx%d) and 'w' (%d) must have equal length", 44 | p, m, l, lw); 45 | endif 46 | 47 | endfunction 48 | -------------------------------------------------------------------------------- /inst/@lti/minus.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} minus 20 | ## Binary subtraction of @acronym{LTI} objects. If necessary, object conversion 21 | ## is done by sys_group. Used by Octave for "sys1 - sys2". 22 | ## 23 | ## @end deftypefn 24 | 25 | ## Author: Lukas Reichlin 26 | ## Created: September 2009 27 | ## Version: 0.1 28 | 29 | function sys = minus (sys1, sys2) 30 | 31 | if (nargin != 2) # prevent sys = minus (sys1, sys2, sys3, ...) 32 | error ("lti: minus: this is a binary operator"); 33 | endif 34 | 35 | [p1, m1] = size (sys1); 36 | [p2, m2] = size (sys2); 37 | 38 | if (p1 != p2 || m1 != m2) 39 | error ("lti: minus: system dimensions incompatible: (%dx%d) - (%dx%d)", 40 | p1, m1, p2, m2); 41 | endif 42 | 43 | sys = __sys_group__ (sys1, sys2); 44 | 45 | in_scl = [eye(m1); eye(m2)]; 46 | out_scl = [eye(p1), -eye(p2)]; 47 | 48 | sys = out_scl * sys * in_scl; 49 | 50 | endfunction 51 | -------------------------------------------------------------------------------- /inst/@tf/__times__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Hadamard/Schur product of @acronym{TF} objects. 20 | ## Used by Octave for "sys1 .* sys2". 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: April 2014 24 | ## Version: 0.1 25 | 26 | function sys = __times__ (sys1, sys2) 27 | 28 | if (! isa (sys1, "tf")) 29 | sys1 = tf (sys1); 30 | endif 31 | 32 | if (! isa (sys2, "tf")) 33 | sys2 = tf (sys2); 34 | endif 35 | 36 | sys = tf (); 37 | sys.lti = __lti_group__ (sys1.lti, sys2.lti, "times"); 38 | 39 | sys.num = cellfun (@mtimes, sys1.num, sys2.num, "uniformoutput", false); 40 | sys.den = cellfun (@mtimes, sys1.den, sys2.den, "uniformoutput", false); 41 | 42 | if (sys1.tfvar == sys2.tfvar) 43 | sys.tfvar = sys1.tfvar; 44 | elseif (sys1.tfvar == "x") 45 | sys.tfvar = sys2.tfvar; 46 | else 47 | sys.tfvar = sys1.tfvar; 48 | endif 49 | 50 | if (sys1.inv || sys2.inv) 51 | sys.inv = true; 52 | endif 53 | 54 | endfunction 55 | -------------------------------------------------------------------------------- /inst/@ss/__prescale__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Prescale state-space model. 20 | ## Uses @uref{https://github.com/SLICOT/SLICOT-Reference, SLICOT TB01ID and TG01AD}, 21 | ## Copyright (c) 2020, SLICOT, available under the BSD 3-Clause 22 | ## (@uref{https://github.com/SLICOT/SLICOT-Reference/blob/main/LICENSE, License and Disclaimer}). 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: June 2011 26 | ## Version: 0.1 27 | 28 | function [retsys, lscale, rscale] = __prescale__ (sys, optarg = 0.0) 29 | 30 | if (isempty (sys.e)) 31 | [a, b, c, ~, scale] = __sl_tb01id__ (sys.a, sys.b, sys.c, optarg); 32 | retsys = ss (a, b, c, sys.d); 33 | lscale = scale.^-1; 34 | rscale = scale; 35 | else 36 | [a, e, b, c, lscale, rscale] = __sl_tg01ad__ (sys.a, sys.e, sys.b, sys.c, optarg); 37 | retsys = dss (a, b, c, sys.d, e); 38 | endif 39 | 40 | retsys.scaled = true; 41 | retsys.lti = sys.lti; # retain i/o names and tsam 42 | 43 | endfunction 44 | -------------------------------------------------------------------------------- /inst/__adjust_iddata_tsam__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Check whether tsam is a e-by-1 cell array of valid sampling times. 20 | ## If not, it tries to convert tsam accordingly. 21 | ## Empty tsam are filled with default value -1. 22 | 23 | ## Author: Lukas Reichlin 24 | ## Created: February 2012 25 | ## Version: 0.1 26 | 27 | function tsam = __adjust_iddata_tsam__ (tsam, e) 28 | 29 | if (isempty (tsam)) 30 | tsam = num2cell (-ones (e, 1)); 31 | elseif (iscell (tsam)) 32 | tsam = reshape (tsam, [], 1); 33 | else 34 | tsam = {tsam}; 35 | endif 36 | 37 | tmp = cellfun (@issample, tsam, {-1}); 38 | 39 | if (any (! tmp)) 40 | error ("iddata: invalid sampling time"); 41 | endif 42 | 43 | nt = numel (tsam); 44 | 45 | if (nt == 1 && e > 1) 46 | tsam = repmat (tsam, e, 1); 47 | elseif (nt != e) 48 | error ("iddata: there are %d experiments, but only %d sampling times", ... 49 | e, nt); 50 | endif 51 | 52 | endfunction 53 | -------------------------------------------------------------------------------- /inst/@frd/__freqresp__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Frequency response of FRD models :-) 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2010 23 | ## Version: 0.3 24 | 25 | function H = __freqresp__ (sys, w, cellflag = false) 26 | 27 | [H, w_sys, tsam] = frdata (sys, "array"); 28 | 29 | if (! isempty (w)) # freqresp (frdsys, w), sigma (frdsys, w), ... 30 | tol = sqrt (eps); 31 | w_idx = arrayfun (@(x) find (abs (w_sys - x) < tol), w, "uniformoutput", false); 32 | w_idx = vertcat (w_idx{:}); 33 | 34 | ## NOTE: There are problems when cellfun uses "uniformoutput", true 35 | ## and find returns an empty matrix, 36 | 37 | if (length (w_idx) != numel (w)) 38 | error ("frd: freqresp: some frequencies are not within tolerance %g", tol); 39 | endif 40 | 41 | H = H(:, :, w_idx); 42 | endif 43 | 44 | if (cellflag) 45 | [p, m, l] = size (H); 46 | H = mat2cell (H, p, m, ones (1, l))(:); 47 | endif 48 | 49 | endfunction 50 | -------------------------------------------------------------------------------- /inst/@iddata/end.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} end 20 | ## End indexing for @acronym{IDDATA} objects. 21 | ## Used by Octave for "dat(1:end)". 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: December 2013 26 | ## Version: 0.1 27 | 28 | function ret = end (dat, k, n) 29 | 30 | if (n > 4) 31 | error ("iddata: end: require at most 4 indices in the expression"); 32 | endif 33 | 34 | switch (k) 35 | case 1 # selecting samples 36 | ret = size (dat, 1); 37 | if (numel (ret) != 1 && ! isequal (num2cell (ret){:})) 38 | error ("iddata: end: for multi-experiment datasets, require equal number of samples when selecting samples with 'end'"); 39 | endif 40 | ret = ret(1); 41 | case {2, 3, 4} # selecting outputs, inputs or experiments 42 | ret = size (dat, k); 43 | otherwise 44 | error ("iddata: end: invalid expression index k = %d", k); 45 | endswitch 46 | 47 | endfunction 48 | -------------------------------------------------------------------------------- /inst/__tito_dim__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## Extract nmeas and ncon from plant P which has been partitioned by mktito. 19 | 20 | ## Author: Lukas Reichlin 21 | ## Created: January 2014 22 | ## Version: 0.1 23 | 24 | function [nmeas, ncon] = __tito_dim__ (P, name) 25 | 26 | [p, m] = size (P); 27 | outgroup = P.outgroup; 28 | ingroup = P.ingroup; 29 | 30 | if (! isfield (outgroup, "V")) 31 | error ("%s: missing outgroup 'V'", name); 32 | endif 33 | 34 | if (! isfield (ingroup, "U")) 35 | error ("%s: missing ingroup 'U'", name); 36 | endif 37 | 38 | nmeas = numel (outgroup.V); 39 | ncon = numel (ingroup.U); 40 | 41 | ## check whether indices of V and U are in ascending order 42 | ## and at the end of the outputs/inputs 43 | 44 | if (! isequal (outgroup.V(:), (p-nmeas+1:p)(:))) 45 | error ("%s: outgroup 'V' invalid", name); 46 | endif 47 | 48 | if (! isequal (ingroup.U(:), (m-ncon+1:m)(:))) 49 | error ("%s: ingroup 'U' invalid", name); 50 | endif 51 | 52 | endfunction 53 | -------------------------------------------------------------------------------- /io.github.gnu_octave.pkg-control.metainfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | io.github.gnu_octave.pkg-control 12 | org.octave.Octave 13 | Control Design and Analysis 14 | The control package for GNU Octave 15 | 16 | Octave 17 | Control 18 | Linear Time Invariant Models 19 | Time Domain Analysis 20 | Frequency Domain Analysis 21 | Pole Placement 22 | Optimal Control 23 | Robust Control 24 | Matrix Equation Solvers 25 | Model and Controller Reduction 26 | System Identification 27 | 28 | 29 |

30 | The Control package for GNU Octave is a collection of functions 31 | for system analysis and control synthesis. The package uses 32 | routines of the SLICOT-Reference library. 33 |

34 |
35 | https://gnu-octave.github.io/packages/control 36 | https://github.com/gnu-octave/pkg-control/issues 37 | FSFAP 38 | GPL-3.0-or-later and BSD-3-Clause 39 | Octave Community 40 | octave-maintainers@gnu.org 41 |
42 | -------------------------------------------------------------------------------- /inst/@tf/__get__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Access key values of TF objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.5 24 | 25 | function val = __get__ (sys, key) 26 | 27 | switch (key) # {, } 28 | 29 | case {"num","den"} 30 | ## Give numerator and denominator of a tf component the same length 31 | [num, den] = __make_tf_polys_equally_long__ (sys); 32 | ## Get the coefficients of the polys with normalized length 33 | if key == "num" 34 | val = cellfun (@get, num, "uniformoutput", false); 35 | else 36 | val = cellfun (@get, den, "uniformoutput", false); 37 | endif 38 | 39 | case {"tfvar", "variable"} 40 | val = sys.tfvar; 41 | if (sys.inv && isdt (sys)) 42 | val = [val, "^-1"]; 43 | endif 44 | 45 | case "inv" 46 | val = sys.inv; 47 | 48 | otherwise 49 | error ("tf: get: invalid key name '%s'", key); 50 | 51 | endswitch 52 | 53 | endfunction 54 | -------------------------------------------------------------------------------- /inst/optiPIDfun.m: -------------------------------------------------------------------------------- 1 | % =============================================================================== 2 | % optiPIDfun Lukas Reichlin July 2009 3 | % =============================================================================== 4 | % Objective Function 5 | % Reference: Guzzella, L. (2007) Analysis and Synthesis of SISO Control Systems. 6 | % vdf Hochschulverlag, Zurich 7 | % =============================================================================== 8 | 9 | function J = optiPIDfun (C_par) 10 | 11 | % Global Variables 12 | global P t dt mu_1 mu_2 mu_3 13 | 14 | % Function Argument -> Controller Parameters 15 | kp = C_par(1); 16 | Ti = C_par(2); 17 | Td = C_par(3); 18 | 19 | % PID Controller with Roll-Off 20 | C = optiPIDctrl (kp, Ti, Td); 21 | 22 | % Open Loop 23 | L = P * C; 24 | 25 | % Sum Block: e = r - y 26 | SUM = ss ([1, -1]); % Matlab converts to SS (and back) for MIMO TF connections 27 | 28 | % Group Sum Block and Open Loop 29 | SUML = append (SUM, L); 30 | 31 | % Build System Interconnections 32 | CM = [3, 1; % Controller Input with Sum Block Output 33 | 2, 2]; % Sum Block Negative Input with Plant Output 34 | 35 | inputs = [1]; % Input 1: reference r(t) 36 | outputs = [1, 2]; % Output 1: error e(t), Output 2: output y(t) 37 | 38 | SUML = connect (SUML, CM, inputs, outputs); 39 | 40 | % Simulation 41 | [y, t_y] = step (SUML, t); 42 | 43 | % ITAE Criterion 44 | itae = dt * (t_y.' * abs (y(:, 1))); 45 | 46 | % Sensitivity 47 | S = inv (1 + L); 48 | Ms = norm (S, inf); 49 | 50 | % Objective Function 51 | J = mu_1 * itae + mu_2 * (max (y(:, 2)) - 1) + mu_3 * Ms; 52 | 53 | end % function 54 | 55 | % =============================================================================== 56 | -------------------------------------------------------------------------------- /inst/__adjust_labels__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Check whether a cell contains the required number of strings. 20 | ## Used by set and __set__. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2009 24 | ## Version: 0.4 25 | 26 | function name = __adjust_labels__ (name, req_len) 27 | 28 | if (iscell (name)) 29 | name = reshape (name, [], 1); 30 | else # catch the siso case, 31 | name = {name}; # e.g. sys = set (sys, "inname", "u_1") 32 | endif 33 | 34 | if (! iscellstr (name)) 35 | error ("lti: set: require string or cell of strings"); 36 | endif 37 | 38 | if (numel (name) != req_len) 39 | if (numel (name) == 1 && req_len > 1) 40 | if (isempty (name{1})) # delete names quickly 41 | name = repmat ({""}, req_len, 1); 42 | else 43 | name = strseq (name{1}, 1:req_len); 44 | endif 45 | else 46 | error ("lti: set: cell must contain %d strings", req_len); 47 | endif 48 | endif 49 | 50 | endfunction 51 | -------------------------------------------------------------------------------- /inst/@tf/__ctranspose__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Conjugate transpose of TF models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: May 2012 23 | ## Version: 0.1 24 | 25 | function sys = __ctranspose__ (sys, ct) 26 | 27 | num = sys.num; 28 | den = sys.den; 29 | 30 | if (ct) # continuous-time 31 | num = cellfun (@conj_ct, num, "uniformoutput", false); 32 | den = cellfun (@conj_ct, den, "uniformoutput", false); 33 | else # discrete-time 34 | ## Both num and den must be the same length 35 | ## for the flip command, 36 | ## so add leading zeros to the shortest one. 37 | ng=get(num{1}); 38 | dg=get(den{1}); 39 | nng=numel(ng); 40 | ndg=numel(dg); 41 | if (nng>ndg) 42 | dg= [zeros(1,nng-ndg) dg]; 43 | else 44 | ng= [zeros(1,ndg-nng) ng] ; 45 | endif 46 | ## the flip effectively replaces every z with 1/z 47 | num={tfpoly(flip(ng))}; 48 | den={tfpoly(flip(dg))}; 49 | endif 50 | 51 | sys.num = num.'; 52 | sys.den = den.'; 53 | 54 | endfunction 55 | -------------------------------------------------------------------------------- /inst/@lti/display.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Display routine for LTI objects. Called by its child classes. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: September 2009 23 | ## Version: 0.3 24 | 25 | function display (sys) 26 | 27 | if (numfields (sys.ingroup) > 0) 28 | __disp_group__ (sys.ingroup, "Input"); 29 | endif 30 | 31 | if (numfields (sys.outgroup) > 0) 32 | __disp_group__ (sys.outgroup, "Output"); 33 | endif 34 | 35 | if (! isempty (sys.name)) 36 | disp (["Name: ", sys.name]); 37 | endif 38 | 39 | if (sys.tsam > 0) 40 | disp (sprintf ("Sampling time: %g s", sys.tsam)); 41 | elseif (sys.tsam == -1) 42 | disp ("Sampling time: unspecified"); 43 | endif 44 | 45 | endfunction 46 | 47 | 48 | function __disp_group__ (group, io) 49 | 50 | name = fieldnames (group); 51 | idx = struct2cell (group); 52 | 53 | cellfun (@(name, idx) printf ("%s group '%s' = %s\n", io, name, mat2str (idx(:).')), ... 54 | name, idx, "uniformoutput", false); 55 | 56 | endfunction 57 | -------------------------------------------------------------------------------- /inst/__adjust_ss_data__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Common code for adjusting SS model data. 20 | ## Used by @ss/ss.m, others possibly follow. 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2010 24 | ## Version: 0.3 25 | 26 | function [a, b, c, d, tsam] = __adjust_ss_data__ (a, b, c, d, tsam); 27 | 28 | if (isempty (d)) 29 | if (all (size (c) == 0)) # ss (a, b), ss (a, b, [], [], ...), but allow c(0xn) and d(0xm) 30 | c = eye (size (a)); 31 | d = zeros (rows (a), columns (b)); 32 | else # ss (a, b, c), ss (a, b, c, [], ...) 33 | d = zeros (rows (c), columns (b)); 34 | endif 35 | endif 36 | 37 | if (isempty (b) && isempty (c)) # sys = ss ([], [], [], d) 38 | b = zeros (0, columns (d)); 39 | c = zeros (rows (d), 0); 40 | endif 41 | 42 | if (is_real_scalar (d) && d == 0) # ss (a, b, c, 0) (for matlab compatibility) 43 | d = zeros (rows (c), columns (b)); # test d == 0 to avoid ss (0) returning 0x0 model 44 | endif 45 | 46 | endfunction 47 | -------------------------------------------------------------------------------- /inst/@tf/__sys_keys__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {[@var{keys}, @var{vals}] =} __sys_keys__ (@var{sys}) 20 | ## @deftypefnx {Function File} {[@var{keys}, @var{vals}] =} __sys_keys__ (@var{sys}, @var{aliases}) 21 | ## Return the list of keys as well as the assignable values for a tf object sys. 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: October 2009 26 | ## Version: 0.3 27 | 28 | function [keys, vals] = __sys_keys__ (sys, aliases = false) 29 | 30 | ## cell vector of tf-specific keys 31 | keys = {"num"; 32 | "den"; 33 | "tfvar"; 34 | "inv"}; 35 | 36 | ## cell vector of tf-specific assignable values 37 | vals = {"p-by-m cell array of row vectors (m = number of inputs)"; 38 | "p-by-m cell array of row vectors (p = number of outputs)"; 39 | "string (usually s or z)"; 40 | "logical (true for negative powers of TF variable)"}; 41 | 42 | if (aliases) 43 | ka = {"variable"}; 44 | keys = [keys; ka]; 45 | endif 46 | 47 | endfunction 48 | -------------------------------------------------------------------------------- /inst/@ss/__sys_inverse__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Inversion of SS models. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.4 24 | 25 | function sys = __sys_inverse__ (sys) 26 | 27 | a = sys.a; 28 | b = sys.b; 29 | c = sys.c; 30 | d = sys.d; 31 | e = sys.e; 32 | 33 | if (! isempty (e) || rcond (d) < eps) # dss or strictly proper ss 34 | 35 | n = rows (a); 36 | m = columns (b); # p = m (square system) 37 | 38 | if (isempty (e)) # avoid testing twice? 39 | e = eye (n); 40 | endif 41 | 42 | sys.a = [a, b; c, d]; 43 | sys.b = [zeros(n, m); -eye(m)]; 44 | sys.c = [zeros(m, n), eye(m)]; 45 | sys.d = zeros (m); 46 | sys.e = [e, zeros(n, m); zeros(m, n+m)]; 47 | 48 | sys.stname = [sys.stname; repmat({""}, m, 1)]; 49 | 50 | else # proper ss 51 | 52 | bid = b / d; 53 | 54 | sys.a = a - bid * c; 55 | sys.b = bid; 56 | sys.c = -d \ c; 57 | sys.d = inv (d); 58 | 59 | endif 60 | 61 | endfunction 62 | -------------------------------------------------------------------------------- /inst/__adjust_frd_data__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Common code for adjusting FRD model data. 20 | ## Used by @frd/frd.m and @frd/__set__.m 21 | 22 | ## Author: Lukas Reichlin 23 | ## Created: October 2010 24 | ## Version: 0.1 25 | 26 | function [H, w] = __adjust_frd_data__ (H, w); 27 | 28 | w = reshape (w, [], 1); 29 | lw = length (w); 30 | 31 | if (ndims (H) != 3 && ! isempty (H)) 32 | if (isscalar (H)) 33 | H = reshape (H, 1, 1, []); 34 | if (lw > 1) 35 | H = repmat (H, [1, 1, lw]); # needed for "frd1 + scalar2" or "scalar1 * frd2) 36 | endif 37 | elseif (isvector (H) && length (H) == lw) # SISO system (H is a vector) 38 | H = reshape (H, 1, 1, []); 39 | elseif (ismatrix (H)) 40 | H = reshape (H, rows (H), []); 41 | if (lw > 1) 42 | H = repmat (H, [1, 1, lw]); # needed for "frd1 + matrix2" or "matrix1 * frd2) 43 | endif 44 | else 45 | error ("frd: first argument H invalid"); 46 | endif 47 | elseif (isempty (H)) 48 | H = zeros (0, 0, 0); 49 | endif 50 | 51 | endfunction 52 | -------------------------------------------------------------------------------- /inst/@lti/parallel.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Function File} {@var{sys} =} parallel (@var{sys1}, @var{sys2}) 20 | ## Parallel connection of two @acronym{LTI} systems. 21 | ## 22 | ## @strong{Block Diagram} 23 | ## @example 24 | ## @group 25 | ## .......................... 26 | ## : +--------+ : 27 | ## : +-->| sys1 |---+ : 28 | ## u : | +--------+ | + : y 29 | ## -------+ O---------> 30 | ## : | +--------+ | + : 31 | ## : +-->| sys2 |---+ : 32 | ## : +--------+ : 33 | ## :.........sys............: 34 | ## 35 | ## sys = parallel (sys1, sys2) 36 | ## @end group 37 | ## @end example 38 | ## @end deftypefn 39 | 40 | ## Author: Lukas Reichlin 41 | ## Created: September 2009 42 | ## Version: 0.1 43 | 44 | function sys = parallel (sys1, sys2) 45 | 46 | if (nargin == 2) 47 | sys = sys1 + sys2; 48 | ## elseif (nargin == 6) 49 | 50 | ## TODO: implement "complicated" case sys = parallel (sys1, sys2, in1, in2, out1, out2) 51 | 52 | else 53 | print_usage (); 54 | endif 55 | 56 | endfunction 57 | -------------------------------------------------------------------------------- /inst/@ss/__zero__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Invariant zeros of SS object. 20 | ## Uses @uref{https://github.com/SLICOT/SLICOT-Reference, SLICOT AB08ND and AG08BD}, 21 | ## Copyright (c) 2020, SLICOT, available under the BSD 3-Clause 22 | ## (@uref{https://github.com/SLICOT/SLICOT-Reference/blob/main/LICENSE, License and Disclaimer}). 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: October 2009 26 | ## Version: 0.4 27 | 28 | function [zer, gain, info] = __zero__ (sys, argc) 29 | 30 | if (isempty (sys.e)) 31 | [zer, gain, rank, infz, kronr, kronl] = __sl_ab08nd__ (sys.a, sys.b, sys.c, sys.d, sys.scaled); 32 | else 33 | [zer, rank, infz, kronr, kronl] = __sl_ag08bd__ (sys.a, sys.e, sys.b, sys.c, sys.d, sys.scaled); 34 | if (argc > 1 && issiso (sys)) 35 | pol = pole (sys); 36 | gain = __sl_tg04bx__ (sys.a, sys.e, sys.b, sys.c, sys.d, ... 37 | real (pol), imag (pol), real (zer), imag (zer)); 38 | else 39 | gain = []; 40 | endif 41 | endif 42 | 43 | info = struct ("rank", rank, "infz", infz, "kronr", kronr, "kronl", kronl); 44 | 45 | endfunction 46 | -------------------------------------------------------------------------------- /inst/@frd/__sys_connect__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{retsys} =} __sys_connect__ (@var{sys}, @var{M}) 20 | ## This function is part of the Model Abstraction Layer. No argument checking. 21 | ## For internal use only. 22 | ## @example 23 | ## @group 24 | ## Problem: Solve the system equations of 25 | ## Y(s) = G(s) E(s) 26 | ## E(s) = U(s) + M Y(s) 27 | ## in order to build 28 | ## Y(s) = H(s) U(s) 29 | ## Solution: 30 | ## Y(s) = G(s) [U(s) + M Y(s)] 31 | ## Y(s) = G(s) U(s) + G(s) M Y(s) 32 | ## Y(s) = [I - G(s) M]^-1 G(s) U(s) 33 | ## \_______ _______/ 34 | ## H(s) 35 | ## @end group 36 | ## @end example 37 | ## @end deftypefn 38 | 39 | ## Author: Lukas Reichlin 40 | ## Created: October 2010 41 | ## Version: 0.1 42 | 43 | function sys = __sys_connect__ (sys, M) 44 | 45 | ## FIXME: feedback (frd (ss (1)), frd (ss (-1))) 46 | 47 | [p, m, l] = size (sys.H); 48 | 49 | I = eye (p); 50 | H = mat2cell (sys.H, p, m, ones (1, l))(:); 51 | 52 | H = cellfun (@(x) (I - x*M) \ x, H, "uniformoutput", false); 53 | 54 | sys.H = cat (3, H{:}); 55 | 56 | endfunction 57 | -------------------------------------------------------------------------------- /inst/@lti/__numeric_to_lti__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2023 Torsten Lilge 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Chcking two systems that have to be connected if they 20 | ## possibly are only numerical values and have to be turned 21 | ## into proper lti systems. 22 | ## For internal use only. 23 | 24 | ## Author: Torsten Lilge 25 | ## Created: July 2023 26 | ## Version: 0.1 27 | 28 | function [sys1, sys2] = __numeric_to_lti__ (sys1, sys2) 29 | 30 | sys = {sys1, sys2}; 31 | for i = 1:2 32 | if (! isa (sys{i}, "lti")) 33 | if (! isa (sys{i}, "numeric")) 34 | error ("lti: mtimes/mplus: one system is neither an lti system nor a numeric value"); 35 | else 36 | sys{i} = tf (sys{i}); 37 | endif 38 | endif 39 | endfor 40 | 41 | sys1 = sys{1}; 42 | sys2 = sys{2}; 43 | 44 | % If one of the two systems is only a static gain, just take the 45 | % sampling time of the other system 46 | if (isstaticgain(sys1) && (get(sys1,'tsam') == 0) && (get(sys2,'tsam') > 0)) 47 | sys1 = c2d (sys1, get(sys2,'tsam')); 48 | elseif (isstaticgain(sys2) && (get(sys2,'tsam') == 0) && (get(sys1,'tsam') > 0)) 49 | sys2 = c2d (sys2, get(sys1,'tsam')); 50 | endif 51 | 52 | endfunction 53 | 54 | -------------------------------------------------------------------------------- /inst/@ss/__sys_keys__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {[@var{keys}, @var{vals}] =} __sys_keys__ (@var{sys}) 20 | ## @deftypefnx {Function File} {[@var{keys}, @var{vals}] =} __sys_keys__ (@var{sys}, @var{aliases}) 21 | ## Return the list of keys as well as the assignable values for a ss object sys. 22 | ## @end deftypefn 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: September 2009 26 | ## Version: 0.3 27 | 28 | function [keys, vals] = __sys_keys__ (sys, aliases = false) 29 | 30 | ## cell vector of ss-specific keys 31 | keys = {"a"; 32 | "b"; 33 | "c"; 34 | "d"; 35 | "e"; 36 | "stname"; 37 | "scaled"}; 38 | 39 | ## cell vector of ss-specific assignable values 40 | vals = {"n-by-n matrix (n = number of states)"; 41 | "n-by-m matrix (m = number of inputs)"; 42 | "p-by-n matrix (p = number of outputs)"; 43 | "p-by-m matrix"; 44 | "n-by-n matrix"; 45 | "n-by-1 cell vector of strings"; 46 | "scalar logical value"}; 47 | 48 | if (aliases) 49 | ka = {"statename"}; 50 | keys = [keys; ka]; 51 | endif 52 | 53 | endfunction 54 | -------------------------------------------------------------------------------- /inst/@lti/freqresp.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Function File} {@var{H} =} freqresp (@var{sys}, @var{w}) 20 | ## Evaluate frequency response at given frequencies. 21 | ## 22 | ## @strong{Inputs} 23 | ## @table @var 24 | ## @item sys 25 | ## @acronym{LTI} system. 26 | ## @item w 27 | ## Vector of frequency values. 28 | ## @end table 29 | ## 30 | ## @strong{Outputs} 31 | ## @table @var 32 | ## @item H 33 | ## Array of frequency response. For a system with m inputs and p outputs, the array @var{H} 34 | ## has dimensions [p, m, length (w)]. 35 | ## The frequency response at the frequency w(k) is given by H(:,:,k). 36 | ## @end table 37 | ## 38 | ## @seealso{dcgain} 39 | ## @end deftypefn 40 | 41 | ## Author: Lukas Reichlin 42 | ## Created: October 2009 43 | ## Version: 0.2 44 | 45 | function H = freqresp (sys, w) 46 | 47 | if (nargin != 2) # case freqresp () not possible 48 | print_usage (); 49 | endif 50 | 51 | if (! is_real_vector (w)) # catches freqresp (sys, sys) and freqresp (w, sys) as well 52 | error ("freqresp: second argument 'w' must be a real-valued vector of frequencies"); 53 | endif 54 | 55 | H = __freqresp__ (sys, w); 56 | 57 | endfunction 58 | -------------------------------------------------------------------------------- /inst/@lti/isstable.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{bool} =} isstable (@var{sys}) 20 | ## @deftypefnx {Function File} {@var{bool} =} isstable (@var{sys}, @var{tol}) 21 | ## Determine whether @acronym{LTI} system is stable. 22 | ## 23 | ## @strong{Inputs} 24 | ## @table @var 25 | ## @item sys 26 | ## @acronym{LTI} system. 27 | ## @item tol 28 | ## Optional tolerance for stability. 29 | ## @var{tol} must be a real-valued, non-negative scalar. 30 | ## Default value is 0. 31 | ## @end table 32 | ## 33 | ## @strong{Outputs} 34 | ## @table @var 35 | ## @item bool 36 | ## True if the system is stable and false otherwise. 37 | ## @end table 38 | ## 39 | ## @example 40 | ## @group 41 | ## real (p) < -tol*(1 + abs (p)) continuous-time 42 | ## abs (p) < 1 - tol discrete-time 43 | ## @end group 44 | ## @end example 45 | ## @end deftypefn 46 | 47 | ## Author: Lukas Reichlin 48 | ## Created: October 2009 49 | ## Version: 0.2 50 | 51 | function bool = isstable (sys, tol = 0) 52 | 53 | if (nargin > 2) 54 | print_usage (); 55 | endif 56 | 57 | pol = pole (sys); 58 | ct = isct (sys); 59 | 60 | bool = __is_stable__ (pol, ct, tol); 61 | 62 | endfunction 63 | -------------------------------------------------------------------------------- /src/is_matrix.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2009-2016 Lukas F. Reichlin 4 | 5 | This file is part of LTI Syncope. 6 | 7 | LTI Syncope is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | LTI Syncope is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with LTI Syncope. If not, see . 19 | 20 | Return true if all arguments are matrices and false otherwise. 21 | 22 | Author: Lukas Reichlin 23 | Created: June 2012 24 | Version: 0.2 25 | 26 | */ 27 | 28 | #include 29 | #include "config.h" 30 | 31 | // PKG_ADD: autoload ("is_matrix", "__control_helper_functions__.oct"); 32 | DEFUN_DLD (is_matrix, args, nargout, 33 | "-*- texinfo -*-\n" 34 | "@deftypefn {Loadable Function} {} is_matrix (@var{a}, @dots{})@*\n" 35 | "Return true if all arguments are matrices and false otherwise.@*\n" 36 | "@var{[]} is a valid matrix.@*\n" 37 | "Avoid nasty stuff like @code{true = isreal (\"a\")}@*\n" 38 | "@seealso{is_real_matrix, is_real_square_matrix, is_real_vector, is_real_scalar}@*\n" 39 | "@end deftypefn") 40 | { 41 | octave_value retval = true; 42 | octave_idx_type nargin = args.length (); 43 | 44 | if (nargin == 0) 45 | { 46 | print_usage (); 47 | } 48 | else 49 | { 50 | for (octave_idx_type i = 0; i < nargin; i++) 51 | { 52 | if (args(i).ndims () != 2 || ! args(i).isnumeric () 53 | || ! (args(i).iscomplex () || args(i).isreal ())) 54 | { 55 | retval = false; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | return retval; 62 | } 63 | -------------------------------------------------------------------------------- /src/is_real_matrix.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2009-2016 Lukas F. Reichlin 4 | 5 | This file is part of LTI Syncope. 6 | 7 | LTI Syncope is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | LTI Syncope is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with LTI Syncope. If not, see . 19 | 20 | Return true if all arguments are real-valued matrices and false otherwise. 21 | 22 | Author: Lukas Reichlin 23 | Created: September 2010 24 | Version: 0.2 25 | 26 | */ 27 | 28 | #include 29 | #include "config.h" 30 | 31 | // PKG_ADD: autoload ("is_real_matrix", "__control_helper_functions__.oct"); 32 | DEFUN_DLD (is_real_matrix, args, nargout, 33 | "-*- texinfo -*-\n" 34 | "@deftypefn {Loadable Function} {} is_real_matrix (@var{a}, @dots{})@*\n" 35 | "Return true if all arguments are real-valued matrices and false otherwise.@*\n" 36 | "@var{[]} is a valid matrix.@*\n" 37 | "Avoid nasty stuff like @code{true = isreal (\"a\")}@*\n" 38 | "@seealso{is_real_square_matrix, is_real_vector, is_real_scalar}@*\n" 39 | "@end deftypefn") 40 | { 41 | octave_value retval = true; 42 | octave_idx_type nargin = args.length (); 43 | 44 | if (nargin == 0) 45 | { 46 | print_usage (); 47 | } 48 | else 49 | { 50 | for (octave_idx_type i = 0; i < nargin; i++) 51 | { 52 | if (args(i).ndims () != 2 || ! args(i).isnumeric () 53 | || ! args(i).isreal ()) 54 | { 55 | retval = false; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | return retval; 62 | } 63 | -------------------------------------------------------------------------------- /inst/@ss/__minreal__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Minimal realization of SS models. The physical meaning of states is lost. 20 | ## Uses @uref{https://github.com/SLICOT/SLICOT-Reference, SLICOT TB01PD and TG01JD}, 21 | ## Copyright (c) 2020, SLICOT, available under the BSD 3-Clause 22 | ## (@uref{https://github.com/SLICOT/SLICOT-Reference/blob/main/LICENSE, License and Disclaimer}). 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: October 2009 26 | ## Version: 0.4 27 | 28 | function retsys = __minreal__ (sys, tol) 29 | 30 | if (strcmpi (tol, "def")) 31 | tol = 0; 32 | elseif (tol > 1) 33 | error ("ss: minreal: require tol <= 1"); 34 | endif 35 | 36 | if (isempty (sys.e)) 37 | [a, b, c] = __sl_tb01pd__ (sys.a, sys.b, sys.c, tol, sys.scaled); 38 | if (rows (a) == rows (sys.a)) 39 | retsys = sys; 40 | else 41 | retsys = ss (a, b, c, sys.d); 42 | retsys.lti = sys.lti; # retain i/o names and tsam 43 | endif 44 | else 45 | [a, e, b, c] = __sl_tg01jd__ (sys.a, sys.e, sys.b, sys.c, tol, sys.scaled, 0, 0); 46 | if (rows (a) == rows (sys.a)) 47 | retsys = sys; 48 | else 49 | retsys = dss (a, b, c, sys.d, e); 50 | retsys.lti = sys.lti; # retain i/o names and tsam 51 | endif 52 | endif 53 | 54 | endfunction 55 | -------------------------------------------------------------------------------- /src/is_real_scalar.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2009-2016 Lukas F. Reichlin 4 | 5 | This file is part of LTI Syncope. 6 | 7 | LTI Syncope is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | LTI Syncope is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with LTI Syncope. If not, see . 19 | 20 | Return true if all arguments are real-valued scalars and false otherwise. 21 | 22 | Author: Lukas Reichlin 23 | Created: September 2010 24 | Version: 0.2 25 | 26 | */ 27 | 28 | #include 29 | #include "config.h" 30 | 31 | // PKG_ADD: autoload ("is_real_scalar", "__control_helper_functions__.oct"); 32 | DEFUN_DLD (is_real_scalar, args, nargout, 33 | "-*- texinfo -*-\n" 34 | "@deftypefn {Loadable Function} {} is_real_scalar (@var{a}, @dots{})@*\n" 35 | "Return true if all arguments are real-valued scalars and false otherwise.@*\n" 36 | "@var{[]} is not a valid scalar.@*\n" 37 | "Avoid nasty stuff like @code{true = isreal (\"a\")}@*\n" 38 | "@seealso{is_real_matrix, is_real_vector}@*\n" 39 | "@end deftypefn") 40 | { 41 | octave_value retval = true; 42 | octave_idx_type nargin = args.length (); 43 | 44 | if (nargin == 0) 45 | { 46 | print_usage (); 47 | } 48 | else 49 | { 50 | for (octave_idx_type i = 0; i < nargin; i++) 51 | { 52 | if (args(i).ndims () != 2 || ! args(i).is_scalar_type () 53 | || ! args(i).isnumeric () || ! args(i).isreal ()) 54 | { 55 | retval = false; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | return retval; 62 | } 63 | -------------------------------------------------------------------------------- /inst/augstate.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn {Function File} {@var{augsys} =} augstate (@var{sys}) 20 | ## Append state vector x of system @var{sys} to output vector y. 21 | ## 22 | ## @example 23 | ## @group 24 | ## . . 25 | ## x = A x + B u x = A x + B u 26 | ## y = C x + D u => y = C x + D u 27 | ## x = I x + O u 28 | ## @end group 29 | ## @end example 30 | ## 31 | ## @end deftypefn 32 | 33 | ## Author: Lukas Reichlin 34 | ## Created: October 2015 35 | ## Version: 0.1 36 | 37 | function augsys = augstate (sys) 38 | 39 | if (nargin != 1 || ! isa (sys, "lti")) 40 | print_usage (); 41 | endif 42 | 43 | if (! isa (sys, "ss")) 44 | warning ("augstate: system not in state-space form\n"); 45 | sys = ss (sys); 46 | endif 47 | 48 | [a, b, c, d, e, tsam] = dssdata (sys, []); 49 | [inn, stn, outn, ing, outg] = get (sys, "inname", "stname", "outname", "ingroup", "outgroup"); 50 | 51 | [p, m] = size (d); 52 | n = rows (a); 53 | 54 | caug = vertcat (c, eye (n)); 55 | daug = vertcat (d, zeros (n, m)); 56 | 57 | outname = vertcat (outn, stn); 58 | 59 | augsys = dss (a, b, caug, daug, e, tsam); 60 | augsys = set (augsys, "inname", inn, "stname", stn, "outname", outname, ... 61 | "ingroup", ing, "outgroup", outg); 62 | 63 | endfunction 64 | -------------------------------------------------------------------------------- /src/is_real_vector.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2009-2016 Lukas F. Reichlin 4 | 5 | This file is part of LTI Syncope. 6 | 7 | LTI Syncope is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | LTI Syncope is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with LTI Syncope. If not, see . 19 | 20 | Return true if all arguments are real-valued vectors and false otherwise. 21 | 22 | Author: Lukas Reichlin 23 | Created: September 2010 24 | Version: 0.2 25 | 26 | */ 27 | 28 | #include 29 | #include "config.h" 30 | 31 | // PKG_ADD: autoload ("is_real_vector", "__control_helper_functions__.oct"); 32 | DEFUN_DLD (is_real_vector, args, nargout, 33 | "-*- texinfo -*-\n" 34 | "@deftypefn {Loadable Function} {} is_real_vector (@var{a}, @dots{})@*\n" 35 | "Return true if all arguments are real-valued vectors and false otherwise.@*\n" 36 | "@var{[]} is not a valid vector.@*\n" 37 | "Avoid nasty stuff like @code{true = isreal (\"a\")}@*\n" 38 | "@seealso{is_real_square_matrix, is_real_matrix, is_real_scalar}@*\n" 39 | "@end deftypefn") 40 | { 41 | octave_value retval = true; 42 | octave_idx_type nargin = args.length (); 43 | 44 | if (nargin == 0) 45 | { 46 | print_usage (); 47 | } 48 | else 49 | { 50 | for (octave_idx_type i = 0; i < nargin; i++) 51 | { 52 | if (args(i).ndims () != 2 || ! (args(i).rows () == 1 || args(i).columns () == 1) 53 | || ! args(i).isnumeric () || ! args(i).isreal ()) 54 | { 55 | retval = false; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | return retval; 62 | } 63 | -------------------------------------------------------------------------------- /inst/@ss/__set__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Set or modify keys of SS objects. 20 | 21 | ## Author: Lukas Reichlin 22 | ## Created: October 2009 23 | ## Version: 0.4 24 | 25 | function sys = __set__ (sys, key, val) 26 | 27 | switch (key) # {, } 28 | case "a" 29 | __ss_dim__ (val, sys.b, sys.c, sys.d); 30 | sys.a = val; 31 | 32 | case "b" 33 | __ss_dim__ (sys.a, val, sys.c, sys.d); 34 | sys.b = val; 35 | 36 | case "c" 37 | __ss_dim__ (sys.a, sys.b, val, sys.d); 38 | sys.c = val; 39 | 40 | case "d" 41 | __ss_dim__ (sys.a, sys.b, sys.c, val); 42 | sys.d = val; 43 | 44 | case "e" 45 | if (isempty (val)) 46 | sys.e = []; # avoid [](nx0) or [](0xn) 47 | else 48 | __ss_dim__ (sys.a, sys.b, sys.c, sys.d, val); 49 | sys.e = val; 50 | endif 51 | 52 | case {"stname", "statename"} 53 | n = rows (sys.a); 54 | sys.stname = __adjust_labels__ (val, n); 55 | 56 | case "scaled" 57 | if (islogical (val) && isscalar (val) || is_real_scalar (val)) 58 | sys.scaled = logical (val); 59 | else 60 | error ("ss: set: key 'scaled' must be a scalar logical"); 61 | endif 62 | 63 | otherwise 64 | error ("ss: set: invalid key name '%s'", key); 65 | endswitch 66 | 67 | endfunction 68 | -------------------------------------------------------------------------------- /inst/@tf/vertcat.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Vertical concatenation of @acronym{TF} objects. 20 | ## Used by Octave for "[sys1; sys2]". 21 | ## Avoids conversion to state-space and back by overriding 22 | ## the general vertcat function for @acronym{LTI} objects. 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: May 2014 26 | ## Version: 0.1 27 | 28 | function sys = vertcat (sys, varargin) 29 | 30 | sys = tf (sys); 31 | varargin = cellfun (@tf, varargin, "uniformoutput", false); 32 | 33 | for k = 1 : (nargin-1) 34 | 35 | sys1 = sys; 36 | sys2 = varargin{k}; 37 | 38 | sys = tf (); 39 | sys.lti = __lti_group__ (sys1.lti, sys2.lti, "vertcat"); 40 | 41 | [p1, m1] = size (sys1.num); 42 | [p2, m2] = size (sys2.num); 43 | 44 | if (m1 != m2) 45 | error ("tf: vertcat: number of system inputs incompatible: [(%dx%d); (%dx%d)]", 46 | p1, m1, p2, m2); 47 | endif 48 | 49 | sys.num = [sys1.num; sys2.num]; 50 | sys.den = [sys1.den; sys2.den]; 51 | 52 | if (strcmp (sys1.tfvar, sys2.tfvar)) 53 | sys.tfvar = sys1.tfvar; 54 | elseif (strcmp (sys1.tfvar, "x")) 55 | sys.tfvar = sys2.tfvar; 56 | else 57 | sys.tfvar = sys1.tfvar; 58 | endif 59 | 60 | if (sys1.inv || sys2.inv) 61 | sys.inv = true; 62 | endif 63 | 64 | endfor 65 | 66 | endfunction 67 | -------------------------------------------------------------------------------- /inst/@tf/horzcat.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## Horizontal concatenation of @acronym{TF} objects. 20 | ## Used by Octave for "[sys1, sys2]". 21 | ## Avoids conversion to state-space and back by overriding 22 | ## the general horzcat function for @acronym{LTI} objects. 23 | 24 | ## Author: Lukas Reichlin 25 | ## Created: April 2014 26 | ## Version: 0.1 27 | 28 | function sys = horzcat (sys, varargin) 29 | 30 | sys = tf (sys); 31 | varargin = cellfun (@tf, varargin, "uniformoutput", false); 32 | 33 | for k = 1 : (nargin-1) 34 | 35 | sys1 = sys; 36 | sys2 = varargin{k}; 37 | 38 | sys = tf (); 39 | sys.lti = __lti_group__ (sys1.lti, sys2.lti, "horzcat"); 40 | 41 | [p1, m1] = size (sys1.num); 42 | [p2, m2] = size (sys2.num); 43 | 44 | if (p1 != p2) 45 | error ("tf: horzcat: number of system outputs incompatible: [(%dx%d), (%dx%d)]", 46 | p1, m1, p2, m2); 47 | endif 48 | 49 | sys.num = [sys1.num, sys2.num]; 50 | sys.den = [sys1.den, sys2.den]; 51 | 52 | if (strcmp (sys1.tfvar, sys2.tfvar)) 53 | sys.tfvar = sys1.tfvar; 54 | elseif (strcmp (sys1.tfvar, "x")) 55 | sys.tfvar = sys2.tfvar; 56 | else 57 | sys.tfvar = sys1.tfvar; 58 | endif 59 | 60 | if (sys1.inv || sys2.inv) 61 | sys.inv = true; 62 | endif 63 | 64 | endfor 65 | 66 | endfunction 67 | -------------------------------------------------------------------------------- /inst/@lti/times.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 2009-2016 Lukas F. Reichlin 2 | ## 3 | ## This file is part of LTI Syncope. 4 | ## 5 | ## LTI Syncope is free software: you can redistribute it and/or modify 6 | ## it under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation, either version 3 of the License, or 8 | ## (at your option) any later version. 9 | ## 10 | ## LTI Syncope is distributed in the hope that it will be useful, 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | ## GNU General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with LTI Syncope. If not, see . 17 | 18 | ## -*- texinfo -*- 19 | ## @deftypefn{Overloaded Operator} {} times 20 | ## Hadamard/Schur product of transfer function matrices. 21 | ## Also known as element-wise multiplication. 22 | ## Used by Octave for "sys1 .* sys2". 23 | ## 24 | ## @strong{Example} 25 | ## @example 26 | ## @group 27 | ## # Compute Relative-Gain Array 28 | ## G = tf (Boeing707) 29 | ## RGA = G .* inv (G).' 30 | ## # Gain at 0 rad/s 31 | ## RGA(0) 32 | ## @end group 33 | ## @end example 34 | ## 35 | ## @end deftypefn 36 | 37 | ## Author: Lukas Reichlin 38 | ## Created: April 2014 39 | ## Version: 0.2 40 | 41 | function sys = times (sys1, sys2) 42 | 43 | if (nargin != 2) # prevent sys = times (sys1, sys2, sys3, ...) 44 | error ("lti: times: this is a binary operator"); 45 | endif 46 | 47 | [p1, m1] = size (sys1); 48 | [p2, m2] = size (sys2); 49 | 50 | if (p1 != p2 || m1 != m2) 51 | if (p1 == 1 && m1 == 1 && p2*m2 > 1) # sys1 SISO, sys2 non-empty 52 | sys1 = repmat (sys1, p2, m2); 53 | elseif (p2 == 1 && m2 == 1 && p1*m1 > 1) # sys2 SISO, sys1 non-empty 54 | sys2 = repmat (sys2, p1, m1); 55 | else 56 | error ("lti: times: system dimensions incompatible: (%dx%d) .* (%dx%d)", ... 57 | p1, m1, p2, m2); 58 | endif 59 | endif 60 | 61 | sys = __times__ (sys1, sys2); 62 | 63 | endfunction 64 | -------------------------------------------------------------------------------- /src/is_real_square_matrix.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (C) 2009-2016 Lukas F. Reichlin 4 | 5 | This file is part of LTI Syncope. 6 | 7 | LTI Syncope is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | LTI Syncope is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with LTI Syncope. If not, see . 19 | 20 | Return true if all arguments are real-valued, square matrices and false otherwise. 21 | 22 | Author: Lukas Reichlin 23 | Created: September 2010 24 | Version: 0.2 25 | 26 | */ 27 | 28 | #include 29 | #include "config.h" 30 | 31 | // PKG_ADD: autoload ("is_real_square_matrix", "__control_helper_functions__.oct"); 32 | DEFUN_DLD (is_real_square_matrix, args, nargout, 33 | "-*- texinfo -*-\n" 34 | "@deftypefn {Loadable Function} {} is_real_square_matrix (@var{a}, @dots{})@*\n" 35 | "Return true if all arguments are real-valued, square matrices and false otherwise.@*\n" 36 | "@var{[]} is a valid square matrix.@*\n" 37 | "Avoid nasty stuff like @code{true = isreal (\"a\")}@*\n" 38 | "@seealso{is_real_matrix, is_real_vector, is_real_scalar}@*\n" 39 | "@end deftypefn") 40 | { 41 | octave_value retval = true; 42 | octave_idx_type nargin = args.length (); 43 | 44 | if (nargin == 0) 45 | { 46 | print_usage (); 47 | } 48 | else 49 | { 50 | for (octave_idx_type i = 0; i < nargin; i++) 51 | { 52 | if (args(i).ndims () != 2 || args(i).rows () != args(i).columns () 53 | || ! args(i).isnumeric () || ! args(i).isreal ()) 54 | { 55 | retval = false; 56 | break; 57 | } 58 | } 59 | } 60 | 61 | return retval; 62 | } 63 | -------------------------------------------------------------------------------- /inst/__axis_margin__.m: -------------------------------------------------------------------------------- 1 | ## Copyright (C) 1998, 2000, 2004, 2005, 2007 2 | ## Auburn University. All rights reserved. 3 | ## 4 | ## 5 | ## This program is free software; you can redistribute it and/or modify it 6 | ## under the terms of the GNU General Public License as published by 7 | ## the Free Software Foundation; either version 3 of the License, or (at 8 | ## your option) any later version. 9 | ## 10 | ## This program is distributed in the hope that it will be useful, but 11 | ## WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ## General Public License for more details. 14 | ## 15 | ## You should have received a copy of the GNU General Public License 16 | ## along with this program; see the file COPYING. If not, see 17 | ## . 18 | 19 | ## -*- texinfo -*- 20 | ## @deftypefn {Function File} {} __axis_margin__ (@var{axdata}) 21 | ## Determine axis limits for 2-D data (column vectors); leaves a 10% 22 | ## margin around the plots. 23 | ## Inserts margins of +/- 0.1 if data is one-dimensional 24 | ## (or a single point). 25 | ## 26 | ## @strong{Input} 27 | ## @table @var 28 | ## @item axdata 29 | ## @var{n} by 2 matrix of data [@var{x}, @var{y}]. 30 | ## @end table 31 | ## 32 | ## @strong{Output} 33 | ## @table @var 34 | ## @item axvec 35 | ## Vector of axis limits appropriate for call to @command{axis} function. 36 | ## @end table 37 | ## @end deftypefn 38 | 39 | function axvec = __axis_margin__ (axdata) 40 | 41 | ## compute axis limits 42 | minv = axdata(1); 43 | maxv = axdata(2); 44 | delv = (maxv-minv)/2; # breadth of the plot 45 | midv = (minv + maxv)/2; # midpoint of the plot 46 | axmid = [midv, midv]; 47 | axdel = [-0.1, 0.1]; # default plot width (if less than 2-d data) 48 | 49 | if (delv == 0) 50 | if (midv != 0) 51 | axdel = [-0.1*midv, 0.1*midv]; 52 | endif 53 | else 54 | ## they're at least one-dimensional 55 | tolv = max(1e-8, 1e-8*abs(midv)); 56 | if (abs (delv) >= tolv) 57 | axdel = 1.1*[-delv,delv]; 58 | endif 59 | endif 60 | 61 | axvec = axmid + axdel; 62 | 63 | endfunction 64 | --------------------------------------------------------------------------------