User Tools

Site Tools


analysis:rhythms:step1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
analysis:rhythms:step1 [2016/03/29 14:30]
mvdm
analysis:rhythms:step1 [2020/01/15 15:00] (current)
mvdm
Line 8: Line 8:
  
 If your MATLAB runs, great! Now decide if you'd rather: If your MATLAB runs, great! Now decide if you'd rather:
-  - Familiarize yourself with MATLAB first. Go [[http://ctnsrv.uwaterloo.ca/vandermeerlab/​doku.php?​id=analysis:​rhythms#​getting_started_with_matlab | here]].+  - Familiarize yourself with MATLAB first. Go [[https://rcweb.dartmouth.edu/~mvdm/wiki/​doku.php?​id=analysis:​rhythms#​getting_started_with_matlab | here]].
   - Dive right in, working with Emotiv data. Read on.   - Dive right in, working with Emotiv data. Read on.
  
Line 21: Line 21:
 Pick one: the quick way, or the future-proof way. Pick one: the quick way, or the future-proof way.
  
-//The quick way//: download the MATLAB loader (from [[https://​raw.githubusercontent.com/​mvdm/​PSYC50Rhythms/​master/​emotiv-loading/​edfread.m | here]]), and place it in a sensible location like ''​\Documents\PSYC50\Code\Loading''​. This will work for now. However, if you ever want to access an updated version of this file, or other code that I put up for use in the course, you'll have to do more downloading. The future-proof way, below, addresses this.+//The quick way//: download the MATLAB loader (from [[https://​raw.githubusercontent.com/​mvdm/​PSYC50Rhythms/​master/​emotiv-loading/​edfread.m | here]], use "Save Link As..." rather than opening this file in your browser), and place it in a sensible location like ''​\Documents\PSYC50\Code\Loading''​. This will work for now. However, if you ever want to access an updated version of this file, or other code that I put up for use in the course, you'll have to do more downloading. The future-proof way, below, addresses this.
  
 //The future-proof way//: I have added the code you'll need for loading EDF data, as well as for doing some other things, on a "​GitHub repository"​. ''​Git''​ is a system for "​distributed version control":​ put simply, a way to collaborate on a set of files that makes it easy to share and receive updates to those files. ''​GitHub''​ is a website that hosts those files in a convenient place so that the ''​Git''​ software can do its job. //The future-proof way//: I have added the code you'll need for loading EDF data, as well as for doing some other things, on a "​GitHub repository"​. ''​Git''​ is a system for "​distributed version control":​ put simply, a way to collaborate on a set of files that makes it easy to share and receive updates to those files. ''​GitHub''​ is a website that hosts those files in a convenient place so that the ''​Git''​ software can do its job.
Line 44: Line 44:
  
 <​code>​ <​code>​
-addpath('​\Documents\GitHub\PSYC50Rhythms'​);​+addpath(genpath('​\Documents\GitHub\PSYC50Rhythms'​));
 </​code>​ </​code>​
  
-(obviously, if you placed the code in some different place, substitute that.)+Obviously, if you placed the code in some different place, substitute that. Also, it may be that your computer prefers forward slashes (''​\''​) instead of backslashes (''/''​)!
  
 Now you've told MATLAB to add this new location to the list of places it looks for commands (the "​path"​). To check that MATLAB can find our shiny new EDF loader, do ''​which edfread''​. If things are set up right, MATLAB should reply with the location of where the ''​edfread.m''​ file is located, and you're all set for the final step below. Now you've told MATLAB to add this new location to the list of places it looks for commands (the "​path"​). To check that MATLAB can find our shiny new EDF loader, do ''​which edfread''​. If things are set up right, MATLAB should reply with the location of where the ''​edfread.m''​ file is located, and you're all set for the final step below.
  
 === Loading and plotting the data === === Loading and plotting the data ===
 +
 +In MATLAB, set its current ("​working"​) directory to where you placed your data. You can to this either using the ''​cd''​ command just like you would in a terminal, by pasting a path that you copied from Finder/​Explorer into the path box, or by clicking the "​Browse for Folder"​ button next to the path box. This important because otherwise MATLAB won't be able to find our data file.
 +
 +Then, you can do:
 +
 +<​code>​
 +fn = '​Seth1.edf';​
 +[hdr,data] = edfread(fn);​
 +</​code>​
 +
 +(As an aside, it is a good idea to enter these commands into the MATLAB Editor, rather than into the Command Window directly. From the Editor, it is easier to save your work, and re-run code without having to re-type or copy and paste it. To start the Editor, type ''​edit''​ at the command line.)
 +
 +Now, at last, you can plot the data:
 +
 +<code matlab>
 +plot(data'​)
 +</​code>​
 +
 +You should get:
 +
 +{{ :​analysis:​rhythms:​sethplot.png?​nolink&​600 |}}
 +
 +The traces you see include some signals recorded from the Emotiv'​s electrodes, positioned on the skull (the traces at the top), signals from the Emotiv'​s accelerometers (the signals in the middle), and some timing and event channels (at the bottom). The neural data traces don't look great: there are various features that we suspect are probably non-neural artifacts, such as the sharp spikes appearing on a few channels simultaneously. But it will do in having something to work with for now!
 +
 +=== Structure of Emotiv data ===
 +
 +Type ''​whos data''​ and note what MATLAB tells you about the size of the ''​data''​ variable: it's ''​37 x 8448'',​ meaning it is a matrix with 37 rows, each containing 8448 //samples// (measurements). The mapping from these rows to electrode identifiers is given in [[https://​cl.ly/​312d1g363V0Y | this file]], see the Emotiv manual for reference on where on the brain these identifiers correspond to.
 +
 +Look at the horizontal (x) axis of the plot we made earlier. It contains labels that correspond to these samples. A more informative plot would contain //time//, in seconds.
 +
 +☛ Construct a vector of timestamps containing the time, starting with 0, of each of the 8448 samples in this data. This requires knowing the sampling rate of the Emotiv; consult the manual or the file header to find this out. Then, replot the data using this time vector.
 +
 +==== Optional: streaming Emotiv data ====
 +
 +If you want to access Emotiv data in (near) real-time, rather than loading a previously saved file, I recommend using the FieldTrip toolbox. Use Git, as above, to clone the current FieldTrip repository. Then, in MATLAB, add it to your path as follows:
 +
 +<​code>​
 +cd('​C:​\Users\mvdm\Documents\GitHub\fieldtrip'​);​
 +ft_defaults;​
 +</​code>​
 +
 +Make sure your Emotiv headset is on and you have the Bluetooth receiver'​s light flickering. Then, from a command prompt, launch the following two executables:​ ''​buffer.exe''​ (in \GitHub\fieldtrip\realtime\bin\win32) and ''​./​emotiv2ft.exe emotiv-config.txt''​. If that looks like it's working (you should get some status updates showing up in the command prompt), do this in MATLAB:
 +
 +<​code>​
 +ft_realtime_plot([])
 +</​code>​
analysis/rhythms/step1.1459276221.txt.gz · Last modified: 2018/07/07 10:19 (external edit)