]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/nichols.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / nichols.m
1 ## Copyright (C) 2009, 2010, 2011, 2012   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 <http://www.gnu.org/licenses/>.
17
18 ## -*- texinfo -*-
19 ## @deftypefn {Function File} {[@var{mag}, @var{pha}, @var{w}] =} nichols (@var{sys})
20 ## @deftypefnx {Function File} {[@var{mag}, @var{pha}, @var{w}] =} nichols (@var{sys}, @var{w})
21 ## Nichols chart of frequency response.  If no output arguments are given,
22 ## the response is printed on the screen.
23 ##
24 ## @strong{Inputs}
25 ## @table @var
26 ## @item sys
27 ## LTI system.  Must be a single-input and single-output (SISO) system.
28 ## @item w
29 ## Optional vector of frequency values.  If @var{w} is not specified,
30 ## it is calculated by the zeros and poles of the system.
31 ## Alternatively, the cell @code{@{wmin, wmax@}} specifies a frequency range,
32 ## where @var{wmin} and @var{wmax} denote minimum and maximum frequencies
33 ## in rad/s.
34 ## @end table
35 ##
36 ## @strong{Outputs}
37 ## @table @var
38 ## @item mag
39 ## Vector of magnitude.  Has length of frequency vector @var{w}.
40 ## @item pha
41 ## Vector of phase.  Has length of frequency vector @var{w}.
42 ## @item w
43 ## Vector of frequency values used.
44 ## @end table
45 ##
46 ## @seealso{bode, nyquist, sigma}
47 ## @end deftypefn
48
49 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
50 ## Created: November 2009
51 ## Version: 0.4
52
53 function [mag_r, pha_r, w_r] = nichols (sys, w = [])
54
55   ## TODO: multiplot feature:   nichols (sys1, "b", sys2, "r", ...)
56
57   if (nargin == 0 || nargin > 2)
58     print_usage ();
59   endif
60
61   [H, w] = __frequency_response__ (sys, w, false, 0, "ext");
62
63   H = reshape (H, [], 1);
64   mag = abs (H);
65   pha = unwrap (arg (H)) * 180 / pi;
66
67   if (! nargout)
68     mag_db = 20 * log10 (mag);
69     
70     plot (pha, mag_db)
71     axis ("tight")
72     xlim (__axis_margin__ (xlim))
73     ylim (__axis_margin__ (ylim))
74     grid ("on")
75     title (["Nichols Chart of ", inputname(1)])
76     xlabel ("Phase [deg]")
77     ylabel ("Magnitude [dB]")
78   else
79     mag_r = mag;
80     pha_r = pha;
81     w_r = w;
82   endif
83
84 endfunction