View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Generate synthetic fMRI data

4.0 | 4 ratings Rate this file 10 Downloads (last 30 days) File Size: 88.6 KB File ID: #36125 Version: 1.14
image thumbnail

Generate synthetic fMRI data



11 Apr 2012 (Updated )

This program is useful for debugging fMRI analyses and models.

| Watch this File

File Information

Given a set of voxel location (sample file provided), experimental design matrix, and a desired signal-to-noise ratio, this program generates a set of synthesized voxel activations.
Each experimental covariate (which can be activated to varying degrees during each trial, as specified in the design matrix) is assigned a single radial basis function. The basis function's center is chosen uniformly within the confines of the specified brain, and the width is also chosen uniformly. (Note: you can associate multiple radial basis functions with each covariate by giving each covariate multiple columns in the design matrix.)

The synthesized brain image for each trial is a weighted combination of the basis functions for the sources active during that trial, plus zero-mean Gaussian noise. (The standard deviation of the Gaussian noise is controlled via the SNR parameter.)

For added realism, an optional flag allows the user to specify whether the synthetic data incorporate a synthetic hemodynamic response function.

The synthetic data can be saved in NIFTI format (this relies on code, included in the download, from

Note: this code includes the "join" function available here:


Tools For N If Ti And Analyze Image and Join inspired this file.

MATLAB release MATLAB 8.6 (R2015b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (15)
11 Nov 2015 Jeremy Manning

Hi hstein,

The key to creating data that satisfy particular time series constraints is to construct an appropriate design matrix, as you noted. Each row of the design matrix corresponds to a time point. Each column corresponds to the desired activity of some brain region (for this simulation, a brain region is a randomly constructed sphere somewhere in the brain). In your case, you'll want to add a column to the design matrix for each BOLD time series that you want the simulation to mirror. (And if you want multiple simulated "brain regions" to mirror a single BOLD time series, you should replicate the corresponding columns of the design matrix.) You should set the "sim_hemo" flag to false so that the time series in your design matrix is not convolved with the HRF.

If you want to create a synthetic .nii image as a 10 by 20 by 30 voxel rectangular prism (stored at synthetic.nii), with a pre-specified design matrix (X), and with no noise (infinite signal-to-noise), you can do so using the following command:

[data, cov_images, params, meta] = generate_data([10 20 30], x, inf, 1, false, 'synthetic.nii');

Where the output parameters are described in the generate_data.m documentation ("help generate_data") and the .nii file synthetic.nii may be viewed with any standard brain image viewer (e.g. fslview).

Comment only
10 Nov 2015 hstein

hstein (view profile)

Hi Jeremy,
I am using your toolbox to plot fMRI data generated with a computational DFT model (see Buss et al. 2014 for a desciption, doi: 10.1162/jocn_a_00496). For each model layer (signal source) I have an average BOLD signal per condition, so my data are already convolved with the HRF.
How can I correctly use these data for image generation with your toolbox? I tried using the layerwise standardized signal (with values within [0,1]) as a nconditions by nlayers design matrix which worked but still seems incorrect to me.

Thanks for your help!

Comment only
27 Apr 2015 Janki Mehta

04 Dec 2014 Marta maieron

really good

21 Jan 2013 Edward King


Comment only
23 Dec 2012 Jeremy Manning

Hi Nes,

You're having trouble downloading the brain plots package? You should add a comment to that submission page, not this one. But if you just click the "Download Submission" link and unzip the file you download, all of the .m files should be in the resulting folder. I just re-downloaded that package to verify, and it looks OK to me...

Comment only
23 Dec 2012 Nes

Nes (view profile)

Hi Jeremy,
I'm searching page, but I cant see any file which I can download.
Your file is erased, isn't it?
Thank you

Comment only
16 May 2012 ladyme

ladyme (view profile)


11 May 2012 Jeremy Manning

The "data" variable contains the images for each trial specified by the design matrix (see above). That's what you pass to plot_brain2d or plot_brain3d. The 2d plots usually work better for viewing the synthetic data. This is because, whereas in real data "interesting stuff" often happens on the outer surface, in the synthetic data the sources are equally likely to be anywhere within the brain volume.

Let's say you want to generat a simple dataset with two trials, one unique source active per trial, and infinite signal-to-noise:

[data,cov_images] = generate_data(meta,eye(2),inf);

To generate 2d plot of first trial using default settings (requires installing, use:


To generate a 3d plot of second trial using default settings, use:


In each of the above examples, "meta" is the matrix included with the download of this package. (See documentation for additional details on the meta matrix.)

Comment only
11 May 2012 ladyme

ladyme (view profile)

so i just fed the result from the generate_data into the plot_brain3d? which to use? data or cov_images? would you mind showing the line how it works? thanks

10 May 2012 Jeremy Manning

Hi ladyme,

To plot the images, you can use

Comment only
10 May 2012 ladyme

ladyme (view profile)

sorry for such a silly question, but how can i plot the image?

Comment only
26 Apr 2012 Jeremy Manning

I've updated the submission with some example design matrices -- I hope that helps! (Give it a day or so for the update to show up.)

Comment only
26 Apr 2012 Karl

Karl (view profile)

The design matrix, X, must be a matrix of real numbers. Each column of X corresponds to a single covariate. Each row of X corresponds to a single trial (one image will be generated per trial). So row i, column j controls how active covariate j is during trial i. For example

X = eye(5);

corresponds to 5 trials, with one covariate active per trial.

X = rand(10,5);

gives you 10 trials, with 5 covariates randomly active during each trial. Finally,

X = [eye(5) eye(5)]

gives you 5 trials, with 2 covariates active during each trial.

Comment only
26 Apr 2012 mizzue

mizzue (view profile)

hi Jeremy,

i am curious how do you design the X matrix?

Comment only
11 Apr 2012 1.1

minor change to program description.

12 Apr 2012 1.2

minor change to program description.

27 Apr 2012 1.3

updated help text to include usage examples.

15 May 2012 1.4

added support for SNR = 0

27 Feb 2013 1.7

support convolution with hemodynamic response function, outputting to NIFTI format.

07 Mar 2013 1.9

modified the meta struct so that the function produces more realistic brain images. i also added an option to output source parameters.

07 Mar 2013 1.12

updated description, added pointer to

01 Jul 2013 1.13

updated HRF convolution, added additional files from file exchange submission #8797

11 Nov 2015 1.14

Substantially faster implementation, usability improvements.

Contact us