The first step we took to try to analyze our data was to create filters for each of the frequency bands associated with different sleep stages. Using MATLAB's Filter Designer tool, we created filters for the alpha (8-12 Hz), theta (4-8 Hz), and delta (0.5-4 Hz) bands. We attempted to apply these filters to our data, but ultimately decided not to include them in our classifier.
Alpha filter
Theta filter
The approach we decided to take for our classifier is to build a convolutional neural network (CNN). CNNs are able to perform advanced image classification and object recognition, and in our research, we found that they have been used by researchers to classify LFP data. The images we will feed our CNN are scalograms of the data. These scalograms are discussed in detail below.
A CNN is made up of many layers, and the more layers there are, the more robust the network becomes. There are 3 main types of layers.
Convolutional layer: In this layer, small filters are applied across every part of the image using convolution. Parameters we will need to specify when creating this layer are the filter size, the number of filters, and the stride, which is the number of pixels that the filter kernel moves over. It is common to apply padding to the image in this layer to ensure the output is the same size as the input. The output will be a feature map that shows how present a given feature is in the original image. The feature being detected is dependent on how each filter is weighted.
A ReLu layer follows each convolutional layer, where a rectified linear unit activation function is applied to introduce nonlinearity into the model.
Pooling layer: The next layer is a pooling layer, which reduces the size of the feature map in order to make the network more efficient. While information may be lost in this layer, it reduces the risk of overfitting and allows more filters to be applied later on with a reduced computational burden. The type of pooling we will most likely implement is max pooling, where the pixel with the maximum value in the pooling filter kernel is what is seen in the output of the layer.
Fully connected layer: The previous layers have produced several feature maps describing the input image. This layer is where the features the network has learned are combined to identify larger patterns in the input. In a graphical representation, this layer connects the neurons of the output to the neurons of the previous layer.
A softmax layer is typically applied after the last fully connected layer to normalize the output. This layer transforms the values of the output into a set of real numbers that sum to 1, i.e. a probability distribution.
Based on our research, we plan to implement our CNN in Matlab using the Deep Learning Toolbox.
In order to increase the resolution of a signal in the frequency domain, a technique called the wavelet transform can be applied. This technique is commonly used in analysis of brain wave data in the frequency domain, including LFP data. As a result, our group decided to explore this technique in an effort to better the sleep stage classification of our model.
The fundamental idea behind a wavelet transform is representing an original signal decomposed into several signals. This transformation only allows for changes in time extension, but not any changes in shape. It relies on the uncertainty principle of signal processing shown below.
This leads to the idea that resolution in time is inversely related to resolution in frequency. For larger windows of analysis in time, there is better frequency resolution, but for smaller windows of analysis in time, there is worse frequency resolution.
Using this principle, wavelet transforms construct the signal in the L2 Hilbert space with basis function equal to the impulse response of the system. The transformation into this domain is similar to the short-time-Fourier-transformation, which divides longer time signals into shorter segments. For slowly varying functions, this leads to high frequency resolution.
Mathematical representation of the wavelet transform is shown below.
Additionally, wavelet transform techniques can be used for image compression. This may be useful for the spectrograms and scalograms of our data that we are generating.
Based on research, we first began our implementation of wavelet transforms with the MATLab cwt function. This function completes a 1-D continuous wavelet transform using the Morse wavelet, a family of wavelets that are complex-valued, but whose Fourier transforms are only supported on the positive real axis. Additionally, the function allows for the specification of the sampling frequency, fs, in hertz. It enables the wavelet transform outputs to include scale-to-frequency conversions in hertz, providing a more precise interpretation of the frequency content at each scale.
The function is able to directly output a scalogram comparing time, frequency, and magnitude of the signal in addition to a the resulting wavelet function from applying the function. To test the features of this function, we outputted a scalogram of the first 1000 data points from our dataset.
We then did the same for a group of data inside of our first sleep state, awake. the major peak in this frequency is below the beta wave range, 12 to 38 Hz, which corresponds to brain activity when awake. Further investigation as to why the magnitude is so high at this frequency must be considered further.
Our team will continue researching the correct type of wavelet transform for processing our data. Brain wave data, including EEGs and LFPs, is often transformed with a Morlet wavelet. The Morlet wavelet is composed of a sinusoid modulated by a Gaussian function. This transform is incredibly similar to a Morse wavelet in application; however, it is more simple and less versatile in adjustment of time-frequency characteristics compared to the Morse wavelet. For the scale of our project, the Morlet wavelet may prove to be adequate.
Relating to this, one general concern with the cwt function on MATLab was its computational efficiency. The function took a while to load and often crashed when given larger data sets. Since our data is incredibly large in comparison to the capabilities of the cwt function, other wavelet transforms will most likely need to be used.
One concern with the initial scalograms generated was that the shaded region automatically applied by Matlab would cause issues when the images were put into our CNN for analysis. We modified our usage of the cwt function to instead output the wavelet coefficients, and we then created the scalogram manually. Using this method, we were able to create a scalogram of the channel 1 LFP readings for the entire sampling period, as shown below. When training our model, we will use the states table discussed in the previous progress report to create scalograms for each of the smaller time periods with labeled sleep states, rather than using a plot with a time span this large. Nevertheless, this method is much more computationally efficient and the output is suitable for image analysis, so this is likely how we will move forward.
Continue Processing Data into Frequency Domain
Generate scalograms for the first 10 sleep states recorded in LFP data.
Automate generation of scalograms using the table values described above.
Note: Our LFP data contains a table with time periods and their corresponding sleep state. See the previous progress report for more detail.
Convert Data into A Useable Form
Save images into a form that is useable by a convolutional neural network (CNN).
Determine if wavelet transform is necessary to get meaningful data and which transform to use.
Note: CNNs generally take in image height, width, and RGB color channels.
Construct Convolutional Neural Network
Research construction of CNN in MATLab.
If needed, data will be exported to Python to construct CNN there instead.
More steps will be defined as research is completed.