Source Code - cSPIKE

Matlab command line library

Description of the codes

cSPIKE v 1.0 29.9.2016: Eero Satuvuori

This is the main part of cSPIKE. The object offers the basic functionality of graphical user interface SPIKY as a command line version. The main functions are implemented with MEX files and C++ backends. Methods are based on the ISI-distance, the SPIKE-distance and the SPIKE-synchronization by Thomas Kreuz et al. The class contains data and methods for storing spike trains as a single set as well as calculating the different distance measures.

*** Important ***

Before you use the cSPIKE for the very first time on a computer you

need to compile the MEX and C++ backends. To do so go to folder

cSPIKEmex and run script MEX_compile.m. This may take few minutes.

Every time you call for MEX files(most functions of the SpikeTrainSet

use them) the folder in which they are located need to be in your

Matlab workspace. InitializecSPIKE-script will add it to your path. It

needs to be called once every time after starting Matlab and any

additional calls are not needed. This is not called by the SpikeTrainSet!


SpikeTrainSet implements the following functions

To create a spike train set object call the constructor:

spiketrains: A cell array with SpikeTrains{1} containing an

array of spike times [spike1 spike2 ...spikeN] for the

first spike train and respectively for the other spike

trains. The object accepts only spike data aligned as row


beginning: The start time of the recording

endgin: The end time of the recording

STS = SpikeTrainSet(spiketrains, beginning, ending )

Then you can call methods for the spike train set:

time1: Start time of the analysis interval.

time2: End time of the analysis interval. If not given or if

time1 = time2 instantaneous dissimilarity value is given instead.

threshold: Threshold for the adaptive method. If not given the

threshold extracted from the data is used instead.

Profile: Profile object

STS.ISIdistance(time1, time2)

STS.ISIdistanceMatrix(time1, time2)

Profile = STS.ISIdistanceProfile(time1, time2)

STS.AdaptiveISIdistance(time1, time2, threshold)

STS.AdaptiveISIdistanceMatrix(time1, time2,threshold)

Profile = STS.AdaptiveISIdistanceProfile(time1, time2,threshold)

STS.SPIKEdistance(time1, time2)

STS.SPIKEdistanceMatrix(obj, time1, time2)

Profile = STS.SPIKEdistanceProfile(obj, time1, time2)

STS.AdaptiveSPIKEdistance(time1, time2, threshold)

STS.AdaptiveSPIKEdistanceMatrix(obj, time1, time2,threshold)

Profile = STS.AdaptiveSPIKEdistanceProfile(obj, time1, time2,threshold)

STS.RateIndependentSPIKEdistance(time1, time2)

STS.AdaptiveRateIndependentSPIKEdistance(time1, time2, threshold)



SPIKESM: Spike synchronization matrix

SPIKEOM: Spike order matrix

normSPIKEOM: normalized spike order matrix

[SPIKESM,SPIKEOM,normSPIKEOM]= STS.SPIKESynchroMatrix(time1, time2)

[SPIKESM,SPIKEOM,normSPIKEOM] = STS.AdaptiveSPIKESynchroMatrix(time1, time2, threshold)

synchro: a cell array identical to spike train set but instead of spike

times it contains SPIKE-synchronization values of each spike

Sorder: a cell array identical to spike train set but instead of spike

times it contains SPIKE-order values of each spike

STOrder: a cell array identical to spike train set but instead of spike

times it contains spike-train-order values of each spike

[synchro,Sorder,STOrder] = STS.SPIKEsynchroProfile(time1, time2)

[synchro,Sorder,STOrder] = STS.AdaptiveSPIKEsynchroProfile(time1, time2,threshold)

varargin: Each time moment is given as a separate parameter. Returns

the dissimilarity averaged over all time points.


STS.TriggeredAdaptiveISImatrix(threshold, varargin)


STS.TriggeredAdaptiveSPIKEmatrix(threshold, varargin)

varargin: Each pair of inputs defines a new interval over which the

distance is defined. A unique union of the intervals is

used when defining the intervals over which the average is



STS.AveragedAdaptiveISIdistanceMatrix(threshold, varargin)


STS.AveragedAdaptiveSPIKEdistanceMatrix(threshold, varargin)

Auxiliary functions:

STS.SetData(spiketrains, beginning, ending )

Replaces the data in the object with new data


Gives the a copy of the data array of the object. Data{1} contains

the edge corrected data and Data{2} the original spikes.


Returns the threshold value obtained from the set

[time1,time2] = STS.giveTIMES()

Gives the beginning and the end of the recording


Plots the spike trains to current axis with colour and spike widith

given. Default colour is black.

SpikeTrainSet contents

  • Class for enclosing spiketrains into one class and handling the set.

  • PRIVATE METHODS **************************************************

  • Checking data availability

  • Unique Union

  • Checking that the DATA given is valid

  • Cutting function

  • Check input times

  • Correct the DATA Edges

  • Form pooled spiketrain of all spiketrains

  • Time shift functions.

  • PUBLIC METHODS ***************************************************

  • Constructor

  • Setting data

  • ISI METHODS ----------------------------------------------------

  • ISI-distance for interval/point

  • Adaptive ISI-distance for interval/point

  • ISI-distance/dissimilarity matrix

  • Adaptive ISI-distance/dissimilarity matrix

  • Triggered ISI-dissimilarity matrix

  • Triggered Adaptive ISI-dissimilarity matrix

  • Averaged ISI-distance matrix

  • Averaged Adaptive ISI-distance matrix

  • ISI-distance profile

  • Adaptive ISI-distance profile

  • SPIKE METHODS --------------------------------------------------

  • SPIKE-distance for interval/point

  • Adaptive SPIKE-distance for interval/point

  • Rate independent SPIKE distance for interval/point

  • Adaptive Rate independent SPIKE distance for interval/point

  • SPIKE distance/dissimilarity matrix

  • Adaptive SPIKE distance/dissimilarity matrix

  • Triggered SPIKE-dissimilarity matrix

  • Triggered Adaptive SPIKE-dissimilarity matrix

  • Averaged SPIKE-distance matrix

  • Averaged Adaptive SPIKE-distance matrix

  • SPIKE-distance profile

  • Adaptive SPIKE-distance profile

  • SPIKE-Synchronization METHODS ----------------------------------

  • SPIKE-Synchronization

  • Adaptive SPIKE-synchronization

  • SPIKE-synchronization profile

  • Adaptive SPIKE-synchronization profile

  • SPIKE-synchronization matrix

  • Adaptive SPIKE-synchronization matrix

  • Auxiliary functions --------------------------------------------

  • Get function

  • Threshold value extracted from the data

  • Start and end of the data set

  • Plotting function

Profile v 1.0 29.9.2016: Eero Satuvuori

Object for storing the data and plotting ISI-profile and SPIKE-profile

The Profile object is created by the object SpikeTrainSet upon calling

for the ISI- and the SPIKE-distance based profiles.

Xvalues = PlotProfileX()

Returns the X-ticks of the profile as a vector

Yvalues = PlotProfileY()

Returns the Y-values of the profile that are matched to their

corresponding index values in the Xvalues.


Plots the profile to the current axis with colour defined. Alpha is

the opacity of the profile. For 1 the profile is solid and for 0.1 almost transparent.

Published with MATLAB® R2015b