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} {[@var{num}, @var{rate}] = } symerr (@var{a},@var{b})
18 ## @deftypefnx {Function File} {[@var{num}, @var{rate}] = } symerr (@var{...},@var{flag})
19 ## @deftypefnx {Function File} {[@var{num}, @var{rate} @var{ind}] = } symerr (@var{...})
21 ## Compares two matrices and returns the number of symbol errors and the
22 ## symbol error rate. The variables @var{a} and @var{b} can be either:
25 ## @item Both matrices
26 ## In this case both matrices must be the same size and then by default the
27 ## the return values @var{num} and @var{rate} are the overall number of symbol
28 ## errors and the overall symbol error rate.
29 ## @item One column vector
30 ## In this case the column vector is used for symbol error comparision
31 ## column-wise with the matrix. The returned values @var{num} and @var{rate}
32 ## are then row vectors containing the num of symbol errors and the symbol
33 ## error rate for each of the column-wise comparisons. The number of rows in
34 ## the matrix must be the same as the length of the column vector
35 ## @item One row vector
36 ## In this case the row vector is used for symbol error comparision row-wise
37 ## with the matrix. The returned values @var{num} and @var{rate} are then
38 ## column vectors containing the num of symbol errors and the symbol error rate
39 ## for each of the row-wise comparisons. The number of columns in the matrix
40 ## must be the same as the length of the row vector
43 ## This behaviour can be overridden with the variable @var{flag}. @var{flag}
44 ## can take the value 'column-wise', 'row-wise' or 'overall'. A column-wise
45 ## comparision is not possible with a row vector and visa-versa.
51 function [num, rate, ind] = symerr (a, b, _flag)
53 if ((nargin < 2) || (nargin > 4))
54 usage ("[num rate ind] = symerr (a, b [,flag])");
56 if (any(any(isinf(a))) || any(any(isnan(a))) || any(any(isinf(b))) || ...
57 any(any(isnan(b))) || !real(a) || !real(b) || ...
58 any(any((floor(a)) != a)) || any(any((floor(b)) != b)) || ...
59 any(any(a < 0)) || any(any(b < 0)))
60 error ("symerr: a and b must contain only postive integers");
66 if ((ar == br) && (ac == bc))
70 elseif (any([ar,br] == 1))
74 error ("symerr: row-wise comparison must have the same number of columns in inputs");
81 elseif (any([ac,bc] == 1))
85 error ("symerr: column-wise comparison must have the same number of rows in inputs");
93 error ("symerr: matrix sizes must match");
98 if (strcmp(_flag,"row-wise"))
99 if (strcmp(type,"column"))
100 error ("symerr: row-wise comparison not possible with column inputs");
103 elseif (strcmp(_flag,"column-wise"))
104 if (strcmp(type,"row"))
105 error ("symerr: column-wise comparison not possible with row inputs");
108 elseif (strcmp(_flag,"overall"))
111 error ("symerr: unrecognized string argument");
114 error ("symerr: unrecognized argument");
118 ## Call the core error function to count the bit errors
119 ind = (__errcore__(a,b) != 0);
123 if (strcmp(type,"matrix") && (ac == 1))
128 rate = num / max(ac,bc);
130 if (strcmp(type,"matrix") && (ar == 1))
135 rate = num / max(ar,br);
138 rate = num / max(ar,br) / max(ac,bc);