Mercurial > forge
annotate main/comm/inst/biterr.m @ 9666:67d4cfc5eeb3 octave-forge
comm: update license to GPLv3+
author | carandraug |
---|---|
date | Tue, 13 Mar 2012 04:31:21 +0000 |
parents | b81e11a89ae2 |
children | fe6da9839797 |
rev | line source |
---|---|
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
1 ## Copyright (C) 2003 David Bateman |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
2 ## |
9666 | 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 | |
6 ## version. | |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
7 ## |
9666 | 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 | |
11 ## details. | |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
12 ## |
9666 | 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/>. | |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
15 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
16 ## -*- texinfo -*- |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
17 ## @deftypefn {Function File} {[@var{num}, @var{rate}] = } biterr (@var{a},@var{b}) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
18 ## @deftypefnx {Function File} {[@var{num}, @var{rate}] = } biterr (@var{...},@var{k}) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
19 ## @deftypefnx {Function File} {[@var{num}, @var{rate}] = } biterr (@var{...},@var{flag}) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
20 ## @deftypefnx {Function File} {[@var{num}, @var{rate} @var{ind}] = } biterr (@var{...}) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
21 ## |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
22 ## Compares two matrices and returns the number of bit errors and the bit |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
23 ## error rate. The binary representations of the variables @var{a} and |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
24 ## @var{b} are treated and @var{a} and @var{b} can be either: |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
25 ## |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
26 ## @table @asis |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
27 ## @item Both matrices |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
28 ## In this case both matrices must be the same size and then by default the |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
29 ## the return values @var{num} and @var{rate} are the overall number of bit |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
30 ## errors and the overall bit error rate. |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
31 ## @item One column vector |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
32 ## In this case the column vector is used for bit error comparision column-wise |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
33 ## with the matrix. The returned values @var{num} and @var{rate} are then |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
34 ## row vectors containing the num of bit errors and the bit error rate for |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
35 ## each of the column-wise comparisons. The number of rows in the matrix |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
36 ## must be the same as the length of the column vector |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
37 ## @item One row vector |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
38 ## In this case the row vector is used for bit error comparision row-wise |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
39 ## with the matrix. The returned values @var{num} and @var{rate} are then |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
40 ## column vectors containing the num of bit errors and the bit error rate for |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
41 ## each of the row-wise comparisons. The number of columns in the matrix |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
42 ## must be the same as the length of the row vector |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
43 ## @end table |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
44 ## |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
45 ## This behaviour can be overridden with the variable @var{flag}. @var{flag} |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
46 ## can take the value 'column-wise', 'row-wise' or 'overall'. A column-wise |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
47 ## comparision is not possible with a row vector and visa-versa. |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
48 ## |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
49 ## By default the number of bits in each symbol is assumed to be give by the |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
50 ## number required to represent the maximum value of @var{a} and @var{b}. |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
51 ## The number of bits to represent a symbol can be overridden by the variable |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
52 ## @var{k}. |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
53 ## @end deftypefn |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
54 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
55 ## 2003 FEB 13 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
56 ## initial release |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
57 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
58 function [num, rate, ind] = biterr (a, b, varargin) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
59 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
60 if ((nargin < 2) || (nargin > 4)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
61 usage ("[num rate ind] = biterr (a, b [,k [,flag]])"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
62 endif |
5839 | 63 |
64 if (ndims (a) > 2 || ndims (b) > 2) | |
65 error ("biterr: a and b must have at most two dimensions"); | |
66 endif | |
67 | |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
68 if (any(any(isinf(a))) || any(any(isnan(a))) || any(any(isinf(b))) || ... |
5839 | 69 any(any(isnan(b))) || !isreal(a) || !isreal(b) || ... |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
70 any(any((floor(a)) != a)) || any(any((floor(b)) != b)) || ... |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
71 any(any(a < 0)) || any(any(b < 0))) |
5839 | 72 error ("biterr: a and b must contain only non-negative integers"); |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
73 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
74 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
75 [ar,ac] = size(a); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
76 [br,bc] = size(b); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
77 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
78 k = max([max(a(:)),max(b(:))]); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
79 m = 1; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
80 while (k > (2^m-1)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
81 m = m + 1; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
82 end |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
83 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
84 if ((ar == br) && (ac == bc)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
85 type = "matrix"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
86 flag = "overall"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
87 c = 1; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
88 elseif (any([ar,br] == 1)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
89 type = "row"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
90 flag = "row"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
91 if (ac != bc) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
92 error ("biterr: row-wise comparison must have the same number of columns in inputs"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
93 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
94 if (ar == 1) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
95 a = ones(br,1) * a; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
96 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
97 b = ones(ar,1) * b; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
98 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
99 elseif (any([ac,bc] == 1)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
100 type = "column"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
101 flag = "column"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
102 if (ar != br) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
103 error ("biterr: column-wise comparison must have the same number of rows in inputs"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
104 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
105 if (ac == 1) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
106 a = a * ones(1,bc); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
107 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
108 b = b * ones(1,ac); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
109 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
110 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
111 error ("biterr: matrix sizes must match"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
112 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
113 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
114 k = 0; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
115 for i =1:length(varargin) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
116 arg = varargin{i}; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
117 if (ischar(arg)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
118 if (strcmp(arg,"row-wise")) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
119 if (strcmp(type,"column")) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
120 error ("biterr: row-wise comparison not possible with column inputs"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
121 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
122 flag = "row"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
123 elseif (strcmp(arg,"column-wise")) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
124 if (strcmp(type,"row")) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
125 error ("biterr: column-wise comparison not possible with row inputs"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
126 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
127 flag = "column"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
128 elseif (strcmp(arg,"overall")) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
129 flag = "overall"; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
130 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
131 error ("biterr: unrecognized string argument"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
132 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
133 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
134 k = arg; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
135 if (k < m) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
136 error ("biterr: the symbol size is too small for largest element"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
137 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
138 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
139 end |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
140 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
141 if (k == 0) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
142 k = m; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
143 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
144 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
145 ## Call the core error function to count the bit errors |
2605 | 146 ind = __errcore__(a,b); |
2382
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
147 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
148 switch (flag) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
149 case 'row', |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
150 if (strcmp(type,"matrix") && (ac == 1)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
151 num = ind; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
152 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
153 num = sum(ind')'; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
154 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
155 rate = num / k / max(ac,bc); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
156 case 'column', |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
157 if (strcmp(type,"matrix") && (ar == 1)) |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
158 num = ind; |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
159 else |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
160 num = sum(ind); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
161 endif |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
162 rate = num / k / max(ar,br); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
163 case 'overall', |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
164 num = sum(sum(ind)); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
165 rate = num / k / max(ar,br) / max(ac,bc); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
166 otherwise |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
167 error("impossible"); |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
168 endswitch |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
169 |
5056d2d5eb72
Changed the directory structure of comm to match the package system
hauberg
parents:
diff
changeset
|
170 endfunction |