1% BIOSIG runs on Matlab and Octave.
2% This is a script installing all components in an automatically.
3%
4% 1) extract the files and
5% 2) save the BIOSIG files in <your_directory>
6% 3) start matlab
7%    cd <your_directory>
8%    biosig_installer
9% 4) For a permanent installation, save the default path with
10%     PATH2RC or
11%     PATHTOOL and click on the "SAVE" button.
12% 5) For removing the toolbox
13%    remove the path to
14%       HOME/tsa
15%       HOME/NaN
16%       HOME/BIOSIG/ and all its subdirectories
17%
18%  NOTE: by default also the NaN-toolbox is installed -
19%  - a statistical toolbox for handling missing values - which
20%  changes the behaviour of some standard functions. For more
21%  information see NaN/README.TXT . In case you do not want this,
22%  you can excluded the path to NaN/*. The BIOSIG tools will still
23%  work, but does not support the handling of NaN's.
24
25% Copyright (C) 2003-2010,2013,2015,2020 by Alois Schloegl <alois.schloegl@gmail.com>
26% This is part of the BIOSIG-toolbox http://biosig.sf.net/
27
28if ~exist('BIOSIG_MATLAB_PATH','var')
29	BIOSIG_MATLAB_PATH = getenv('BIOSIG_MATLAB_PATH');
30end
31if isempty(BIOSIG_MATLAB_PATH)
32	if exist('./t200_FileAccess','dir')
33		BIOSIG_MATLAB_PATH = pwd;
34	elseif exist('./biosig/t200_FileAccess','dir')
35		BIOSIG_MATLAB_PATH = fullfile(pwd,'biosig');
36	else
37		fprintf(2,'Error: biosig subdirectories not found\n');
38	        return;
39	end;
40end;
41
42subdirs = {'doc', 't200_FileAccess', 't210_Events', 't250_ArtifactPreProcessingQualityControl', 't300_FeatureExtraction', 't330_StimFit', 't340_MachineLearningOptimalDetection', 't400_Classification', 't450_MultipleTestStatistic', 't490_EvaluationCriteria', 't500_Visualization', 't501_VisualizeCoupling'};
43for k = 1:length(subdirs)
44	addpath(fullfile(BIOSIG_MATLAB_PATH,subdirs{k}))
45end
46
47if ~exist('OCTAVE_VERSION','builtin'),
48	%% Matlab
49	path([BIOSIG_MATLAB_PATH,'/viewer'],path);		% viewer
50	path([BIOSIG_MATLAB_PATH,'/viewer/utils'],path);	% viewer
51	path([BIOSIG_MATLAB_PATH,'/viewer/help'],path);	% viewer
52
53	path([BIOSIG_MATLAB_PATH,'/tsa'],path);		%  Time Series Analysis
54	path([BIOSIG_MATLAB_PATH,'/tsa/inst'],path);		%  Time Series Analysis
55	path([BIOSIG_MATLAB_PATH,'/tsa/src'],path);		%  Time Series Analysis
56
57	if exist([BIOSIG_MATLAB_PATH,'/freetb4matlab'],'dir')
58		path(path,[BIOSIG_MATLAB_PATH,'/freetb4matlab/oct2mat']);	% some basic functions used in Octave but not available in Matlab
59		path(path,[BIOSIG_MATLAB_PATH,'/freetb4matlab/general']);	% some basic functions used in Octave but not available in Matlab
60	end
61
62	fprintf(1,'\nThe NaN-toolbox is going to be installed\n');
63	fprintf(1,'The NaN-toolbox is a powerful statistical and machine learning toolbox, \nwhich is also able to handle data with missing values.\n');
64	fprintf(1,'Typically, samples with NaNs are simply skipped.\n');
65	fprintf(1,'If your data contains NaNs, installing the NaN-toolbox will \nmodify the following functions in order to ignore NaNs:\n');
66	fprintf(1,'\tcor, corrcoef, cov, geomean, harmmean, iqr, kurtosis, mad, mahal, mean, \n\tmedian, moment, quantile, prctile, skewness, std, var.\n');
67	fprintf(1,'If you do not have NaN, the behaviour is the same; if you have NaNs in your data, you will get more often a reasonable result instead of a NaN-result.\n');
68	fprintf(1,'If you do not want this behaviour, remove the directory NaN/inst from your path.\n');
69	fprintf(1,'Moreover, NaN-provides also a number of other useful functions. Installing NaN-toolbox is recommended.\n\n');
70
71	%% add NaN-toolbox: a toolbox for statistics and machine learning for data with Missing Values
72	path([BIOSIG_MATLAB_PATH,'/NaN'],path);
73	%% support both types of directory structure
74	if exist([BIOSIG_MATLAB_PATH,'/NaN/inst'],'dir')
75		path([BIOSIG_MATLAB_PATH,'/NaN/inst'],path);
76	end;
77	if exist([BIOSIG_MATLAB_PATH,'/NaN/src'],'dir')
78		path([BIOSIG_MATLAB_PATH,'/NaN/src'],path);
79	end
80end
81
82
83tmp_biosig_helper_directory = pwd;
84try
85	if 0, % ~exist('OCTAVE_VERSION','builtin') && ~ispc
86		mex -setup
87	end;
88        if ~ispc && exist([BIOSIG_MATLAB_PATH,'/NaN/src'],'dir');
89		cd([BIOSIG_MATLAB_PATH,'/NaN/src']);
90	        make
91	end;
92catch
93	fprintf(1,'Compilation of Mex-files failed - precompiled binary mex-files are used instead\n');
94end;
95cd(tmp_biosig_helper_directory);
96clear tmp_biosig_helper_directory;
97
98try
99    x = betainv(.5, 1, 2);
100catch
101    path(path,[BIOSIG_MATLAB_PATH,'/freetb4matlab/statistics/distributions']);	% Octave-Forge statistics toolbox converted with freetb4matlab
102    path(path,[BIOSIG_MATLAB_PATH,'/freetb4matlab/statistics/tests']);	% Octave-Forge statistics toolbox converted with freetb4matlab
103    disp('statistics/distribution toolbox (betainv) from freetb4matlab added');
104end;
105
106try
107    x = mod(1:10,3)'-1;
108    [Pxx,f] = periodogram(x, [], 10, 100);
109    [b,a]   = butter(5, [.08,.096]);
110catch
111    path(path,[BIOSIG_MATLAB_PATH,'/freetb4matlab/signal'],'-end');	% Octave-Forge signal processing toolbox converted with freetb4matlab
112    disp('signal processing toolbox (butter,periodogram) from freetb4matlab added');
113end;
114
115% test of installation
116fun = {'butter','periodogram','betainv'};
117for k = 1:length(fun),
118        x = which(fun{k});
119        if isempty(x) || strcmp(x,'undefined'),
120                fprintf(2,'Function %s is missing\n',upper(fun{k}));
121        end;
122end;
123
124disp('BIOSIG-toolbox activated');
125disp('	If you want BIOSIG permanently installed, use the command SAVEPATH.')
126disp('	or use PATHTOOL to select and deselect certain components.')
127
128