1 ## Copyright (C) 2003 David Bateman
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {} scatterplot (@var{x})
18 ## @deftypefnx {Function File} {} scatterplot (@var{x},@var{n})
19 ## @deftypefnx {Function File} {} scatterplot (@var{x},@var{n},@var{off})
20 ## @deftypefnx {Function File} {} scatterplot (@var{x},@var{n},@var{off},@var{str})
21 ## @deftypefnx {Function File} {} scatterplot (@var{x},@var{n},@var{off},@var{str},@var{h})
22 ## @deftypefnx {Function File} {@var{h} =} scatterplot (@var{...})
24 ## Display the scatter plot of a signal. The signal @var{x} can be either in
28 ## @item A real vector
29 ## In this case the signal is assumed to be real and represented by the vector
30 ## @var{x}. The scatterplot is plotted along the x axis only.
31 ## @item A complex vector
32 ## In this case the in-phase and quadrature components of the signal are
33 ## plotted seperately on the x and y axes respectively.
34 ## @item A matrix with two columns
35 ## In this case the first column represents the in-phase and the second the
36 ## quadrature components of a complex signal and are plotted on the x and
37 ## y axes respectively.
40 ## Each point of the scatter plot is assumed to be seperated by @var{n}
41 ## elements in the signal. The first element of the signal to plot is
42 ## determined by @var{off}. By default @var{n} is 1 and @var{off} is 0.
44 ## The string @var{str} is a plot style string (example 'r+'),
45 ## and by default is the default gnuplot point style.
47 ## The figure handle to use can be defined by @var{h}. If @var{h} is not
48 ## given, then the next available figure handle is used. The figure handle
49 ## used in returned on @var{hout}.
51 ## @seealso{eyediagram}
53 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com>
54 ## * modified for new gnuplot interface (octave > 2.9.0)
56 function varargout = scatterplot (x, n, _off, str, h)
58 if ((nargin < 1) || (nargin > 5))
59 usage (" h = scatterplot (x, n [, off [, str [, h]]]])");
63 if (min(size(x)) == 1)
67 elseif (size(x,2) == 2)
72 error ("scatterplot: real signal input must be a vector");
76 if (min(size(x)) != 1)
77 error ("scatterplot: complex signal input must be a vector");
84 error ("scatterplot: zero length signal");
88 if (!isscalar(n) || !isreal(n) || (floor(n) != n) || (n < 1))
89 error ("scatterplot: n must be a positive non-zero integer");
96 if (!isscalar(_off) || !isreal(_off) || (floor(_off) != _off) || ...
97 (_off < 0) || (_off > length(x)-1))
98 error ("scatterplot: offset must be an integer between 0 and length(x)-1");
111 error ("scatterplot: plot format must be a string");
123 xr = xr(off+1:n:rows(xr));
124 xi = xi(off+1:n:rows(xi));
127 if (!strcmp(signal,"complex"))
128 ## FIXME: What is the appropriate xrange
132 xmax = ceil(2 * xmax / xran) / 2 * xran;
133 xmin = floor(2 * xmin / xran) / 2 * xran;
134 axis([xmin, xmax, -1, 1]);
136 title("Scatter plot");
138 ylabel("Quadrature");
151 %! xi = [1:1/ovsp:n-0.1];
152 %! y = randsrc(1,n,[1 + 1i, 1 - 1i, -1 - 1i, -1 + 1i]) ;
153 %! yi = interp1(x,y,xi);
154 %! noisy = awgn(yi,15,"measured");
156 %! h = scatterplot(noisy,1,0,"b",1);
158 %! scatterplot(noisy,ovsp,0,"r+",h);