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}] = } biterr (@var{a},@var{b})
18 ## @deftypefnx {Function File} {[@var{num}, @var{rate}] = } biterr (@var{...},@var{k})
19 ## @deftypefnx {Function File} {[@var{num}, @var{rate}] = } biterr (@var{...},@var{flag})
20 ## @deftypefnx {Function File} {[@var{num}, @var{rate} @var{ind}] = } biterr (@var{...})
22 ## Compares two matrices and returns the number of bit errors and the bit
23 ## error rate. The binary representations of the variables @var{a} and
24 ## @var{b} are treated and @var{a} and @var{b} can be either:
27 ## @item Both matrices
28 ## In this case both matrices must be the same size and then by default the
29 ## the return values @var{num} and @var{rate} are the overall number of bit
30 ## errors and the overall bit error rate.
31 ## @item One column vector
32 ## In this case the column vector is used for bit error comparision column-wise
33 ## with the matrix. The returned values @var{num} and @var{rate} are then
34 ## row vectors containing the num of bit errors and the bit error rate for
35 ## each of the column-wise comparisons. The number of rows in the matrix
36 ## must be the same as the length of the column vector
37 ## @item One row vector
38 ## In this case the row vector is used for bit error comparision row-wise
39 ## with the matrix. The returned values @var{num} and @var{rate} are then
40 ## column vectors containing the num of bit errors and the bit error rate for
41 ## each of the row-wise comparisons. The number of columns in the matrix
42 ## must be the same as the length of the row vector
45 ## This behaviour can be overridden with the variable @var{flag}. @var{flag}
46 ## can take the value 'column-wise', 'row-wise' or 'overall'. A column-wise
47 ## comparision is not possible with a row vector and visa-versa.
49 ## By default the number of bits in each symbol is assumed to be give by the
50 ## number required to represent the maximum value of @var{a} and @var{b}.
51 ## The number of bits to represent a symbol can be overridden by the variable
58 function [num, rate, ind] = biterr (a, b, varargin)
60 if ((nargin < 2) || (nargin > 4))
61 usage ("[num rate ind] = biterr (a, b [,k [,flag]])");
64 if (ndims (a) > 2 || ndims (b) > 2)
65 error ("biterr: a and b must have at most two dimensions");
68 if (any(any(isinf(a))) || any(any(isnan(a))) || any(any(isinf(b))) || ...
69 any(any(isnan(b))) || !isreal(a) || !isreal(b) || ...
70 any(any((floor(a)) != a)) || any(any((floor(b)) != b)) || ...
71 any(any(a < 0)) || any(any(b < 0)))
72 error ("biterr: a and b must contain only non-negative integers");
78 k = max([max(a(:)),max(b(:))]);
84 if ((ar == br) && (ac == bc))
88 elseif (any([ar,br] == 1))
92 error ("biterr: row-wise comparison must have the same number of columns in inputs");
99 elseif (any([ac,bc] == 1))
103 error ("biterr: column-wise comparison must have the same number of rows in inputs");
111 error ("biterr: matrix sizes must match");
115 for i =1:length(varargin)
118 if (strcmp(arg,"row-wise"))
119 if (strcmp(type,"column"))
120 error ("biterr: row-wise comparison not possible with column inputs");
123 elseif (strcmp(arg,"column-wise"))
124 if (strcmp(type,"row"))
125 error ("biterr: column-wise comparison not possible with row inputs");
128 elseif (strcmp(arg,"overall"))
131 error ("biterr: unrecognized string argument");
136 error ("biterr: the symbol size is too small for largest element");
145 ## Call the core error function to count the bit errors
146 ind = __errcore__(a,b);
150 if (strcmp(type,"matrix") && (ac == 1))
155 rate = num / k / max(ac,bc);
157 if (strcmp(type,"matrix") && (ar == 1))
162 rate = num / k / max(ar,br);
165 rate = num / k / max(ar,br) / max(ac,bc);