From: <sla...@us...> - 2009-07-06 09:07:01
|
Revision: 5988 http://octave.svn.sourceforge.net/octave/?rev=5988&view=rev Author: slackydeb Date: 2009-07-06 09:06:55 +0000 (Mon, 06 Jul 2009) Log Message: ----------- Add margin (thanks to Lukas Reichlin <luk...@sw...>). Modified Paths: -------------- trunk/octave-forge/main/control/INDEX Added Paths: ----------- trunk/octave-forge/main/control/inst/margin.m Modified: trunk/octave-forge/main/control/INDEX =================================================================== --- trunk/octave-forge/main/control/INDEX 2009-07-06 08:58:15 UTC (rev 5987) +++ trunk/octave-forge/main/control/INDEX 2009-07-06 09:06:55 UTC (rev 5988) @@ -55,6 +55,7 @@ bode bode_bounds nichols freqchkw ltifr nyquist tzero tzero2 rlocus + margin Controller design dgkfdemo hinfdemo dhinfdemo dlqe dlqr lqe lqg lqr Added: trunk/octave-forge/main/control/inst/margin.m =================================================================== --- trunk/octave-forge/main/control/inst/margin.m (rev 0) +++ trunk/octave-forge/main/control/inst/margin.m 2009-07-06 09:06:55 UTC (rev 5988) @@ -0,0 +1,76 @@ +## Copyright (C) 2009 Doug Stewart and Lukas Reichlin +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program; if not, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +## -*- texinfo -*- +## @deftypefn{Function File} {[@var{gamma}, @var{phi}, @var{w_gamma}, @var{w_phi}] =} margin (@var{sys}) +## Gain and phase margins. +## +## @strong{Inputs} +## @table @var +## @item sys +## Continuous time system. +## @end table +## +## @strong{Outputs} +## @table @var +## @item gamma +## Gain margin (as gain, not dbs). +## @item phi +## Phase margin (in degrees). +## @item w_gamma +## Radian frequency for the gain margin. +## @item w_phi +## Radian frequency for the phase margin. +## @end table +## +## @seealso{bode} +## @end deftypefn + +## Version: 0.1alpha + + +function [gamma, phi, w_gamma, w_phi] = margin(sys) + + if (nargin != 1 || (! isstruct (sys))) + print_usage (); + endif + + ## Get Frequency Response + [mag, pha, w] = bode (sys); + + ## fix the phase wrap around + phw = unwrap (pha * pi/180); + pha = phw * 180/pi; + + ## find the Gain Margin and its location + [x, ix] = min (abs (pha + 180)); + + if (x > 1) + gamma = "INF"; + ix = length (pha); + else + gamma = 1 / mag(ix); + endif + + w_gamma = w(ix); + + ## find the Phase Margin and its location + [pmx, ipmx] = min (abs (mag - 1)); + + phi = 180 + pha(ipmx); + w_phi = w(ipmx); + +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |