Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Shannon fano coding with MATLAB,

Status
Not open for further replies.

fatemenahid

Newbie level 3
Joined
Dec 10, 2011
Messages
4
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,301
hello my friends I need shannon fano coding m-file ,please help me how I can write shannon fano simulation in MATLAB!
 

hello friend i am sending u an attach ment please check if it is help ful

This process can be done in a forward mode, which requires less memory and processing time. However, it does not always result in the same degree of compression as the Huffman process.
One way the code can be determined is by the following procedure:
• Arrange the messages in decreasing probability of occurrence
• Divide the messages into 2 equally probable groups
• If there are two possible divisions, select the one with the fewest states above the division
• Assign one group a value of 0 and the other a 1
• Continue the division process until all there is nothing left to divide
Resulting Shannon-Fano Code Table
Message or Event Probability of Occurrence Binary Representation Shannon-Fano
Code
M2 0.4 010 0
M4 0.2 100 100
M3 0.15 011 101
M1 0.09 001 110
M7 0.07 111 1110
M6 0.05 110 11110
M5 0.03 101 111110
M8 0.01 000 111111

On the average, this code will transmit 2.5 bits per message:
This coding algorithm is often less efficient than that of Huffman, but can be implemented with simpler hardware
 
u can simply use the google language conver tool to simply cont the explained language
 

Attachments

  • f1.doc
    23.5 KB · Views: 319
  • f2.doc
    23.5 KB · Views: 247
  • fano1.doc
    24.5 KB · Views: 297
  • shan.doc
    24.5 KB · Views: 309
Try this.

Code:
clc;
clear all;
close all;

m=input('Enter the no. of message ensembles : ');
z=[];
h=0;l=0;
display('Enter the probabilities in descending order');
for i=1:m
    fprintf('Ensemble %d\n',i);
    p(i)=input('');
end
%Finding each alpha values 
a(1)=0;
for j=2:m;
    a(j)=a(j-1)+p(j-1);
end
fprintf('\n Alpha Matrix');
display(a);
%Finding each code length
for i=1:m
    n(i)= ceil(-1*(log2(p(i))));
end
fprintf('\n Code length matrix');
display(n);
%Computing each code
for i=1:m
    int=a(i);
for j=1:n(i)
    frac=int*2;
    c=floor(frac);
    frac=frac-c;
    z=[z c];
    int=frac;
end
fprintf('Codeword %d',i);
display(z);
z=[];
end
%Computing Avg. Code Length & Entropy
fprintf('Avg. Code Length');
for i=1:m
    x=p(i)*n(i);
    l=l+x;
    x=p(i)*log2(1/p(i));
    h=h+x;
end
display(l);
fprintf('Entropy');
display(h);
%Computing Efficiency
fprintf('Efficiency');
display(100*h/l);
fprintf('Redundancy');
display(100-(100*h/l));
 
Last edited by a moderator:
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top