function lambda = comconpair(lambda)
%COMCONPAIR Find complex conjugate pairs
% Y = COMCONPAIR(X) returns the complex conjugate pairs from the vector
% X

% EMA Toolbox
% Peter Fiala 2008 feb.

N = length(lambda);
tol = 1e-3;
s = 0;
pairs = zeros(0,2);
for n = 1 : N
if ~ismember(n, pairs(:,2))
lam = lambda(n);
[ind, i] = setdiff(1:N,n);
dif = abs(conj(lam) - lambda(ind))/abs(lam);
q = find(dif < tol);
if ~isempty(q)
s = s+1;
pairs(s,:) = [n i(q)];
end
end
end
lambda = lambda(reshape(pairs.',2*s,1));