function H = entropy(v, normalize)
% ENTROPY Compute the entropy of a vector (log base 2)
% H = entropy(v) computes the entropy
% H = entropy(v, 1) computes the normalized entropy = H / log2(size of vector)

  
v = v + (v==0);
H = -1 * sum(v .* log2(v));

if exist('normalize')
  n = length(v);
  H = H / log2(n);
end
