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

📄 encode_symbol.m

📁 压缩包中的内容用matlab语言对算术码进行描述
💻 M
字号:
function [output_bits] = encode_symbol( symbol, esti_prob, num_symbol )
global Low High UnderFlow_Bits
global K

totals = cumsum(esti_prob);
if (symbol == 1)
    s.low_count = 0;
    s.high_count = totals(1);
else
    s.low_count = totals(symbol-1);
    s.high_count = totals(symbol);
end
s.scale = totals(num_symbol) + 1;
    
Range = High - Low + 1;
High = Low + floor(( Range * s.high_count ) / s.scale - 1 );
Low = Low + floor(( Range * s.low_count ) / s.scale );

output_bits=0;
while ( 1==1 )
    High_MSB = bitget( High, K );
    Low_MSB = bitget( Low, K );
    if ( High_MSB == Low_MSB ) 
        OutputBit( High_MSB );
        output_bits = output_bits + 1;
        while ( UnderFlow_Bits > 0 ) 
            OutputBit( ~High_MSB );
            output_bits = output_bits + 1;
            UnderFlow_Bits = UnderFlow_Bits - 1;    
        end    
    else 
        if (bitget(Low, K-1) & (~bitget(High, K-1))) 
            UnderFlow_Bits = UnderFlow_Bits + 1;
            Low = bitset(Low, K-1, 0);
            High = bitset(High, K-1, 1);
        else
            break;
        end
    end
   Low=bitset(Low * 2, K + 1, 0);
   High=bitset(High * 2 + 1, K + 1, 0);
end
return

function OutputBit( bit )
global out_bit_file 
out_bit_file.rack = bitset(out_bit_file.rack, out_bit_file.mask, bit);
out_bit_file.mask = out_bit_file.mask - 1;
if ( out_bit_file.mask == 0 ) 
    if ( fwrite( out_bit_file.file, out_bit_file.rack, 'uint8' ) ~= 1 )
        fprintf( 'Fatal error in OutputBit!\n' );
    else
        out_bit_file.rack = uint8(0);
        out_bit_file.mask = 8;
    end
end
return

⌨️ 快捷键说明

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