Introduction to Matlab for Neuroimaging Luis Hernandez-Garcia Hernandez-Garcia, UM FMRI course
Goals Become familiar with Matlab Learn a few programming skills Learn how to make simple simulations of BOLD signals. Understand how FMRI data are stored and manipulated. See the “guts” of the General Linear Model Hernandez-Garcia, UM FMRI course
Why? Need to manipulate data at lower level Need easy, fast way to carry out lots of computations Matlab is quick and easy: Doesn’t require compilation, Direct access to variables during execution. Great debugging tools. Matlab has lots of built-in math functions. SPM is built on matlab -> easier to get under the hood and interact with SPM Hernandez-Garcia, UM FMRI course
About programming People in this class range the whole gamut of expertise Computers are not smart Frustration The learning curve Worth the effort Hernandez-Garcia, UM FMRI course
Module 1: Get acquainted with Matlab Hernandez-Garcia, UM FMRI course
So … Here’s Matlab! Hernandez-Garcia, UM FMRI course
Today’s Concepts The Path Variables and operations Scripts Functions Loops Conditional statements (IF … then ..) Hernandez-Garcia, UM FMRI course
The Lab Exercise Follow instructions in C:\fmri_lab\FMRICourse\LabAssignments\Lab1_Matlab\Matlab_T utorial_1.doc Copy and Paste between doc and Matlab. Make edits as instructed. Think about what you are seeing and ASK LOTS OF QUESTIONS. Read as much documentation along the way as you can. Sign the sheet as you leave What if I already know how to Matlab ? Hernandez-Garcia, UM FMRI course
Module 2: Single Pixel analysis in Matlab (General Linear Model) Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression Our data are a bunch of measurements of the variables x and y A linear model of these data: y = mx + b + noise (we can solve for m and b) If this model fits, then x and y are correlated. Hernandez-Garcia, UM FMRI course
y x Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression If m is “significant”, then we infer that the model is true. Significant means that m is big enough compared to the noise. “noise” is the residual signal after we remove the fitted signal. Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression Our data are a bunch of measurements of the variables x1 , x2 , x3 … and y A bigger linear model of these data: y = m1x1 + m2x2 + m3x3 +… + noise Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression In fMRI, y is a time course x1, x2, ..etc are also time courses Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression In the usual GLM analysis of FMRI data, all the x1, x2, … are not usually measured. Instead , we make an ideal model and hope it’s good enough. Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression Say it with matrices Y = X*M + e Mest = (X)-1*Y eest = Y – X*Mest Tscore(1) = Mest(1) /std. dev(eest(1)) Hernandez-Garcia, UM FMRI course
Today’s exercise Generate and explore temporal noise for FMRI data (e) Create a linear model for a BOLD time series using Matlab (X) Create a Realistic (but fake) BOLD signal (Y) Use regression to test whether the model fits the signal Hernandez-Garcia, UM FMRI course
Note for today Don’t use the GUI for setting the path. Instead do it from the command line addpath C:\fmri_Course\FMRI_lab\Lab2_Matlab\Mlib addpath C:\SPM12 If you don’t want to have to do this each time you start matlab, put these commands in startup.m
Module 3: FMRI data and Matlab Hernandez-Garcia, UM FMRI course
Today’s Concepts Data storage 3D and 4D matrices Index v. subscript Orthogonal views Correlation and functional connectivity. Hernandez-Garcia, UM FMRI course
Brain Imaging Data is a 3D movie Hernandez-Garcia, UM FMRI course
A single slice: 2D matrix Hernandez-Garcia, UM FMRI course
Multiple slices: from 2D to 3D …. Same thing to make a 4D matrix Hernandez-Garcia, UM FMRI course
A 4D data set as a 2D matrix! Hernandez-Garcia, UM FMRI course
Image storage All the pixel values are stored sequentially. Headers: What information is needed to display an image? Data “proper” AVW and NIFTI formats Hernandez-Garcia, UM FMRI course
The Lab Exercise Read in NIFTI and Analyze format Understand data ordering Navigate and display the time series Do a “connectivity analysis” Use regression Use all the data as a single matrix Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression Our data are a bunch of measurements of the variables x and y A linear model of these data: y = mx + b + noise (we will solve for m and b) If this model is true, then x and y are correlated. Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression If m is “significant”, then we infer that the model is true. Significant means that m is big enough compared to the noise. Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression Say it with matrices Y = X*b + e best = (X)-1*Y eest = Y – X*best Tscore(1) = best(1) /eest(1) Hernandez-Garcia, UM FMRI course
Super Quick Review of Linear regression In Connectivity analysis: The MODEL for all pixels is the time course of the “seed pixel”. Hernandez-Garcia, UM FMRI course
Notes for today’s tutorial When setting the path: do not use the GUI. Instead put this in the command line addpath C:\fmri_lab\FMRICourse\Lab3_Matlab\Mlib addpath C:\SMP8 Hernandez-Garcia, UM FMRI course