any one help me in implementation of arithmetic coding (compressing of text file)

2 views (last 30 days)
hi i'm tareq i need help in matlab i want to compress (text file) by using arithmetic coding now let us turn to the details 1- first I have been loaded the text file by use(x=fileraed('c:/name.txt') x=length(x) since the arithmetic coding depending on the Probability of characters we must calculate the repeated character >>>>> so how can i do it

Answers (2)

Jan
Jan on 2 Mar 2012
Perhaps this helps already:
str = fileread('c:/name.txt');
[n, bin] = histc(str, unique(str));
  3 Comments
Walter Roberson
Walter Roberson on 2 Mar 2012
That is *not* arithmetic compression.
In any case, once you have executed the two lines Jan gave, then the answer you state that you want would be
n(bin)

Sign in to comment.


Walter Roberson
Walter Roberson on 2 Mar 2012
Arithmetic coding does not depend upon the probability of repeated characters in any way similar to the way you are indicating.
Arithmetic coding updates probabilities as each pattern (which might correspond to a character) is observed in the encoding process. The patterns that are encountered most often grow dynamically to have the largest fractions allocated to them. This is not based on any pre-calculation of probabilities.
A book I recommend highly is Text Compression by Bell, Cleary, Witten. I find that I have used the material from that book over and over again in a wide variety of circumstances.
  2 Comments
tareq
tareq on 2 Mar 2012
that's completely right and i have been read many books about text compression
and i have (text compression by bell) but as you know there is two laws
NewHigh:=01dLow+Range*HighRange(X);
NewLow:=01dLow+Range*LowRange(X);
all what i want to compress text file and this done by using these lows
Walter Roberson
Walter Roberson on 2 Mar 2012
My Bell, Cleary, Witten is at work so I cannot look up page references at the moment, but I am absolutely positive that you do *not* pre-calculate probabilities for arithmetic compression. I implemented the code myself a number of years ago (long enough ago that I no longer have the source, and do not recall which language I used.)

Sign in to comment.

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!