File: pzmap.m

package info (click to toggle)
octave-control 1.0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,628 kB
  • ctags: 160
  • sloc: makefile: 64; sh: 4
file content (88 lines) | stat: -rw-r--r-- 2,624 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
## Copyright (C) 1996, 1998, 2000, 2002, 2003, 2004, 2005, 2006, 2007
##               Auburn University.  All rights reserved.
##
##
## 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 3 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; see the file COPYING.  If not, see
## <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {[@var{zer}, @var{pol}] =} pzmap (@var{sys})
## Plots the zeros and poles of a system in the complex plane.
##
## @strong{Input}
## @table @var
## @item sys
## System data structure.
## @end table
##
## @strong{Outputs}
## @table @var
## @item pol
## @item zer
## if omitted, the poles and zeros are plotted on the screen.
## otherwise, @var{pol} and @var{zer} are returned as the 
## system poles and zeros (see @command{sys2zp} for a preferable function call).
## @end table
## @end deftypefn

function [zer, pol] = pzmap (sys)

  if (nargin != 1)
    print_usage ();
  elseif (! isstruct (sys));
    error ("pzmap: sys must be in system format");
  endif

  [zer, pol] = sys2zp (sys);

  ## force to column vectors, split into real, imaginary parts
  zerdata = poldata = [];
  if (length (zer))
    zer = reshape (zer, length (zer), 1);
    zerdata = [real(zer(:,1)), imag(zer(:,1))];
  endif
  if (length (pol))
    pol = reshape (pol, length (pol), 1);
    poldata = [real(pol(:,1)), imag(pol(:,1))];
  endif

  ## determine continuous or discrete plane
  vars = "sz";
  varstr = vars(is_digital (sys) + 1);

  ## Plot the data

  if (length (zer) == 0)
    plot (poldata(:,1), poldata(:,2), "@12 ;poles (no zeros);");
  elseif (length (pol) == 0)
    plot (zerdata(:,1), zerdata(:,2), "@31 ;zeros (no poles);");
  else
    plot (zerdata(:,1), zerdata(:,2), "@31 ;zeros;",
	  poldata(:,1), poldata(:,2), "@12 ;poles;");
  endif

  if (is_siso (sys))
    title (sprintf ("Pole-zero map from %s to %s",
		    sysgetsignals (sys, "in", 1, 1),
		    sysgetsignals (sys, "out", 1, 1)));
  endif

  xlabel (sprintf ("Re(%s)", varstr));
  ylabel (sprintf ("Im(%s)", varstr));
  grid ("on");

  ## compute axis limits
  axis (axis2dlim ([zerdata; poldata]));

endfunction