function g = compGauss(seq)
% COMPGAUSS Checks if a sequence is described by a gaussian distribution.
%
% [G] = COMPGAUSS(SEQ) where the out (G) is one if the function considers
% the input sequence (SEQ) as a gaussian sequence (zero in other case).
% Copyright (C) Iván López Espejo 2010
% Version: Id: compGauss.m , v 1.0 2010
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 can obtain a copy of the GNU General Public License from
% ftp://prep.ai.mit.edu/pub/gnu/COPYING-2.0 or by writing to
% Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Ideal probability density function.
sg = var(seq);
u = mean(seq);
% Normalized pdf.
lim = 0.00001;
xl = u - sqrt(-2*sg*log(lim)); % Left limit.
xr = u + sqrt(-2*sg*log(lim)); % Right limit.
x = xl:.1:xr;
f = exp(-((x-u).^2)/(2*sg));
f = f/sum(f);
% Original sequence's pdf.
fs = hist(seq,length(f));
fs = fs/max(fs);
% Pseudo-cosine interpolation.
cz = 0;
for j = 2:length(fs)
if fs(j) == 0
cz = cz + 1;
if cz > 0 && j == length(fs)
y1 = fs(j-cz-1);
y2 = fs(j);
x1 = acos(y1);
x2 = acos(y2);
int = (x2-x1)/(cz+1);
for k = 1:cz
fs(j-cz-1+k) = cos(x1+k*int);
end
cz = 0;
end
else
if cz > 0
y1 = fs(j-cz-1);
y2 = fs(j);
x1 = acos(y1);
x2 = acos(y2);
int = (x2-x1)/(cz+1);
for k = 1:cz
fs(j-cz-1+k) = cos(x1+k*int);
end
cz = 0;
end
end
end
fs = fs/sum(fs); % Area normalization.
% Plot and return of the result.
plot(fs)
grid on
hold on
plot(f,'r')
hold off
legend('PDF de la secuencia','PDF gaussiana')
title('Comparación de PDFs')
THRESHOLD = 0.003; % Empiric threshold to consider if a sequence is or not a gaussian sequence.
if sum((fs-f).^2) < THRESHOLD
g = true;
else
g = false;
end
disp('Error cuadrático: ')
disp(sum((fs-f).^2))