⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 biterr.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [num, rat] = biterr(x, y, K, tot)
%BITERR Computes bit error.
%       [NUMBER, RATIO] = BITERR(X, Y) compares the elements in the input
%       matrices X and Y. The number of the bit differences is outputted in 
%       NUMBER. The ratio of NUMBER to the total bit number contained in
%       Y is output in RATIO. All elements in X and Y should be non-negative
%       integers. The total bit number in Y is estimated by 
%            column_y * row_y * K, 
%       where K is the bit number for each element in Y. K is the smallest
%       integer satisfying MAX < 2^K, where MAX is the maximum number in both
%       X and Y. When X or Y is a matrix and the other is a vector, this 
%       function convert the vectors to a matrix with the column number the
%       same as the matrix before the comparison.
%
%       [NUMBER, RATIO] = BITERR(X, Y, K) specifies the bit number in X and Y
%       in the calculation.
%
%       [NUMBER, RATIO] = BITERR(X, Y, K, 'columnwise') NUMBER and RATIO are
%       row vectors with the number and ratio for each column comparison.
%
%       See also SYMERR.

%       Wes Wang 1/14/94, 9/30/95.
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 17:52:24 $

[nx, mx] = size(x);
[ny, my] = size(y);

if (min(nx, mx) < 1) | (min(ny, my) < 1)
    num = [];
    rat = [];
    return;
elseif (min(nx, mx) > 1) & (min(ny, my) > 1)
    if (nx ~= ny) | (mx ~= my)
        error('Dimentions must be agree.')
    end;
else
    if min(nx, mx) <= 1
        x = x(:);
        if (size(x, 1) ~= ny)
            error('Dimentions must be agree.')
        else
            x = x * ones(1, my);
        end;
    elseif min(ny, my) <= 1
        y = y(:);
        if (size(y, 1) ~= nx)
            error('Dimentions must be agree.')
        else
            y = y * ones(1, mx);
        end;
        [ny, my] = size(y);
    else
        error('Dimentions must be agree.')
    end;
end;

if nargin < 3
    M = max(max(max(y)), max(max(x))) + 1;
    M = 2^(ceil(log(M)/log(2)));
    M = max(2, M);
    K = ceil(log(M)/log(2));
end;
z = flxor(x, y);

if nargin <= 3
    vec = find(z ~= 0);
    if isempty(vec)
        num = 0;
        rat = 0;
    else
        vec = z(vec);
        num = sum(sum(de2bi(vec, K)));
        rat = num / (ny * my * K);
    end;
else
    if findstr(tot, 'row')
        num = zeros(ny, 1);
        for i = 1 : ny
            vec = find(z(i, :) ~= 0);
            if isempty(vec)
                num(i) = 0;
            else
                vec = z(i, vec);
                num(i) = sum(sum(de2bi(vec, K)));
            end;
        end;
        num = num / my / K;
    else
        num = zeros(1, my);
        for i = 1 : my
            vec = find(z(:, i) ~= 0);
            if isempty(vec)
                num(i) = 0;
            else
                vec = z(vec, i);
                num(i) = sum(sum(de2bi(vec, K)));
            end;
        end;
        num = num / ny / K;
    end;
end;

% end of biterr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -