The code comes in nine java files. I will go through them briefly.

The main file, *EEG.java*, represents the main EEG worker window
and implements all the panels, boxes, menus and button commands.

*Ipos.java* codes the shape of the display of the brain patterns in
the left hand panel of the main window. It loads a set of 129
electrode positions from the file "data/129.CartAscii.txt".
These 3D points are projected into a flat plane and connected
into a nearest neighbour graph which is used to generate the
interlocking polygons that colour each node, and to generate
the NodeProbe patterns.

*Imapcols.java* contains the array of colours used for painting the
nodes to represent the different intensities. If you are wanting
to tinker with the program and make it use more attractive colours
than simply red and blue, this is a good place to start.

*Imap.java* represents an actual drawing of the brain pattern
as it is shown on the left hand panel of the main window.
This is composed of a reference to the Ipos and the Imapcols,
together with an array of 129 node intensities to represent.

*Ibrainpatterns.java* is the second window with the row of brain patterns.
Consequently, it contains an array of Imaps.

The data is loaded by the functions in *Iraw.java*. This is
of interest to anyone writing programs for reading output from
EGI's machines. Their file comes in a simple format where all
the electrode readings are recorded as short 16 bit integer
numbers. There are functions for saving out a file in the same format.
These should be ignored since they were merely used to trim down
the example files I did have into one that was shorter.

*Idata.java* is where the calculations are controlled. The
data from a single experiment, or the output from the fake
data generator, is copied into here. This stores an array of,
in the sample example, 850 129-dimensional vectors.

The most important function here is
*MakeSubspaceVex()*
which, given a series
of vectors,
*electrodesub[0], ... electrodesub[nv - 1]*,
loops through the 850 vectors
*electrodeins[0], ..., electrodeins[849]*
and for each *i* finds values of
*subspacescalars[i][0], ..., subspacescalars[i][nv - 1]*
such that the magnitude of the vector
*diff = electrodeins[i] - (subspacescalars[i][0] * electrodesub[0] + ... + subspacescalars[i][nv - 1] * electrodesub[nv - 1])*
is minimized.

This latter equation can be expressed as:
*d = e - S * s*
where *S* is the matrix of subspace vectors (*nv* columns
and 129 rows), and *s* are the scalars we want to find out.
Left-multiplying both sides by *Transpose(S)*
will set the left hand side to zero (if *d* is minimal),
and leave the right hand side as an *nv* row
column-vector minus a square matrix times another column vector.
This can be solved using standard matrix arithmetic to derive
a solution for *s* and thus a value for *d*.

When you click on the **NextVex** button, the program
simply selects the vector with the highest magnitude of *d*
as a good candidate for finding the widest support for
the EEG space using the fewest basis vectors.

*Imath.java* contains the matrix functions, including
matrix solution of the above matrix equation by Gaussian
elimination. This code could be used in other applications.

*Igraph.java* represents the time graph of the electrode readings in
the right hand panel of the main window.

This code is protected by the GNU General Public license which means you are free to use, modify and redistribute it as long as it does not get included as part of a program that is not also protected by an Open Source license.