Mensen / swa-matlab

Sleep Wave Analysis - an open source toolbox for matlab to score and analyse various waveforms in sleep EEG data
52 stars 20 forks source link

Data formats for automated sleep scoring swa_FindSWRef #33

Closed hcsekillan closed 8 years ago

hcsekillan commented 8 years ago

We are having difficulty importing our data using swa_FindSWRef. Our data is atypical in that there is only 2 channels of EEG. We had previously been advised to create a structure from these two channels called something like Data.SWRef = data (where data = our 2 channels). We were then instructed to manually enter the sample rate in the variable Info.Recording.sRate. Our first question is where does the Info structure come from? We have tried entering it manually using the swa_getInfoDefaults function. Our second issue is that having created Data and Info structure, the swa_FindSWRef returns an error stating it is not defined for structures. Please can you help??!

Mensen commented 8 years ago

You are correct in that for just two channels, the main function to be used is the swa_FindSWRef; and the two channels should be specified in the Data structure under the field "SWRef"

The Info structure can indeed just be made manually if you choose (in my own workflow it is automatically instantiated using the [Data, Info] = swa_convertFromEEGLAB();

The swa_getInfoDefaults function will get you the default detection settings. These can also be changed manually to explore different settings.

Could you post the output of size(Data.SWRef) and also just copy and paste the error message from matlab about structures?

It sounds like Data.SWRef is a structure, while it should just be a matrix of channels x samples. So in your case 2 x number_of_samples. For correct input type the output of the command isa(Data.SWRef, 'struct') should be false (0), and the output of isa(Data.SWRef, 'double') should be true (1).

Let me know.

Mensen commented 8 years ago

I should also point out that there is no automatic sleep scoring into stages in the toolbox. The automatic portion of the toolbox is for individual wave detection. This seems to be what you're doing using the swa_FindSWRef anyways, but the issue title "automated sleep scoring" made me think I should be more explicit about this.

If I find a good automatic scoring algorithm I will be certain to include it in the toolbox, but so far I haven't been impressed with the results of any I've come across so far.

hcsekillan commented 8 years ago

Thank you for responding so promptly.

The output of size(Data.SwRef) is [7930937, 2]. Also, output of isa(Data.SWRef, 'struct') is 0 and isa(Data.SWRef, 'double') is 1. We are not clear on how to obtain the default Info settings. In a previous email you suggested:

"The variable "Info" is another structure that tells the toolbox about your data as well as the parameters you want to use for detection. Since you haven't imported the data in a standard way you'll have set the sampling rate manually like this:

Info.Recording.sRate = 250; % the sampling rate of the recording in Hz

Then get the default parameter settings using the following:

Info = swa_getInfoDefaults(Info, 'SW', 'envelope');

Now you can change any of the parameters manually. Just have a look into the Info.Parameters field and change whatever you think might be appropriate, or just leave the defaults which usually work quite well depending on the data quality etc.

But doing this returns error message

Undefined function 'swa_getInfoDefaults' for input arguments of type 'struct'.

and error function for

swa_FindSWRef (Data.SWRef, Info) returns Undefined function 'swa_FindSWRef' for input arguments of type 'struct'.

MAny thanks ..

Mensen commented 8 years ago

Ah I see...

This seems to be a problem of not finding the function in your path. It sounds like the problem is not that your data file is a struct, but that it is an undefined function

This suspicion could be confirmed with my the output of which swa_FindSWRef

the output should be something like:

_/.../swa-matlab/Tools/swagetInfoDefaults.m

if the function is not in your path, then you will get the message:

_'swagetInfoDefaults.m' not found.

If the functions aren't in your path you can go to the set path menu in Matlab and select add folder with subfolders and point to the directory where swa-matlab is saved.

hcsekillan commented 8 years ago

I now have a different error message...

[Data, Info, SW] = swa_FindSWRef (Data, Info); Error using - Matrix dimensions must agree.

Error in swa_get_peaks (line 27) posBumps = MPP(2 : end) - MNP < ...

Error in swa_FindSWRef (line 72) [MNP, MPP] = swa_get_peaks(slopeData, Info, 1);

For information, Data.SWRef is an array of data in two rows, so that size(Data.SWRef,1); returns an answer of 2.

Many thanks

Mensen commented 8 years ago

Hi @hcsekillan

I've tried to reproduce the error somehow but have had no luck. There must be something special in your data that I'm not used to handling with a more specific error message.

At the very least it seems that there is an uneven amount of positive and negative peaks in your canonical reference channel (SWRef), but this should be picked up earlier than when you receive the message you're looking at.

Anyway you could save the Data.SWRef in a separate file and send it to me? Or link me to it on dropbox or google drive?

Thanks!