Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 472

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 487

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 494

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-settings.php on line 530

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594 Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594 Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 594

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 611 Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705 Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 705 Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /www/htdocs/w00a4756/wp-includes/classes.php on line 728

Strict Standards: Redefining already defined constructor for class wpdb in /www/htdocs/w00a4756/wp-includes/wp-db.php on line 306

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-includes/cache.php on line 103

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /www/htdocs/w00a4756/wp-includes/cache.php on line 425

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /www/htdocs/w00a4756/wp-includes/theme.php on line 623

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /www/htdocs/w00a4756/wp-includes/class.wp-dependencies.php on line 15
SPM for programmers
Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 947

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /www/htdocs/w00a4756/wp-includes/kses.php on line 948

Tips Martin Pyka on 19 Aug 2011

## Manual convolution with the HRF

With the help of two SPM-functions you can manually convolve time series in Matlab. This might help to understand how the convolution with the HRF (or any other function) affects the time series. Here is an example:

% create a time series reg = [zeros(10,1); ones(10,1); zeros(10,1); ones(10,1); zeros(10,1)]; plot(reg) 

% create a basis function, in this case the hrf bf = spm_get_bf % with a tr of 2.2 and HRF as basis function you receive dt: 2.2000 name: 'hrf' length: 33 order: 1 bf: [15x1 double] % these are necessary definitions for the spm_Volterra-function U.u = reg; U.name = {’reg’}; % U needs a name, but the string has no meaning % convolve reg with the hrf convreg = spm_Volterra(U, bf.bf); plot(convreg) 

Tips Martin Pyka on 31 May 2010

## Convert matrix coordinates to image coordinates and vice versa

To convert matrix coordinates for a given Nifti/Analyze-image into the image coordinates and vice versa, you need to load the transformation matrix of the image into the workspace:

vol = spm_vol('image.img') vol.mat % displays the transformation matrix 

% trasform from matrix/voxel coordinates to image coordinates (the fourth element has to be 1) vol.mat * [x y z 1]‘ % transform image coordinates (e.g. mni space) to matrix coordinates inv(vol.mat) * [x y z 1]‘ 

Code Martin Pyka on 28 May 2010

## Extent threshold

The “extent threshold” function deletes all clusters in a given contrast image that consist of less than k voxels. The corresponding matlab code can be found in spm_getSPM.m (line 674f). In case you would like to use this code manually for other imaging data, here is a matlab-function called extentThreshold that allows you to apply the extent threshold on a 3d volume of your choice.

The function can be used in the following way: if data is a 3d-matrix (of let’s say voxel values) and you want to display clusters with voxels that are greater than zero and with a cluster size of at least 20, write:

indices = find(data>0); newdata = extentThreshold(data, indices, 20); 

newdata includes only the elements of data that are greater than zero and that belong to a cluster with at least 20 other elements exceeding this threshold.

Code Martin Pyka on 18 May 2010

## Display the frequency domain of a signal

SPM has a nice feature to plot the frequency domain of a signal. You can use it, for example, when you click on “Review” and - after you selected an SPM.mat file - on “Design” - “Explore” - “Session 1″ - Regressor. The corresponding function can be found in spm_fMRI_design_show.m in line 90ff.

To call this plot directly from the Matlab console e.g. in order to visualize the frequency domain of extracted VOIs, I copied the code into a separate m-file function, which looks like this:

function fft_gui(signal, rt, HPF) gX = abs(fft(signal)).^2; gX = gX*diag(1./sum(gX)); q = size(gX,1); Hz = [0:(q - 1)]/(q*rt); q = 2:fix(q/2); plot(Hz(q),gX(q,:)) patch([0 1 1 0]/HPF,[0 0 1 1]*max(max(gX)),[1 1 1]*.9); xlabel(’Frequency (Hz)’) ylabel(’relative spectral density’) title(['Frequency domain',sprintf('\n'), ' {\bf',num2str(HPF),'}', ... ' second High-pass filter'],’Interpreter’,'Tex’); grid on axis tight

To display the frequency domain of a signal, just call this function with the appropriate RT and high-pass filter value, e.g.:

signal = (sin((1:100)*0.8)+sin((1:100)*1.4) + sin((1:100)*2))'; fft_gui(signal, 3, 128)

Tips Martin Pyka on 23 Mar 2009

## Displaying Results in SPM

Here are some useful tips for displaying results in SPM:

Tips Martin Pyka on 26 Aug 2008

## Change the color theme of SPM

If you use several SPM versions on your system at the same time (e.g. a standard installation and an experimental version of your SPM) it is handy to have a simple visual information about the SPM version you are currently viewing at. You can change the color theme of your SPM installation (the color of the list-component and the buttons, etc.) at the end of the file spm_defaults.m. The variables are
 defaults.ui.colour1 = [0.8 0.8 1.0]; defaults.ui.colour2 = [1.0 1.0 0.8]; defaults.ui.colour3 = [0.0 0.0 0.0];

Tips Martin Pyka on 20 Aug 2008

## Accessing the design matrix

If you need the design matrix of your first level analysis for other applications you can print it out or write it out into a file with Matlab code. All you have to do is: load the SPM.mat file into the workspace and access the right variable.

> load('SPM.mat'); > SPM.xX.X % this is the designmatrix > SPM.xX.X(:,1) % this is the first column of your design matrix > SPM.xX.X(2,:) % this is the second row of your design matrix

You can use the commands fwrite or fprintf for writing these data to a file.

> help spm_fMRI_design

Tips Martin Pyka on 19 Aug 2008

 > load('your_job_file.mat'); > spm_jobman('run', jobs); !shutdown -s -f; 
 > spm_jobman('run', jobs); !shutdown -h -now;