diff --git a/text/thesis/02MaterialsAndMethods.tex b/text/thesis/02MaterialsAndMethods.tex index eb6940b..8fb48ea 100644 --- a/text/thesis/02MaterialsAndMethods.tex +++ b/text/thesis/02MaterialsAndMethods.tex @@ -154,10 +154,15 @@ \end{figure} Common kernels are polynomial, Gaussian and hyperbolic kernels. \subsection{Regression} - Regression is the idea of finding $A$ so that $$Ax=y,$$ where x is the input and y the output of a system. Having this $A$ from any given input the output can be predicted. %TODO + Regression is the idea of finding $\beta$ so that $$y= X\beta+\epsilon$$ where X is the $n\times p$ input matrix and y the $n\times 1$ output vector of a system. Having this $\beta$ from given input the output can be predicted.\\ + There are different ways to find this $\beta$. One common approach is the \emph{ordinary least squares}-Algorithm. $$\hat{\beta}=\arg\min\limits_{b\in\mathds{R}^p} \left(y-Xb\right)^T\left(y-Xb\right),$$ meaning the chosen $\hat\beta$ is that $b$ which produces the lowest error since $Xb$ should be - besides from noise $\epsilon$ - the same as $y$.\\ + Choosing $\beta$ like this brings the risk of overfitting. The training data is matched well, new data however are classified poorly. This problem is addressed with RIDGE-Regression. \subsubsection{RIDGE-Regression} + Instead of minimizing only the error in RIDGE-Regression (also called \emph{Tikhonov regularization}) the size of vector $\beta$ is also minimized: $$\hat{\beta}=\arg\min\limits_{b\in\mathds{R}^p} \left(y-Xb\right)^T\left(y-Xb\right)+\lambda b^Tb.$$ + $\lambda$ decides how big the influence of size of $\beta$ or $b$ respectively is. \subsection{Cross Validation} - %TODO + $k$-fold cross validation means splitting the data into $k$ equally sized parts, training the model on $k-1$ parts and validating on left one.%TODO + %May be nested (example) \section{Experimental design} The data used for this work were mainly recorded by Farid Shiman, Nerea Irastorza-Landa, and Andrea Sarasola-Sanz for their work (\cite{Shiman15},\cite{Sarasola15}). We were allowed to use them for further analysis.\\ There were 9 right-handed subjects with an average age of 25 (variance 6.67, minimum 20, maximum 28). Three female and 6 male subjects were tested. All the tasks were performed with the dominant right hand.\\ @@ -178,7 +183,7 @@ \section{Data Acquisition} \subsection{Loading of data} The data recorded with BCI2000 (\cite{Schalk04}) can be loaded into \matlab{} with a specific \texttt{.mex} file. The according \texttt{.mex}-Files for some platforms (Windows, MAC, Linux) are available from BCI2000 precompiled.\\ - We loaded the signal plus the according status data and the parameters (see Algorithm~\ref{alg:load_bcidat}). + We load the signal plus the according status data and the parameters (see Algorithm~\ref{alg:load_bcidat}). \begin{algorithm} \begin{algorithmic} \State [signal, states, params] = load\_bcidat('dataFile.dat'); @@ -188,7 +193,7 @@ \end{algorithm} \subsubsection{Signal} The signal is loaded as matrix of 41 channels (see Table~\ref{tab:channelNames}). All the values are integers %TODO: representing what? - and also can be loaded as floating point values representing microvolts. Since the representation should not make any difference when analyzing the spectrum we used the smaller representation %TODO: check + and also can be loaded as floating point values representing microvolts. Since the representation should not make any difference when analyzing the spectrum we use the smaller representation %TODO: check \begin{table} \centering \begin{tabular}{c|c|l} @@ -246,26 +251,37 @@ All the settings from the BCI2000 recording are saved in and loaded from the \texttt{parameters}.\\ Examples are the names of the channels, the random seed for BCI2000 and the sounds, meaning and duration for different stimuli. \subsection{Filtering} - For filtering we used second order Butterworth filters. + For filtering we use second order Butterworth filters. For normal EEG we used: \begin{enumerate} \item Highpass at \texttt{minEEGFreq} (usually 2Hz) \item Lowpass at \texttt{maxEEGFreq} (usually 49Hz) \item bandstop at 48-52Hz and 148-152Hz to eliminate (possibly relevant) power line noise \end{enumerate} - For low frequencies we used: + For low frequencies we use: \begin{enumerate} \item Highpass at 0.01Hz \item Lowpass at 1Hz \end{enumerate} - For EMG data we used: + For EMG data we use: \begin{enumerate} \item Highpass at 2Hz to eliminate movement artifacts \item bandstop at 48-52Hz and 148-152Hz to eliminate (possibly relevant) power line noise \end{enumerate} - For filtering we used \matlab{}s \texttt{filtfilt} function to reduce shift due to multiple filtering steps. + For filtering we use \matlab{}s \texttt{filtfilt} function to reduce shift due to multiple filtering steps. \subsection{Windowing} - %TODO? + To process continuous EEG or EMG data it is necessary to define windows. These windows are shifted over the data to get discrete values for the further steps.\\ + We choose as default for EEG + \begin{itemize} + \item window $1 s$ + \item shift $200ms$ + \end{itemize} + and for EMG + \begin{itemize} + \item window $0.2s$ + \item shift $50ms$. + \end{itemize} + For re-synchronization we pass the shift to every function that needs to align EMG and EEG data and operate on \emph{time-from-start} there. \subsection{Waveform length} For the representation of EMG data we used waveform length as described by Phinyomark et al. in \cite{Phinyomark12} which gives a measurement for the change in the window. It is calculated as the sum over the absolute difference of consecutive measurements in the time window: $$\sum\limits_{i=1}^N \left| x_i-x_{i-1}\right|,$$ @@ -274,12 +290,13 @@ \subsection{Classification} \label{sec:newClass} Very bad results when classifying EMG into Move/Rest made us further inspect the data. The actual movement came quite a while after the stimulus.\\ - To address this problem we did a re-classification of the data according to actual movements (cf. Appendix~\ref{code:classify}). To decide whether the subject is moving or not we compared the mean EMG activity (from Waveform Length) to a threshold (10,000 by default).\\ - If there was movement we defined the class occurring most in the second before as the current task. If there was movement but the stimulus told to rest, we assigned the last active stimulus.\\ - In addition we took the second before movement onset out of the data (classified as -1) and (optionally) half a second before movement onset as belonging to the following stimulus.\\ - Finally we did some smoothening by taking the most occurring class one second before to one second after the current time step as its class.\\ - As last step we adjusted the length of the stimulus-vector to the length of the EEG data.\\ - According to this classification we took only data in the further analysis which were classified different than -1 meaning they are either clear rest or clear movement. + To address this problem we did a re-classification of the data according to actual movements (cf. Appendix~\ref{code:classify}). To decide whether the subject is moving or not we compare the mean EMG activity (from Waveform Length) to a threshold (10,000 by default).\\ + If there is movement we define the class occurring most in the second before as the current task. If there is movement but the stimulus tells to rest, we assign the last active stimulus.\\ + In addition we take the second before movement onset out of the data (classified as -1) and (optionally) half a second before movement onset as belonging to the following stimulus.\\ + Finally we do some smoothening by taking the most occurring class one second before to one second after the current time step as its class.\\ + As last step we adjust the length of the stimulus-vector to the length of the EEG data.\\ + According to this classification we take only data in the further analysis which are classified different than -1 meaning they are either clear rest or clear movement. + \subsection{Synergies} %TODO \section{Data Analysis} \subsection{Classification} diff --git a/text/thesis/Bfunctions.tex b/text/thesis/Bfunctions.tex index cc28b49..a7cb410 100644 --- a/text/thesis/Bfunctions.tex +++ b/text/thesis/Bfunctions.tex @@ -1,17 +1,17 @@ -\chapter{Documentation of \matlab{}-Code} +\chapter{Documentation of the \matlab{}-Code} \section{\texttt{callAll.m}} \section{Data Acquisition} -\subsection{\texttt{classifyAccordingToEMG.m}} -\label{code:classify} -\subsection{\texttt{readAll.m}} -\label{code:readAll} -\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} -\subsection{\texttt{generateTrainingDataPos.m}} -Same as \ref{code:generate} but using position instead of movement from kinematics data. + \subsection{\texttt{classifyAccordingToEMG.m}} + \label{code:classify} + \subsection{\texttt{readAll.m}} + \label{code:readAll} + \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} + \subsection{\texttt{generateTrainingDataPos.m}} + Same as \ref{code:generate} but using position instead of movement from kinematics data. \section{Data Analysis} \section{Plots} diff --git a/text/thesis/thesis.tex b/text/thesis/thesis.tex index 04d17f6..3f74a9b 100644 --- a/text/thesis/thesis.tex +++ b/text/thesis/thesis.tex @@ -19,6 +19,7 @@ \usepackage{amsmath} \usepackage[official]{eurosym} \usepackage[chapter]{algorithm} +\usepackage{dsfont} \usepackage{algpseudocode} %\renewcommand{\familydefault}{\sfdefault}