huffman encoding and compression
2 ビュー (過去 30 日間)
古いコメントを表示
I have a data set that I imported to MATLAB using textscan, and now I want to encode/compress it. The data set is 3660x4, I used this script to upload it:
fileID=fopen('filename');
if fileID < 3
disp('Error: file couldn''t be opened.')
else
C = textscan(fileID,'%s %s %s %s')
end
And got this:
C =
{3660x1 cell} {3660x1 cell} {3660x1 cell} {3660x1 cell}
What I originally did was take each column, round the data (so that the code would work, if I didnt round it, I would get a repmat error), put it through the code, and get the dictionary and encoded data. i would repeat this with every column and I'd end up with 4 different dictionaries.
The thing is that I need each data point to be as precise as possible, so I can't round it. And when I enter a whole column (not rounder) into the script, I get a repmat error:
>> huff.m
Enter Symbols[C{1}]
Enter Probabilities[p]
??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.
Error in ==> huffmandict>insertMaxVar
What I want to accomplish is to create a single dictionary (not 4), that I would be able to use on the whole data set.
For example, I'd have numbers 0-9, as well as '.', '/'
0 [code]
1 [code]
2 [code]
3 [code]
4 [code]
5 [code]
6 [code]
7 [code]
8 [code]
9 [code]
. [code]
/ [code]
Ex. Let's say '.' is 000 0 is 001 1 is 010 2 is 100 , and I want the code for 1.102 to be 010000010001100
Anyone know how to do this? The huffman script I use is:
symbols = input('Enter Symbols');
x=symbols;
p = input('Enter Probabilities');
y=p;
[dict,avglen] = huffmandict(symbols,p) % Create the dictionary
entropy=-sum(p.*log2(p))
I=entropy;
efficiency=avglen/I
temp = dict;
for i = 1:length(temp)
temp{i,2} = num2str(temp{i,2});
end
temp;
sig = repmat(input('Signal'),1,1); % Data to encode
symbols = [x];
p = [y];
dict = huffmandict(symbols,p);
hcode = huffmanenco(sig,dict)
dhsig = huffmandeco(hcode,dict);
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Large Files and Big Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!