📄 main_encode.m
字号:
% This is main program for encode
clc
clear all
clear global
format long
global no_of_chars no_of_symbols cum_freq char_to_index index_to_char low high top_value code_value_bits bits_to_follow first_qtr third_qtr bits_to_go buffer output max_freq freq
% ---------------------------------------------------------------------------------------
code_value_bits=16;
no_of_chars=256;
eof_symbol=no_of_chars+1;
no_of_symbols=no_of_chars+1;
max_frequency=16383;
top_value=2^code_value_bits-1;
first_qtr=fix(top_value / 4) +1;
half=fix(2*first_qtr);
third_qtr=fix(3*first_qtr);
output=[];
% ---------------------------------------------------------------------------------------
% Read the input file from text.txt
choice=2;
fid=fopen('text.txt','r');
fid2=fopen('compressed.txt','w');
if (choice==1)
start_model_fixed;
else
start_model_adaptive;
end
start_outputting_bits;
start_encoding;
while (1~=0)
ch = fread(fid,1);
if(feof(fid)),break;end
symbol=char_to_index(ch);
encode_symbol(symbol,cum_freq);
if choice~=1
update_model_adaptive(symbol);
end
end
encode_symbol(eof_symbol,cum_freq);
done_encoding;
done_outputting_bits;
for ii=1:length(output)
fprintf(fid2,'%c',output(ii));
end
fclose(fid);
fclose(fid2)
disp('COMPLETE')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -