Spike raster plot


A graphical representation of neural activity - spike timing.


The most important information of spikes or action potentials is timing. Size and shape do not matter. Therefore, in many cases it used to be enough to just store these spike timings offline. You would delete the actual shape of the spikes or the membrane potential between spikes present in the recorded voltage trace, in order to save space on your hard drive. Nowadays, computer space is no longer so much a limitation, and scientists are getting interested in items such as local field potentials and oscillations (and the size and shape of spikes). Still, for the analysis of spikes, creating a raster or a dot plot is one of the first things you would want to do. A raster (dot) plot graphically shows a tick (dot) at the time a spike was present in the recorded voltage trace.


Here, you will create a raster plot of the activity of a neuron in the auditory cortex, that was recorded while 13 tones of different frequencies (200 Hz to 16 kHz, logarithmically spaced) at 4 different sound levels (40, 50, 60 and 70 dB) were presented 10 times (making a total of 520 trials). The data for this tutorial can be found here. Detection of action potentials and sorting of the spikes has already been done (by Jan Schnupp's BrainWare in TDT; if you are interested, you can find a review on spike detection and sorting here and a Matlab toolbox here).


At every trial, the recording started 300 ms before the presentation a 150 ms long tone. Spikes at the start of the trial are timestamped 0 ms.

First, as always, you will have to load the data.

whos tonespike % to see the structure in your command space

In your workspace, you will see that the data are stored in a structure (struct), and this structure has a size of 1x520. To obtain the spike timings of the first trial, type:

t = tonespike(1).spiketime; % Spike timings in the first trial

This is a vector containing 12 elements / spike times (check this yourself). Every trial will have its own number of spikes, as the cell will not fire the same number of spikes for every stimulus. This is why the data are stored in a struct-array as this allows you to store vectors of different sizes. The second trial only has 5 spikes:

t = tonespike(2).spiketime; % Spike timings in the second trial

Now, let's plot a raster of the 180th trial:

t       = tonespike(180).spiketime; % Spike timings in the 180th trial
nspikes   = numel(t); % number of elemebts / spikes
for ii = 1:nspikes % for every spike
    line([t(ii) t(ii)],[179.5 180.5],'Color','k'); % draw a black vertical line at time t (x) and at trial 180 (y)
xlabel('Time (ms)'); % Time is in millisecond
ylabel('Trial number');
You might notice that after 300 ms (the tone onset) spikes occur more often. So the firing rate of this neuron seems to increase, even for one trial, during the presentation of a sound.image

The increase in firing rate will be more clear, when we plot all the trials. For that we add an extra for-loop.

ntrials = numel(tonespike); % number of trials
for jj = 1:ntrials
    t       = tonespike(jj).spiketime; % Spike timings in the jjth trial
    nspikes   = numel(t); % number of elemebts / spikes
    for ii = 1:nspikes % for every spike
      line([t(ii) t(ii)],[jj-0.5 jj+0.5],'Color','k'); 
      % draw a black vertical line of length 1 at time t (x) and at trial jj (y)
xlabel('Time (ms)'); % Time is in millisecond
ylabel('Trial number');

You will see something similar to the top figure (also indicated by thick black vertical lines are onset and offset of the stimulus; note also the different y-axis label and ticks). The number of spikes increase during tone presentation (between 300 and 450 ms) for about half of the trials (and after tone offset there is another burst). You might notice that this neuron's activity is not very reproducible from trial to trial. This is to be expected, as neurons are usually tuned to specific stimulus features, and most trials contained different stimuli. However, even during an exact stimulus repeat, the neural response will contain an element of randomness. What this actually means for the reliability of neural information transmission, will be explained in other tutorials.

Matlab Code

The pa_spk_rasterplot.m file in the PandA toolbox easily produces the raster plots for structure arrays, and also for matrices.