function [Out1, Out2, Out3] = fastica(mixedsig, varargin)
error ('You must supply the mixed data as input argument.');
if length (size (mixedsig)) > 2,
error ('Input data can not have more than two dimensions.');
if any (any (isnan (mixedsig))),
error ('Input data contains NaN''s.');
if ~isa (mixedsig, 'double')
fprintf ('Warning: converting input data into regular (double) precision.\n');
mixedsig = double (mixedsig);
[mixedsig, mixedmean] = remmean(mixedsig);
[Dim, NumOfSampl] = size(mixedsig);
if (rem(length(varargin),2)==1)
error('Optional parameters should always go by pairs');
for i=1:2:(length(varargin)-1)
if ~ischar (varargin{i}),
error (['Unknown type of optional parameter name (parameter' ...
' names must be strings).']);
switch lower (varargin{i})
stabilization = lower (varargin{i+1});
maxFinetune = varargin{i+1};
sampleSize = varargin{i+1};
verbose = lower (varargin{i+1});
if strcmp (verbose, 'off'), b_verbose = 0; end
firstEig = varargin{i+1};
interactivePCA = lower (varargin{i+1});
approach = lower (varargin{i+1});
g = lower (varargin{i+1});
finetune = lower (varargin{i+1});
maxNumIterations = varargin{i+1};
displayMode = lower (varargin{i+1});
displayInterval = varargin{i+1};
jumpWhitening = jumpWhitening + 1;
whitesig = varargin{i+1};
jumpWhitening = jumpWhitening + 1;
whiteningMatrix = varargin{i+1};
jumpWhitening = jumpWhitening + 1;
dewhiteningMatrix = varargin{i+1};
switch lower (varargin{i+1})
error(['Unrecognized parameter: ''' varargin{i} '''']);
fprintf('Number of signals: %d\n', Dim);
fprintf('Number of samples: %d\n', NumOfSampl);
fprintf('The signal matrix may be oriented in the wrong way.\n');
fprintf('In that case transpose the matrix.\n\n');
fprintf ('Whitened signal and corresponding matrises supplied.\n');
fprintf ('PCA calculations not needed.\n');
fprintf ('Values for PCA calculations supplied.\n');
fprintf ('PCA calculations not needed.\n');
if (jumpPCA > 0) & (b_verbose),
fprintf ('You must suply all of these in order to jump PCA:\n');
fprintf ('''pcaE'', ''pcaD''.\n');
[E, D]=pcamat(mixedsig, firstEig, lastEig, interactivePCA, verbose);
fprintf ('Whitening not needed.\n');
if (jumpWhitening > 0) & (b_verbose),
fprintf ('You must suply all of these in order to jump whitening:\n');
fprintf ('''whiteSig'', ''whiteMat'', ''dewhiteMat''.\n');
[whitesig, whiteningMatrix, dewhiteningMatrix] = whitenv ...
(mixedsig, E, D, verbose);
if (b_verbose & userNumOfIC)
fprintf('Warning: estimating only %d independent components\n', numOfIC);
fprintf('(Can''t estimate more independent components than dimension of data)\n');
[A, W] = fpica (whitesig, whiteningMatrix, dewhiteningMatrix, approach, ...
numOfIC, g, finetune, a1, a2, myy, stabilization, epsilon, ...
maxNumIterations, maxFinetune, initState, guess, sampleSize, ...
displayMode, displayInterval, verbose);
fprintf('Adding the mean back to the data.\n');
(max(abs(W * mixedmean)) > 1e-9) & ...
(strcmp(displayMode,'signals') | strcmp(displayMode,'on'))
fprintf('Note that the plots don''t have the mean added.\n');
Out2 = dewhiteningMatrix;
Out3 = dewhiteningMatrix;