Frequently Asked Questions (FAQs)
© 20092011 Kayser
last updated: February 22, 2011
CSD toolbox home  
CSD toolbox tutorial  
common mistakes and errors  
frequently asked questions FAQs 
1. Can I use an EEGlab or BioSemi montage that also includes spherical angles Theta and Phi? 

Because EEGlab uses a different spherical coordinates system, in which the spherical angle Theta is shifted 90° compared to its CSD toolbox equivalent, the EEGlab coordinates must be converted to CSD toolbox spherical coordinates. Similarly, BioSemi uses a spherical coordinate system (cf. position coordinates) in which the angle Phi denotes vertex downward shifts as opposed to the CSD toolbox which uses the origin of the sphere as the angle reference point. The CSD toolbox function ConvertLocations.m provides an easy means to convert between these different notations (type "help ConvertLocations" at the command window to obtain help on this function).

Back to top  Home  Tutorial  Errors  FAQs 
2. Are there any differences between the spherical coordinates provided by CSD toolbox or EEGlab / BioSemi? 

Apart from a 90° rotation of spherical angle Theta, EEGlab places standard and extended 1020system electrode sites at different locations than CSD toolbox. Likewise, even after adjusting of the spherical angle Phi, some BioSemi position coordinates with nominal identity differ from those provided by the CSD toolbox. In EEGlab and BioSemi, for instance, all electrodes on the xy plane (i.e., the circle combining the locations Fpz, T7, Oz, and T8) are located 2° below the sphere's equator. In contrast, the CSD toolbox places these locations directly on the equator (i.e., where they belong if one directly follows the logic of the 1020system; e.g., cf. Jurcak et al., 2007). Whereas these differences may be of minor importance when mapping volumeconducted scalp potentials, these differences will have a greater impact for the computation of CSD estimates, because the CSD computation is based on relative differences between scalp sites. For example, a prominent visual ERP component at occipital will be differently represented if, let's say, sites P9, P7, P5, P07, and P09 have a different spatial representation. This issue will ultimately also impede on the comparison of findings across studies, a limitation that can be overcome by using a referencefree CSD approach. A different consideration is using a more realistic head model rather than a simplified spherical model, but it does not appear that the EEGlab coordinates are preferrable in this regard when compared to their CSD toolbox counterparts. For these reasons, it is strongly recommended to use spherical locations as specified in the CSD toolbox lookup table (see ASCII file "105System_Mastoids_EGI129.csd"). At the very least, the coordinate system used to specify electrode locations should be clearly indicated.

Back to top  Home  Tutorial  Errors  FAQs 
3. How do I convert between the different spherical angles used in CSD toolbox and EEGlab or BioSemi, or given by generic 3D Cartesian coordinates? 

The CSD toolbox function ConvertLocations.m converts between the CSD toolbox spherical coordiante system stored in *.csd files, the EEGlab polar and spherical coordinate systems used in *.locs and *.ced files, the BioSemi spherical coordinate system used in *.biosemi text files consisting of a channel label followed by two spherical angles (cf. position coordinates), or as given by *.xyz text files specifying generic 3D Cartesian coordinate (channel label followed by x, y, and z coordinates). This function also allows to specify a subset of electrodes included in one of these ASCII coordinate files to generate a new and/or reordered EEG montage (type "help ConvertLocations" at the command window to obtain help on this function).

Back to top  Home  Tutorial  Errors  FAQs 
4. Why do I get an "Inner matrix dimensions must agree" error when submitting data to the CSD.m function? 

