\chapter{Documentation of the Code}
\label{app:docu}
The documentation of the Code will be split into parts according to the usage. in this parts the order will be alphabetically in the name of the function.

\section{\texttt{callAll.m}}
    \texttt{callAll.m} and \texttt{callAllPos.m} are the central point in the corresponding calculations. From this script every other function is called and the parameters are defined here.\\
    The default values for the parameters are given in table \ref{tab:default}.

    There are two independent scripts since this makes it possible to do calculations at the same time on the same machine and change called scripts without influencing the other run. In addition when calculating positions instead of velocities, some calculations do not need to be redone. Those are left out in \texttt{callAllPos.m}.
\section{Data Acquisition}
    \subsection{\texttt{balanceClasses.m}}
        Balances classes e.g. for a SVM by dropping data from bigger classes.

        This function also takes an additional parameter \texttt{maxPerClass} which defines how many elements per class are taken in at most. This parameter can be used to enhance computations.

        The number of classes (\texttt{noClasses}) has to be passed to make sure no class is completely omitted because there was no such value in the training set.

        This function throws an error if the number of samples per class is lower than 1.
    \subsection{\texttt{classifyAccordingToEMG.m}}
    \label{code:classify}
        Here the reclassification as described in section~\ref{mm:newClass} is done.

        For each data point it is decided whether it belongs to movement or not according to the given threshold in EMG activity. If not there is no movement so the class is set to 0 (rest).\\
        If there is movement it is decided whether there should be according to the given classification. If not the old class is applied also for this point. If yes it is checked whether the movement just started (up to now class was 0). If the movement just started, 1 second before is taken out (pause \true) or half second before is classified same, 0.5s to 1s is dropped (pause \false).
    \subsection{\texttt{readAll.m}}
    \label{code:readAll}
        This is the central function for the acquisition of data.

        First the name of the generated file is composed out of the given parameters. In this way the acquisition step only has to be done once.\\
        If the file is not existing yet, it is created in the following steps:\\
        Data from BCI2000 is read along the corresponding kinematic information. Then this data is transformed in the form we want to use it (cf. \texttt{generateTrainingData} \ref{code:generate}). The data from each of the five runs (cf. section~\ref{mm:design}) is aggregated in one variable per modality.

        As a next step the classification is done using \texttt{classifyAccordingToEMG.m} (\ref{code:classify}). The result is then smoothed and adjusted to the length of EEG data.

        Finally the kinematics and the synergies are generated matching the size of EMG data. All is then saved under the given path as \texttt{.mat} file.
    \subsection{\texttt{readAllPos.m}}
        Same as \ref{code:readAll} but using position instead of movement from kinematics data.
    \subsection{\texttt{generateTrainingData.m}}
    \label{code:generate}
        %TODO
    \subsection{\texttt{generateTrainingDataPos.m}}
        Same as \ref{code:generate} but using position instead of movement from kinematics data.
\section{Data Analysis}
    \subsection{\texttt{correlation2.m}}
        Calculates the squared correlation between each corresponding columns of two matrices.\\
        This is used as a measure for fit when comparing the number of synergies.
\section{Evaluation}
    \subsection{\texttt{evaluation.m}}
        Script for composing the file containing the results (\texttt{evaluation.mat}). This file is used for the evaluations after some manual post-processing (mainly renaming).
    \subsection{\texttt{evaluationAccuracys.m}}
        Evaluations run on results from SVMs.
    \subsection{\texttt{evaluationCorrelations.m}}
        Evaluations run on results from ridge regressions.
