File Exchange

image thumbnail

Shannon-fano encoder

version 1.0 (97.6 KB) by

a shannonfano encoder with a row matrix input of occurrences/probab and outputs codewords&avelength

23 Downloads

Updated

View License

%made by Jamil Kasan from Manila, Philippines
%input = row matrix of occurrences or probabilities e.g. ss=[1 3 4 5] or
%ss=[0.4 0.3 0.2 0.1]
%outputs = string of codewords,average codeword length

to try its credibility, play sf encoder (need to change the location of ff7.txt)

sfencoderkasan is a function file for shannon-fano encoder
its input is a row matrix of occurrences or probabilities
its outputs are ​codex which is the codewords and T which is the average codeword length

Comments and Ratings (11)

Philip Geluz

Quick question, when i run in matlab everything works fine however it won't display the code. it will display (1x1) cell. how do i get it to display the code word.

Can I have the C++ code? Pm sent

Jamil Kasan

Jamil Kasan (view profile)

@Robert Green, I reread my notes back from College, and I think the one in Wikipedia is wrong, it is actually fano coding, and what I made here is the real shannon-fano coding, but if you do want to have the fano code in c++, Id let you have it, thank you too that you made me get my notes back

Jamil Kasan

Jamil Kasan (view profile)

@Robert Green, sorry for that, I think I mislabelled it or I was just wrong, it was years ago that I do not remember it anymore, anyways, I made shannon fano encoder in c++ but it isn't refactored yet cause I just made it for 2 hours, I forgot to obey Uncle Bob this time
(If you wanted the code I just made, feel free to email me, in my informal email=kasan.jamil@yahoo.com)

Robert Green

your code is actually Shannon coding, not Shannon-Fano coding. see http://en.wikipedia.org/wiki/Shannon_coding

Robert Green

Hi Jamil. Thank you for the code, but this code doesn't seem to be correct. when yo give it the occurences [15,7,6,6,5] it returns codewords [00,011,100,101,110] which is not correct. The correct Shanon-Fano codewords are [00,01,10,110,111]. see http://en.wikipedia.org/wiki/Shannon%E2%80%93Fano_coding

Jamil Kasan

Jamil Kasan (view profile)

@ahmed
btw, thanks for the comment and rate

Jamil Kasan

Jamil Kasan (view profile)

@ahmed
the outputs are in string characters, only for display purposes, that's why.

ahmed

ahmed (view profile)

this is really amazing but when i tried it it gave me {1x1 cell} instead of all codes i tried to fix it but with no result can u just tell me why it gave my these results ?

Jamil Kasan

Jamil Kasan (view profile)

the sfencoderkasan is a pcode, comment and rate please. pm me for the source code (mil1_hoopplayer@yahoo.com)

Jamil Kasan

Jamil Kasan (view profile)

Please comment or rate, that would be much appreciated. Thanks.

MATLAB Release
MATLAB 7.10 (R2010a)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Win prizes and improve your MATLAB skills

Play today