Code covered by the BSD License  

Highlights from
Symbol Probability in a message

image thumbnail

Symbol Probability in a message


Ashish Meshram (Meet)


This file deals with calculating symbol probability in a message

function x = GetSymAPrioriProb(a)
% This function calculates the probability of symbols in a text.
%       a = string containing text in row vector
%       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

% 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

Contact us