%-------------------------------  Copyright ---------------------------------
%--   Copyright (C) 2005 Universite de Bretagne-Sud / LESTER
%--   Author : Christophe Cunat
%-------------------------------------------------------------------------------
%-- This program is free software; you can redistribute it and/or
%-- modify it under the terms of the GNU General Public License
%-- as published by the Free Software Foundation; either version 2
%-- of the License, or (at your option) any later version.
%
%-- This program is distributed in the hope that it will be useful,
%-- but WITHOUT ANY WARRANTY; without even the implied warranty of
%-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%-- GNU General Public License for more details.
%
%-- You should have received a copy of the GNU General Public License
%-- along with this program; if not, write to the Free Software
%-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
%-------------------------------------------------------------------------------
% File : P_distribution
% Computes Probability distribution for correlation values
%-------------------------------------------------------------------------------
function [ c_a, c_e ] = P_distribution( p, N )
%  p    : probability of input error
%  LG2_N: Logarithm base 2 of the number of inputs
% returns 
%   c_a: probability distribution for approximated correlation
%   c_e: probability distribution for exact correlation

%% Approximated correlation
c4a = [p^4 + 4*p^3*(1-p), 6*p^2*(1-p)^2,...
       4*p*(1-p)^3, (1-p)^4];
% Exact correlation
c4e = [p^4, 4*p^3*(1-p), 6*p^2*(1-p)^2,...
       4*p*(1-p)^3, (1-p)^4];
c_a = [ 1 ]; c_e = [ 1 ];
for l=1:N/4
    c_a = conv(c4a, c_a);
    c_e = conv(c4e, c_e);
end;
