SEREEGA is a modular, general-purpose, free and open-source MATLAB-based toolbox to generate simulated toy data mimicking event-related electroencephalography (EEG) data. It uses EEGLAB for some of its functions.
Starting with a forward model obtained from a head model or pre-generated lead field, dipolar brain components can be defined. Each component has a specified position and orientation in the brain. Different activation signals can be assigned to these components. EEG data is simulated by projecting all activation signals from all components onto the scalp and summing them together.
SEREEGA is modular in that different head models and lead fields are supported, as well as different activation signals. Currently, SEREEGA supports the New York Head (ICBM-NY) pre-generated lead field, the Pediatric Head Atlases pre-generated lead fields, and FieldTrip custom lead field generation. Four types of activation signals are provided: ERP (event-related potential, i.e. systematic deflections in the time domain), ERSP (event-related spectral perturbation, i.e. systematic modulations of oscillatory activations), noise (stochastic processes in the time domain), and signals based on an autoregressive model. A final data class allows the inclusion of any already existing time series as an activation signal.
SEREEGA is intended as a tool to generate data with a known ground truth in order to evaluate neuroscientific and signal processing methods, e.g. blind source separation, source localisation, connectivity measures, brain-computer interface classifier accuracy, derivative EEG measures, et cetera.
As an example, the following code produces an EEGLAB dataset containing 100 epochs of 64-channel EEG data, each consisting of the summed activity of 64 simulated sources spread across the brain. The final dataset includes a ground-truth ICA decomposition that can be used to verify the accuracy of newly calculated decompositions.
% configuring for 100 epochs of 1000 ms at 1000 Hz
config = struct('n', 10, 'srate', 1000, 'length', 1000);
% obtaining a 64-channel lead field from ICBM-NY
leadfield = lf_generate_fromnyhead('montage', 'S64');
% obtaining 64 random source locations, at least 2.5 cm apart
sourcelocs = lf_get_source_spaced(leadfield, 64, 25);
% each source will get the same type of activation: brown coloured noise
signal = struct('type', 'noise', 'color', 'brown', 'amplitude', 1);
% packing source locations and activations together into components
components = utl_create_component(sourcelocs, signal, leadfield);
% simulating data
data = generate_scalpdata(components, leadfield, config);
% converting to EEGLAB dataset format, adding ICA weights
EEG = utl_create_eeglabdataset(data, config, leadfield);
EEG = utl_add_icaweights_toeeglabdataset(EEG, components, leadfield);
SEREEGA on GitHub
SEREEGA manuscript preprint on bioRxiv
A permutation test (aka randomisation test) for MATLAB, supporting one- and two-tailed tests and capable of visualising the outcome using a histogram. Provides a p-value, the observed difference, and the effect size. It is also possible to perform exact tests, during which all possible combinations are considered.
For example, the following tests two samples (n=5000 each) from normal distributions against each other, one shifted .1 to the right (two-tailed, 10000 permutatinos). It produces the subsequent plot.
sample1 = randn(1,5000);
sample2 = randn(1,5000) + .1;
permutationTest(sample1, sample2, 10000, 'plot', 1);
permutationTest on GitHub
permutationTest on MATLAB Central
This script allows you to generate a colour scale (as for colormap, colorbar) using any number of custom colours, and allows you to arrange these colours by adjusting their relative positions with respect to each other, much like you may be used to creating gradients in e.g. Adobe Photoshop or CorelDRAW. It will automatically interpolate the colours in between the indicated anchor points.
In its most basic form, simply call the script using an n-by-3 matrix of RGB values, and it will generate the colour map accordingly. For example, to create and set a simple black-red-yellow-white colormap, we would put those four colours in that order as the first argument to multigradient, and pass that onto MATLAB's colormap command:
rgb = [0 0 0; 1 0 0; 1 1 0; 1 1 1];
It is possible to change the relative location of the colours by adjusting the relative values of the color stops, or control points. One control point must be indicated for each given colour. (Exception: when two colours are given, three control points can be used, with the second one representing the middle of the colour scale.)
pts = [1 5 6 7];
Further tricks are optional, but include interpolation in HSV space, isoluminant maps through interpolation in L*a*b* (Lab) space, Kenneth Moreland's algorithm for divergent colour maps for scientific visualisation, and many presets, including some by Kenneth Moreland and Cynthia Brewer.
multigradient on GitHub
multigradient on MATLAB Central
Kenneth Moreland's website includes good colour advise and the algorithm implemented here.
Cynthia Brewer's color advise for maps from which a number of presets have been taken.
plot_erp is a MATLAB-based script to plot event-related potentials (ERPs) from any number of given epoched datasets (in EEGLAB format), for a single channel. For each ERP curve, any number of datasets can be given. It can optionally calculate and plot a difference wave, standard errors, and permutation-based statistics (using permutationTest). Mean curves and statistics can be calculated either within or between datasets.
For example: Two ERPs plus their difference, standard error of the mean for all curves, and statistics highlighting significant differences, using the default colour scheme.
Or: ERPs for eight groups of 19 datasets each with custom colours, labels, and x scale indicator position.
plot_erp on GitHub
MATLAB script to map values from one range onto another range, either linearly or along a given exponential curve. Also supports inverse ranges, and can extrapolate. This is perhaps a small feat but I've found it to be highly useful in a range of scenarios.
For example, we may map the values in a source range from 10 to 15 to their corresponding values in a target range between 0 and .5, where 10 becomes .5 and 15 becomes 0, with an exponential curve falloff using the power of 5.
maptorange on GitHub
maptorange on MATLAB Central
This has made the analysis of some visual data a little easier for me. Rather than browsing through image files in alphabetical order, this script allows them to be browsed through in a multi-dimensional fashion. Take for example the following files:
Regular alphabetical ordering would have you browse first through all apples, colour by colour, then through the bananas, colour by colour, and then the pears and plums. These files, however, contain two dimensions: fruit type, and fruit colour. This script makes it possible to jump from the green banana to the green apple with one button, and from the green apple to the yellow apple with another.
Simply supply it with a directory and a file pattern, and the script automatically extracts and orders all dimension values.
File names should be consistent except for the variable parts, and the variable parts should be separated somehow. A variable part of the file names representing one dimension is indicated using an asterisk (*). For the above example, the pattern would be:
The script then allows you to browse through the available dimensions using the keyboard. The keys for the first dimension are under the "1", i.e. on a QWERTY keyboard, "q" for one up in this dimension, and "a" for one down. "w" and "e" increase and decrease the second dimension, respectively, and "o" and "l" represent the ninth dimension. The first two dimensions can additionally be controlled by the arrow keys.
Dimensions are numbered in the order that they appear in the file names.
Keyboard shortcuts include shift+D to set the directory, and shift+P for the pattern. Enter applies, escape exits.
Multi-Dimensional Image Browser on GitHub
This scripts extracts word entries from text files (e.g. plain text dictionaries, word lists, etc.) and then allows case-insensitive regular expression searches to be performed on those entries, for those occassions where you need to find words or terms fitting a specific pattern. German words of exactly 35 characters, for example, or funny words in the English dictionary that twice contain either bb or dd:
The results of the searches are both shown in the console and written to a text file.
14 dictionaries and word lists are included. Additional dictionaries can be added by simply adding the corresponding names and extraction expressions to the dictionaries array. Encode the files in UTF-8 without BOM.
Empty input either exits the script (when in dictionary selection mode) or goes back to dictionary selection.
Python Regex Dictionary Search on GitHub
A small, single-file PHP script that handles everything you need in order to turn an online directory into a responsive image gallery. By default, it serves up a thumbnail (and directory) browser, automatically creating thumbnails for supported graphical file formats. When a thumbnail is selected in the browser, or when accessing a specific image directly using its URL, the script serves up a full-screen image viewer with navigational controls. When on desktop, this image viewer can additionally show images either at 100% of their size, or fit them to the screen, and can be controlled by keyboard. On mobile, swipes can be used for navigation. From this screen, the image can also be downloaded.
The script can easily be customised with respect to the thumbnail size, shape, and the number of columns. Furthermore, the style sheet uses only four, customisable colours. Two colour schemes are included.
This online example uses a dark colour scheme.
This online example uses a light colour scheme.
Noctifer Directory Gallery Script on GitHub