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

📄 golombcode1.m

📁 自适应 Golomb 编码
💻 M
字号:
function [MBits, RBits] = GolombCode1 (BFileNo, Codeword)
% Send codeword >= 0 by Adaptive Golomb Entropy Coder
% to the binary file BFileNo, and return the number of bits sent
% The File was opened elsewhere and must be closed elsewhere
% Xiaopeng WANG June 2004

global OutK1 Count AdapType PDF PDThresh CofG CGOff Top Bot FixedBit

ToShow = 20; % How many codewords to display


MBits = 0;
RBits = 0;
Count = Count + 1;
if Count < ToShow
    fprintf(' \n Count =%u  Code = %u ', Count, Codeword)
end 

% Calculate the MSB + 1 of the codeword
Code = abs(Codeword); % Negative values not expected
if Code == 0
    MSBPlus1 = 0;
else
    MSBPlus1 = 1 + fix(log2(Code));
end
if Count < ToShow
    fprintf('  MSB+1 = %u  Initial K = %u ', MSBPlus1, OutK1)
end
% Now send it
WasLow = 0;
% First the Exponent is adjusted upwards as necessary
while OutK1 < MSBPlus1
    WasLow = 1;
    bitsout(BFileNo, 0, 1);
    MBits = MBits + 1;
    OutK1 = OutK1 + 1;
end
% Now send the prefix 1
bitsout(BFileNo, 1, 1);
MBits = MBits + 1;
Resid = 0;
if OutK1 > 1
    if WasLow
        % We have counted up so are sure of MSB
        Resid = mod(Code, 2^(OutK1-1));
        bitsout(BFileNo, Resid, OutK1-1)
        RBits = OutK1-1;
    else
        % K was correct or high so we are not sure of MSB
        Resid = mod(Code, 2^OutK1);
        bitsout(BFileNo, Resid, OutK1)
        RBits = OutK1;
    end
end

if Count < ToShow
    fprintf('  Adjusted K = %u  Resid = %u ', OutK1, Resid)
end


if Count < ToShow
    fprintf('  Adapted K = %u  MSB Cost = %u R Cost = %u', OutK1, MBits, RBits)
end

if Count == ToShow
    if ToShow > 0
        keyboard
    end
end



⌨️ 快捷键说明

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