1 ## Copyright (C) 2009, 2010, 2011, 2012 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
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.
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.
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/>.
19 ## @deftypefn {Function File} {[@var{mag}, @var{w}] =} bodemag (@var{sys})
20 ## @deftypefnx {Function File} {[@var{mag}, @var{w}] =} bodemag (@var{sys}, @var{w})
21 ## Bode magnitude diagram of frequency response. If no output arguments are given,
22 ## the response is printed on the screen.
27 ## LTI system. Must be a single-input and single-output (SISO) system.
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
39 ## Vector of magnitude. Has length of frequency vector @var{w}.
41 ## Vector of frequency values used.
44 ## @seealso{bode, nichols, nyquist, sigma}
47 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
48 ## Created: November 2009
51 function [mag_r, w_r] = bodemag (sys, w = [])
53 ## TODO: multiplot feature: bodemag (sys1, "b", sys2, "r", ...)
55 if (nargin == 0 || nargin > 2)
59 [H, w] = __frequency_response__ (sys, w, false, 0, "std");
61 H = reshape (H, [], 1);
65 mag_db = 20 * log10 (mag);
68 xl_str = "Frequency [rad/s]";
70 xl_str = sprintf ("Frequency [rad/s] w_N = %g", pi / get (sys, "tsam"));
75 ylim (__axis_margin__ (ylim))
77 title (["Bode Magnitude Diagram of ", inputname(1)])
79 ylabel ("Magnitude [dB]")