File: plot.m

package info (click to toggle)
octave-control 2.6.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,576 kB
  • ctags: 414
  • sloc: cpp: 6,640; objc: 215; makefile: 38
file content (117 lines) | stat: -rw-r--r-- 3,663 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
## Copyright (C) 2009-2014   Lukas F. Reichlin
##
## This file is part of LTI Syncope.
##
## LTI Syncope 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.
##
## LTI Syncope 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 LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {} plot (@var{dat})
## @deftypefnx {Function File} {} plot (@var{dat}, @var{exp})
## Plot signals of iddata identification datasets on the screen.
## The signals are plotted experiment-wise, either in time- or
## frequency-domain.  For multi-experiment datasets,
## press any key to switch to the next experiment.
## If the plot of a single experiment should be saved by the
## @command{print} command, use @code{plot(dat,exp)},
## where @var{exp} denotes the desired experiment.
## @end deftypefn

## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
## Created: February 2012
## Version: 0.2

function plot (dat, exp = ":")

  if (nargin > 2)       # nargin == 0  is handled by built-in plot
    print_usage ();
  endif

  if (nargin == 2 && ! is_real_vector (exp))
    error ("iddata: plot: second argument must be a vector of indices");
  endif 

  expname = __labels__ (dat.expname, "exp");
  expname = expname(exp);
  
  idx = substruct ("()", {":", ":", ":", exp});  
  dat = subsref (dat, idx);
  
  [n, p, m, e] = size (dat);

  if (dat.timedomain)
    if (m == 0)         # time series
      for k = 1 : e
        if (k > 1)
          pause
        endif
        plot (dat.y{k})
        title (expname{k})
        legend (__labels__ (dat.outname, "y"){:})
        xlabel ("Time")
        ylabel ("Output Signal")
      endfor
    else                # inputs present
      for k = 1 : e
        if (k > 1)
          pause
        endif
        subplot (2, 1, 1)
        plot (dat.y{k})
        title (expname{k})
        legend (__labels__ (dat.outname, "y"){:})
        ylabel ("Output Signal")
        subplot (2, 1, 2)
        stairs (dat.u{k})
        legend (__labels__ (dat.inname, "u"){:})
        xlabel ("Time")
        ylabel ("Input Signal")
      endfor
    endif
  else                  # frequency domain
    if (m == 0)         # time series
      for k = 1 : e
        if (k > 1)
          pause
        endif
        bar (dat.w{k}, 20*log10 (abs (dat.y{k})))
        xlim ([dat.w{k}(1), dat.w{k}(end)])
        title (expname{k})
        legend (__labels__ (dat.outname, "y"){:})
        xlabel ("Frequency")
        ylabel ("Output Magnitude [dB]")
      endfor
    else                # inputs present
      for k = 1 : e
        if (k > 1)
          pause
        endif
        subplot (2, 1, 1)
        bar (dat.w{k}, 20*log10 (abs (dat.y{k})))
        xlim ([dat.w{k}(1), dat.w{k}(end)])
        title (expname{k})
        legend (__labels__ (dat.outname, "y"){:})
        ylabel ("Output Magnitude [dB]")
        subplot (2, 1, 2)
        bar (dat.w{k}, 20*log10(abs (dat.u{k})))
        xlim ([dat.w{k}(1), dat.w{k}(end)])
        legend (__labels__ (dat.inname, "u"){:})
        xlabel ("Frequency")
        ylabel ("Input Magnitude [dB]")
      endfor
    endif
  endif

  ## TODO: think about the 20*log10 and the bars in general

endfunction