Code covered by the BSD License  

Highlights from
Generate synthetic fMRI data

4.0 | 4 ratings Rate this file 33 Downloads (last 30 days) File Size: 87.6 KB File ID: #36125 Version: 1.13
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


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

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
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

Contact us