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} {} eyediagram (@var{x},@var{n})
18 ## @deftypefnx {Function File} {} eyediagram (@var{x},@var{n},@var{per})
19 ## @deftypefnx {Function File} {} eyediagram (@var{x},@var{n},@var{per},@var{off})
20 ## @deftypefnx {Function File} {} eyediagram (@var{x},@var{n},@var{per},@var{off},@var{str})
21 ## @deftypefnx {Function File} {} eyediagram (@var{x},@var{n},@var{per},@var{off},@var{str},@var{h})
22 ## @deftypefnx {Function File} {@var{h} =} eyediagram (@var{...})
24 ## Plot the eye-diagram of a signal. The signal @var{x} can be either in one
28 ## @item A real vector
29 ## In this case the signal is assumed to be real and represented by the vector
30 ## @var{x}. A single eye-diagram representing this signal is plotted.
31 ## @item A complex vector
32 ## In this case the in-phase and quadrature components of the signal are
33 ## plotted seperately.
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.
39 ## Each line of the eye-diagram has @var{n} elements and the period is assumed
40 ## to be given by @var{per}. The time axis is then [-@var{per}/2 @var{per}/2].
41 ## By default @var{per} is 1.
43 ## By default the signal is assumed to start at -@var{per}/2. This can be
44 ## overridden by the @var{off} variable, which gives the number of samples
45 ## to delay the signal.
47 ## The string @var{str} is a plot style string (example 'r+'),
48 ## and by default is the default gnuplot line style.
50 ## The figure handle to use can be defined by @var{h}. If @var{h} is not
51 ## given, then the next available figure handle is used. The figure handle
52 ## used in returned on @var{hout}.
54 ## @seealso{scatterplot}
56 ## 2005-04-23 Dmitri A. Sergatskov <dasergatskov@gmail.com>
57 ## * modified for new gnuplot interface (octave > 2.9.0)
59 function varargout = eyediagram (x, n, _per, _off, str, h)
61 if ((nargin < 2) || (nargin > 6))
62 usage (" h = eyediagram (x, n [, per [, off [, str [, h]]]])");
66 if (min(size(x)) == 1)
69 elseif (size(x,2) == 2)
74 error ("eyediagram: real signal input must be a vector");
78 if (min(size(x)) != 1)
79 error ("eyediagram: complex signal input must be a vector");
86 error ("eyediagram: zero length signal");
89 if (!isscalar(n) || !isreal(n) || (floor(n) != n) || (n < 1))
90 error ("eyediagram: n must be a positive non-zero integer");
96 elseif (isscalar(_per) && isreal(_per))
99 error ("eyediagram: period must be a real scalar");
108 elseif (!isscalar(_off) || !isreal(_off) || (floor(_off) != _off) || ...
109 (_off < 0) || (_off > (n-1)))
110 error ("eyediagram: offset must be an integer between 0 and n");
124 error ("eyediagram: plot format must be a string");
140 horiz = (per*[0:n]/n - per/2)';
141 if (2*floor(n/2) != n)
142 horiz = horiz - per / n / 2;
145 off = mod(off+ceil(n/2),n);
146 Nn = ceil((off + lx) / n);
147 post = Nn*n - off - lx;
148 xr = reshape([NaN * ones(off,1); xr; NaN * ones(post,1)],n,Nn);
149 xr = [xr ; [xr(1,2:end), NaN]];
150 xr = [xr; NaN*ones(1,Nn)];
151 if (all(isnan(xr(2:end,end))))
153 horiz = [repmat(horiz(1:n+1),1,Nn-1);NaN*ones(1,Nn-1)](:);
155 horiz = [repmat(horiz(1:n+1),1,Nn);NaN*ones(1,Nn)](:);
158 if (strcmp(signal,"complex"))
159 xi = reshape([NaN * ones(off,1); xi; NaN * ones(post,1)],n,Nn);
160 xi = [xi ; [xi(1,2:end), NaN]];
161 xi = [xi; NaN*ones(1,Nn)];
162 if (all(isnan(xi(2:end,end))))
167 if (strcmp(signal,"complex"))
169 plot(horiz,xr(:),fmt);
170 title("Eye-diagram for in-phase signal");
174 plot(horiz,xi(:),fmt);
175 title("Eye-diagram for quadrature signal");
179 plot(horiz,xr(:),fmt);
180 title("Eye-diagram for signal");
195 %! xi = [1:1/ovsp:n-0.1];
196 %! y = randsrc(1,n,[1 + 1i, 1 - 1i, -1 - 1i, -1 + 1i]) ;
197 %! yi = interp1(x,y,xi);
198 %! noisy = awgn(yi,15,"measured");
199 %! eyediagram(noisy,ovsp);