| Communications Toolbox | ![]() |
Logical Operations in Galois Fields
You can apply logical tests to Galois arrays and obtain a logical array. Some important types of tests are testing for equality of two Galois arrays and testing for nonzero values in a Galois array.
Testing for Equality
To compare corresponding elements of two Galois arrays that have the same size, use the operators == and ~=. The result is a logical array, each element of which indicates the truth or falsity of the corresponding elementwise comparison. If you use the same operators to compare a scalar with a Galois array, then MATLAB compares the scalar with each element of the array, producing a logical array of the same size.
m = 5; r1 = gf([1:3],m); r2 = 1 ./ r1; lg1 = (r1 .* r2 == [1 1 1]) % Does each element equal one? lg2 = (r1 .* r2 == 1) % Same as above, using scalar expansion lg3 = (r1 ~= r2) % Does each element differ from its inverse?
Comparison of isequal and ==. To compare entire arrays and obtain a logical scalar result rather than a logical array, you can use the built-in isequal function. Note, however, that isequal uses strict rules for its comparison, and returns a value of 0 (false) if you compare
The example below illustrates this difference between == and isequal.
m = 5; r1 = gf([1:3],m); r2 = 1 ./ r1; lg4 = isequal(r1 .* r2, [1 1 1]); % False lg5 = isequal(r1 .* r2, gf(1,m)); % False lg6 = isequal(r1 .* r2, gf([1 1 1],m)); % True
Testing for Nonzero Values
To test for nonzero values in a Galois vector, or in the columns of a Galois array that has more than one row, use the any or all function. These two functions behave just like the ordinary MATLAB functions any and all, except that they consider only the underlying array elements while ignoring information about which Galois field the elements are in. Examples are below.
m = 3; randels = gf(randint(6,1,2^m),m); if all(randels) % If all elements are invertible invels = randels .\ 1; % Compute inverses of elements. else disp('At least one element was not invertible.'); end alph = gf(2,4); poly = 1 + alph + alph^3; if any(poly) % If poly contains a nonzero value disp('alph is not a root of 1 + D + D^3.'); end code = rsenc(gf([0:4;3:7],3),7,5); % Each row is a code word. if all(code,2) % Is each row entirely nonzero? disp('Both code words are entirely nonzero.'); else disp('At least one code word contains a zero.'); end
| Arithmetic in Galois Fields | Matrix Manipulation in Galois Fields | ![]() |