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

📄 bin2float.m

📁 FPGA输出数据的时频域分析GUI界面
💻 M
字号:
function y = bin2float(x)
%BIN2FLOAT convert binary vector into float format.
%   y = bin2float(x) x must a binary vector or matrix. The first column
%   of x stands for signed bit.

%   Author:Harrison Zheng
%   ShenZhen HYT Science&Technology CO.,LTD.
%   Date:2006.11.30
if any(any(x>1)) || any(any(x<0)) || any(any(x~=fix(x)))
    error('Input x must be a binary vector or matrix');
end

[m,n] = size(x);
tmpInt = bi2de(x(:,2:end),'left-msb'); % Convert binary vectors to decimal numbers
y = zeros(m,1);
for k=1:m
    if ~x(k,1)                         % If the symbol bit is 0, ...
        y(k) = tmpInt(k);
    else                               % If the symbol bit is 1, ...
        if (tmpInt(k)==0)              % And if the data bit decinal number is 0
            y(k) = -(2^(n-1)-1);
        else                           % And if the data bit decinal number is not 0
            y(k) = -bi2de(logical2float(~de2bi(tmpInt(k)-1,...
                n-1,'left-msb')),'left-msb');
        end
    end
end
y = y/2^(n-1);

% EOF

⌨️ 快捷键说明

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