Code covered by the BSD License  

Highlights from
Symbol Probability in a message

image thumbnail

Symbol Probability in a message

by

 

This file deals with calculating symbol probability in a message

GetSymAPrioriProb(a)
function x = GetSymAPrioriProb(a)
% This function calculates the probability of symbols in a text.
%
% INPUT:
%       a = string containing text in row vector
% OUTPUT:
%       x = Structure with following fields
%           sym = Unique sysmbols present in string
%           freq = Occurrence frequency of a sysmbol
%           prob = Probability of a symbol
%

% Implemented by ASHISH MESHRAM
% meetashish85@gmail.com http://www.facebook.com/ashishmeet

% Checking input argument
if nargin<0||isempty(a),error('Not enough input argument');end

% Implementation starts here
x.sym = unique(a,'stable'); % Unique symbols present in string
x.freq = zeros(1,length(x.sym)); % Preallocating frequency
for k = 1:length(x.sym)
    x.freq(k) = length(strfind(a,x.sym(k))); % Calculate frequecny
    x.prob(k) = x.freq(k)/length(a);    % Calculate probability
end

Contact us