The CSD toolbox function CSD.m requires as input an electrodes × samples data matrix (i.e., consisting of rows equal to the number of electrodes), and transformation matrices G and H consisting of rows and columns equal to the number of electrodes (type "help CSD.m" at the command window to obtain help on this function). If these dimensions do not match, the original code of CSD.m would result in this Matlab error:
This error is typically the result of not transposing the input data matrix (e.g., submitting a samples × electrodes rather than an electrodes × samples matrix orientation; see also answer to FAQ #5. ). It can also be caused by the Matlab textread.m routine, which in some Matlab versions (e.g., Matlab 6.5, Release 13) incorrectly reads numeric values from a text file. [For the example data provided for the tutorial, the addition of zero column at the end of the data matrix can easily be corrected by removing the last column, e.g. by entering "D = D (:,1:31)" at the command line.] The user should always verify the dimensions of the data matrix (e.g., by inspecting the Matlab workspace). However, an improved error checking for the input matrix dimensions was implemented in the revised CSD toolbox function CSD.m.

Back to top  Home  Tutorial  Errors  FAQs 
5. What causes the "G (?by?) and H (?by?) matrix dimensions must match rows (?) of data matrix" error of function CSD.m? 

The cause of this error is explained in the answer to FAQ #4. The CSD toolbox function CSD.m requires as input an electrodes × samples data matrix (i.e., consisting of rows equal to the number of electrodes), and transformation matrices G and H consisting of rows and columns equal to the number of electrodes (type "help CSD.m" at the command window to obtain help on this function). The likely origin of this error is submitting the transpose of the required data matrix (i.e., submitting a samples × electrodes rather than an electrodes × samples matrix orientation), which could be, for instance, the result of plotting the ERP waveforms, which requires preliminary transposition (see example given in step #5 of the CSD toolbox online tutorial). To understand the difference between a n × m and a m × n matrix, which contain the same data values but in different cells, envision referencing a particular cell of these matrices (i.e., the value in the cell of row 4 and column 2 of matrix D, which is referenced in Matlab as "D(4,2)", will change after transposing the matrix "D = D';", and this particular value will be in the cell of row 2 and column 4, that is, in "D(4,2)").

Back to top  Home  Tutorial  Errors  FAQs 
6. How do I include a linked reference (e.g., linked mastoids, linked ears) in my EEG montage? 
The answer to this question depends on how the data for a linked reference was recorded or stored. If two or more reference sites (e.g., left and right mastoids) were physicallylinked during data acquisition, or their data were averaged offline and the original channels were dropped (i.e., the original data is no longer available), the data from the reference locations can not be used in the CSD transform. In this case, the EEG montage consists of all recordings sites minus the reference locations, which is regrettable but nevertheless allows a sound CSD transform. However, if the data from the original reference locations are still accessible, these reference locations can and should be included in the EEG montage and must, of course, be represented in the surface potential data. For example, if the EEG was recorded with a leftmastoid reference (i.e., site LM or TP9) and the EEG data also include the right mastoid (i.e., site RM or TP10), an additional channel LM with zeros should be added to the surface potential data, and sites LM and RM should be included in the EEG montage. [Note: It is a severe error to include data of a linked reference for the CSD transform because these physicallydistinct scalp locations can not be modeled as a single site on the scalp.] 
Back to top  Home  Tutorial  Errors  FAQs 
7. Should I include a noncephalic reference in my EEG montage? 
No, because a noncephalic reference cannot be reasonably modeled as a scalp location. However, it is perfectly acceptable to simply use the surface potential data recorded from all scalp sites. Thus, the answer to this question is similar to when using a physicallylinked cephalic reference (as described in FAQ #6). 
Back to top  Home  Tutorial  Errors  FAQs 
8. What about applying a CSD transform to EEG spectra? 
CSD estimates can be only computed from surface potential data, which includes single EEG epochs. Thus, CSD spectra can be computed from CSDtransformed EEG epochs using the same spectral decomposition techniques (e.g., FFT) typically applied to referenced surface potentials (for an application of CSD spectra, see Tenke & Kayser, 2005). However, it makes no sense to compute "CSD spectra" from EEG power spectra because the power spectrum is a nonlinear and irreversibe data transformation (see detailed explanation here). 
Back to top  Home  Tutorial  Errors  FAQs 
9. Can I use CSD data to compute an inverse solution with other source localization tools, such as BESA or LORETA? 
CSD estimates represent underlying current generators because a surface Laplacian provides a conservative and accurate estimate of the current flow at the scalp. However, because the CSD transformation has already eliminated properties related to volume conduction, the use of CSD estimates as an input to "inverse" programs designed to infer, quantify and localize the intracranial generators of surface potentials (e.g., BESA, LORETA) is a violation of basic assumptions on which all of these inverse solution methods rely. Despite this caveat, it is still possible to expand the applicability of CSD methods by using inverse tools with surface potential topographies corresponding to time intervals or spectral bands (or their datadriven component simplications) that were initially identified and characterized using the referencefree CSD transform. 
Back to top  Home  Tutorial  Errors  FAQs 
10. Matlab appears to use a different CSD.m routine  what is going on? 
During prior releases of Matlab, the signal toolbox used the function CSD.m to compute Cross Spectral Density estimates. However, in Matlab revision R2009a (Version 7.8.0.347), this routine had been replaced by the function CPSD.m to compute Cross Power Spectral Density estimates, although CSD.m still worked. With the release of Matlab revision R2010a (Version 7.10.0.499), the original crossspectral density function CSD.m has been completely removed from Matlab, so this is no longer an issue. However, if you encounter a conflict between the CSD toolbox function CSD.m and the Matlab signal toolbox function CSD.m while using a previous Matlab release, there are several practical workarounds. For instance, it is possible to (temporarily) change the Matlab search path (in Matlab, click on the [File] menu and then on [Set Path...], and modify the search path order accordingly, or remove the path with the routine you don't want to use). Alternatively, you may consider renaming (or copying) the CSD toolbox routine CSD.m located in the CSD toolbox subdirectory "../func" (e.g., SP2CSD.m would be an appropriate new name). 
Back to top  Home  Tutorial  Errors  FAQs 
11. After converting surface potentials to CSD, can the converted data be analyzed like surface EEG? 
Laplaciantransformed EEG/ERP may be processed with any routine typically applied to surface potential EEG/ERP (i.e., referenced) data, which include high and/or low pass filter, fast fourier transform (FFT), baseline correction, averaging of epochs, etc. However, one has to keep in mind that CSD data are referencefree (i.e., data can not be converted back into surface potentials), which prohibits all postprocessing transformations that involve a recording reference (e.g., rereferencing the data). 
Back to top  Home  Tutorial  Errors  FAQs 
12. Is the polarity of a CSD signal more informative than the polarity of the surface potential? 
Yes, it is. The choice for a surface potential reference is quasiarbitrary, meaning that the polarity can only be interpreted in relative but not absolute terms. For instance, rereferencing the data from a vertex (Cz) recording reference to a linkedmastoids or average reference will change the polarity of the EEG/ERP signal for certain sites (regions) and/or time intervals (components), which, of course, has also implications for spectral data properties (e.g., phase, amplitude). In contrast, a surface Laplacian or CSD transform represents "true" estimates of current activity at scalp, meaning that the signal polarity (negative = sink, positive = source) is unambiguous by itself. CSD estimates are inherently referencefree by virtue of their computation (i.e., second spatial derivative), that is, they depend only on the topography of the EEG signal. As the EEG/ERP topography is not altered by different reference schemes because the subtraction of a constant (i.e., a different reference) does not alter the relative values between recording sites per sample point, CSD estimates are unique (i.e., there is only one CSD solution for a given EEG montage). 
Back to top  Home  Tutorial  Errors  FAQs 
13. How do I generate CSD transformations from an EEGlab data file? 
The general procedure is described in the CSD toolbox tutorial, which is strongly recommended to any researcher before embarking upon the transformation of EEG/ERP data into CSD estimates. However, two excellent example scripts kindly provided by John J.B. Allen showcase how to exploit the EEG montage information included in any EEGlab data file to generate the montagedependent "Channels × Channels" transformation matrices G and H (EEGlab_Make_G_H.m), and how to use these transformation matrices with individual EEGlab data files, consisting of "Channels × Sample Points × Epochs (Trials)" data matrices, to obtain corresponding CSD data files (EEGlab_Loop_Epochs.m). 
Back to top  Home  Tutorial  Errors  FAQs 
14. Is there an effcient way to loop through individual, very large EEGlab data files consisting of 3D data matrices (channelsbysamplesbyepochs)? 
As a general Matlab rule, preallocating memory, as opposed to sequentially allocating memory as a matrix increases in size over time, may substantially reduce overall computing time. If very large data files are to be converted, this may be an important consideration. The example script EEGlab_Loop_Epochs.m contains three different instructions to obtain CSD data from a "Channels × Sample Points × Epochs" data file used by EEGlab. The first set of instructions loops through all epochs and submits each epoch as a "Channels × Sample Points" 2D data matrix to the CSD.m routine, which is fine; however, without the initial memory preallocation for the CSD data output, this would be unnecessarily time consuming as the content of the final CSD data matrix is copied every time the matrix size is increased. The second set of instructions uses the Matlab reshape.m function to temporally reorganize the "Channels × Sample Points × Epochs" 3D data matrix into a "Channels × (Sample Points * Epochs)" 2D data matrix to comply with submitting a "Channels × Samples" 2D data matrix to the CSD.m function, which also works well. Surprisingly, submitting a "Channels × Sample Points × Epochs" 3D data matrix to CSD.m, as shown in the third set of instructions, works equally well despite the extra dimension. The reason for this unexpected observation is that Matlab implements a 3D matrix simply as a sequence of consecutive 2D matrices. For example, if EEG.data is a "64 channels × 256 samples × 100 epochs" data matrix, the Matlab statement "size(EEG.data)" will return "64 256 100" as the answer; however, explicitly requesting only two dimensions with the statement "[chans,points] = size(EEG.data)" will return "channels = 64" and "points = 25600", the latter being equal to the product of samples * epochs (this is also how the dimensions of a 3D data matrix are listed in the Matlab workspace). Thus, the compact oneline CSD statement in the third set of instructions produces the same results as the other two instruction sets. 
Back to top  Home  Tutorial  Errors  FAQs 
15. I am running out of memory when using the CSD.m routine with large data files  are there any workarounds? 
By default, Matlab uses double precision for data matrices. However, for most practical purposes regarding the CSD.m routine, single precision is fully sufficient. For instance, the Matlab statement "A = single(A);" converts a double precision matrix to single precision and reduces memory demands by half (the reverse Matlab statement "A = double(A);" reassigns double precision to matrix A). The example script EEGlab_Loop_Epochs.m shows how these operations can easily be integrated in the Matlab syntax. If this does not solve the memory issue, the obvious next work around is to split the CSD conversion process into smaller steps at a time (e.g., looping through all data epochs as shown in the first set of instructions given in EEGlab_Loop_Epochs.m). The extreme end of this workaround is submitting one sample point at a time to the CSD.m routine (i.e, a column vector, which represents a "Channels × 1" 2D data matrix). 
Back to top  Home  Tutorial  Errors  FAQs 