Home
Neuroimaging Analysis
Introduction to Magnetic Resonance Imaging
try%3A%0A%20%20%20%20import%20micropip%0A%20%20%20%20await%20micropip.install(%5B'dartbrains-tools'%2C%20'numpy'%2C%20'plotly'%5D)%0Aexcept%20ImportError%3A%0A%20%20%20%20pass%0A_marimo_book_micropip_done%20%3D%20True
mo.md('%5Cn%20%20%20%20%23%20MR%20Physics%3A%20From%20Protons%20to%20Brain%20Images%5Cn%5Cn%20%20%20%20*Written%20by%20Luke%20Chang%20%26%20Ben%20Graul*%5Cn%5Cn%20%20%20%20How%20do%20MRI%20scanners%20work%3F%20And%20what%20signal%20are%20we%20actually%20measuring%3F%5Cn%20%20%20%20Understanding%20the%20physics%20underlying%20MRI%20is%20essential%20for%20interpreting%5Cn%20%20%20%20neuroimaging%20results%2C%20yet%20many%20people%20who%20use%20MRI%20don%5C't%20fully%20grasp%5Cn%20%20%20%20how%20it%20works%20--%20largely%20because%20MR%20physics%20can%20be%20unintuitive.%5Cn%5Cn%20%20%20%20This%20course%20primarily%20focuses%20on%20Blood%20Oxygenated%20Level%20Dependent%20(BOLD)%20fMRI%20signals.%20Gaining%20a%20deep%20understanding%20of%20the%20MR%20physics%20and%20physiological%20basis%20for%20the%20BOLD%20fMRI%20signal%20is%20beyond%20the%20scope%20of%20this%20course%20and%20we%20refer%20the%20interested%20reader%20to%20the%20excellent%20%5BHuettel%2C%20Song%2C%20%26%20McCarthy%20(2004)%20Functional%20magnetic%20resonance%20imaging%20textbook%5D(https%3A%2F%2Fwww.amazon.com%2FFunctional-Magnetic-Resonance-Imaging-Huettel%2Fdp%2F0878936270%2Fref%3Dpd_sbs_14_1%2F144-9493364-1935804%3F_encoding%3DUTF8%26pd_rd_i%3D0878936270%26pd_rd_r%3Dac61b1df-17bf-47c5-8db5-25dfa36bcd16%26pd_rd_w%3DJ61zv%26pd_rd_wg%3Dd1O2i%26pf_rd_p%3D703f3758-d945-4136-8df6-a43d19d750d1%26pf_rd_r%3DPCEXDFT3TQQ4JW7FD8HF%26psc%3D1%26refRID%3DPCEXDFT3TQQ4JW7FD8HF)%20for%20a%20more%20in%20depth%20conceptual%20and%20quantitative%20overview.%5Cn%5Cn%20%20%20%20The%20goal%20of%20this%20tutorial%20is%20to%20build%20your%20intuition%20from%20the%20ground%5Cn%20%20%20%20up%2C%20starting%20with%20things%20you%20already%20know%20(magnets%20and%20compasses)%20and%5Cn%20%20%20%20working%20toward%20functional%20brain%20imaging.%20Along%20the%20way%2C%20you%5C'll%20interact%5Cn%20%20%20%20with%20simulations%20that%20let%20you%20**see**%20and%20**feel**%20how%20changing%20physical%5Cn%20%20%20%20parameters%20affects%20the%20signal.%5Cn%5Cn%20%20%20%20%3E%20**Note%20on%20simplifications%3A**%20We%5C'll%20use%20*classical*%20physics%20explanations%5Cn%20%20%20%20%3E%20throughout%2C%20following%20the%20approach%20advocated%20by%5Cn%20%20%20%20%3E%20%5BLars%20G.%20Hanson%5D(https%3A%2F%2Fwww.drcmr.dk%2Fbloch).%20While%20not%20quantum-mechanically%5Cn%20%20%20%20%3E%20complete%2C%20this%20classical%20picture%20provides%20strong%20intuitions%20that%20will%5Cn%20%20%20%20%3E%20serve%20you%20well.%20Where%20the%20full%20story%20differs%2C%20we%5C'll%20flag%20it%20in%5Cn%20%20%20%20%3E%20optional%20%22Deep%20Dive%22%20sections.%5Cn%5Cn%20%20%20%20This%20notebook%20covers%20three%20major%20topics%3A%5Cn%20%20%20%201.%20**Magnetism%20%26%20Resonance**%20%E2%80%94%20magnetic%20fields%2C%20proton%20alignment%2C%20precession%2C%20RF%20excitation%2C%20and%20the%20FID%20signal%5Cn%20%20%20%202.%20**Signal%20%26%20Contrast**%20%E2%80%94%20T%E2%82%81%2FT%E2%82%82%20relaxation%2C%20the%20Bloch%20equations%2C%20tissue%20contrast%2C%20and%20pulse%20sequences%5Cn%20%20%20%203.%20**Imaging%20%26%20fMRI**%20%E2%80%94%20gradients%2C%20spatial%20encoding%2C%20k-space%2C%20the%20BOLD%20signal%2C%20and%20EPI%5Cn%20%20%20%20')
import%20marimo%20as%20mo%0Aimport%20numpy%20as%20np%0Aimport%20plotly.graph_objects%20as%20go%0Afrom%20pathlib%20import%20Path%0Afrom%20plotly.subplots%20import%20make_subplots%0Afrom%20dartbrains_tools.mr_simulations%20import%20GAMMA_H%2C%20GAMMA%2C%20TISSUE_PROPERTIES%2C%20rotation_x%2C%20rotation_y%2C%20rotation_z%2C%20apply_rf_pulse%2C%20apply_relaxation%2C%20simulate_bloch%2C%20fid_signal%2C%20compute_spectrum%2C%20t1_recovery%2C%20t2_decay%2C%20spin_echo_signal%2C%20gradient_echo_signal%2C%20hrf%2C%20image_to_kspace%2C%20kspace_to_image%2C%20mask_kspace%2C%20plot_magnetization_3d%2C%20plot_signal_timeline%2C%20plot_contrast_bars%2C%20plot_pulse_sequence%2C%20plot_kspace_and_image%0Afrom%20dartbrains_tools.mr_widgets%20import%20CompassWidget%2C%20NetMagnetizationWidget%2C%20PrecessionWidget%2C%20SpinEnsembleWidget%2C%20EncodingWidget%2C%20KSpaceWidget%2C%20ConvolutionWidget%0A_ROOT%20%3D%20next((p%20for%20p%20in%20(Path.cwd()%2C%20*Path.cwd().resolve().parents)%20if%20(p%20%2F%20'book.yml').exists()))%0AIMG_DIR%20%3D%20_ROOT%20%2F%20'images'%20%2F%20'signal_generation'
mo.md('%5Cn%20%20%20%20')
mo.md(%22%5Cn%20%20%20%20Let's%20first%20start%20with%20a%20short%20video%20on%20the%20basics%20of%20MR%20physics%20by%20Martin%20Lindquist.%5Cn%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%20Part%201%3A%20Magnetism%20%26%20Resonance%5Cn%5Cn%20%20%20%20---%5Cn%20%20%20%20%22)
VIDEO
mo.Html('%5Cn%20%20%20%20%20%20%3Ciframe%5Cn%20%20%20%20%20%20%20%20%20%20width%3D%22560%22%20height%3D%22315%22%5Cn%20%20%20%20%20%20%20%20%20%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FXsDXxgjEJVY%22%5Cn%20%20%20%20%20%20%20%20%20%20frameborder%3D%220%22%20allowfullscreen%3E%5Cn%20%20%20%20%20%20%3C%2Fiframe%3E%5Cn%20%20%20%20%20%20')
mo.md(%22%5Cn%20%20%20%20%23%23%201.%20What%20is%20a%20Magnetic%20Field%3F%5Cn%5Cn%20%20%20%20You've%20used%20a%20compass%20before%20--%20a%20tiny%20magnetized%20needle%20that%20aligns%5Cn%20%20%20%20with%20the%20Earth's%20magnetic%20field%20to%20point%20north.%20This%20simple%20device%5Cn%20%20%20%20illustrates%20the%20core%20idea%20behind%20MRI%3A%20**magnetic%20objects%20tend%20to%20align%5Cn%20%20%20%20with%20an%20applied%20magnetic%20field.**%5Cn%5Cn%20%20%20%20The%20Earth's%20magnetic%20field%20is%20weak%20--%20only%20about%2025-65%20*micro*Teslas%5Cn%20%20%20%20(%C2%B5T).%20An%20MRI%20scanner%20produces%20a%20field%20that%20is%20roughly%20**100%2C000%20times%5Cn%20%20%20%20stronger**%3A%20typically%201.5%20or%203%20Tesla%20(T)%2C%20with%20research%20scanners%5Cn%20%20%20%20going%20up%20to%207T%20or%20beyond.%5Cn%5Cn%20%20%20%20Let's%20start%20with%20a%20simulation%20inspired%20by%20the%5Cn%20%20%20%20%5BDRCMR%20Compass%20MR%20Simulator%5D(https%3A%2F%2Fwww.drcmr.dk%2FCompassMR%2F).%5Cn%20%20%20%20Use%20the%20slider%20below%20to%20change%20the%20strength%20of%20the%20external%20magnetic%5Cn%20%20%20%20field%20(%5C%5C(B_0%5C%5C))%20and%20watch%20how%20a%20compass%20needle%20responds.%5Cn%20%20%20%20%22)
b0_compass_slider%20%3D%20mo.ui.slider(start%3D0.0%2C%20stop%3D5.0%2C%20step%3D0.1%2C%20value%3D3.0%2C%20label%3D'B%E2%82%80%20field%20strength%20(mT)'%2C%20full_width%3DTrue)
_widget%20%3D%20CompassWidget(b0%3Dfloat(b0_compass_slider.value))%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5B_wrapped%5D)
mo.md(%22%5Cn%20%20%20%20**Key%20observations%3A**%5Cn%20%20%20%20-%20With%20no%20field%20(%5C%5C(B_0%20%3D%200%5C%5C))%2C%20the%20needle%20just%20sits%20wherever%20it%20is%20--%20no%20preferred%20direction.%5Cn%20%20%20%20-%20As%20you%20increase%20%5C%5C(B_0%5C%5C)%2C%20the%20needle%20oscillates%20back%20toward%20alignment%20**faster**.%5Cn%20%20%20%20-%20The%20**frequency**%20of%20oscillation%20increases%20with%20field%20strength.%5Cn%20%20%20%20-%20The%20oscillation%20is%20detected%20by%20a%20nearby%20coil%20as%20a%20**signal**%20that%20decays%20over%20time.%5Cn%5Cn%20%20%20%20These%20same%20principles%20apply%20inside%20an%20MRI%20scanner%2C%20except%20instead%20of%20compass%5Cn%20%20%20%20needles%2C%20we're%20working%20with%20hydrogen%20nuclei%20--%20tiny%20magnets%20inside%20your%20body.%5Cn%20%20%20%20%22)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%202.%20From%20Compass%20to%20Proton%5Cn%5Cn%20%20%20%20We%20don't%20have%20compass%20needles%20inside%20the%20body%2C%20but%20do%20have%20a%20large%20number%20of%20**hydrogen%20nuclei**%20(protons).%5Cn%20%20%20%20Hydrogen%20is%20the%20most%20abundant%20element%20in%20the%20body%20(it's%20in%20every%20water%5Cn%20%20%20%20molecule)%2C%20and%20each%20hydrogen%20nucleus%20acts%20like%20a%20tiny%20magnet%20because%20of%5Cn%20%20%20%20a%20quantum%20property%20called%20**spin**.%5Cn%5Cn%20%20%20%20In%20the%20absence%20of%20an%20external%20magnetic%20field%2C%20these%20tiny%20magnets%20point%5Cn%20%20%20%20in%20random%20directions%2C%20and%20their%20effects%20cancel%20out%20--%20there's%20no%20net%5Cn%20%20%20%20magnetization.%20But%20when%20we%20place%20them%20in%20a%20strong%20%5C%5C(B_0%5C%5C)%20field%2C%20a%5Cn%20%20%20%20slight%20majority%20align%20*with*%20the%20field%20rather%20than%20*against*%20it.%20This%5Cn%20%20%20%20tiny%20surplus%20creates%20a%20measurable%20**net%20magnetization**%20vector%2C%20called%5Cn%20%20%20%20%5C%5C(M_0%5C%5C)%2C%20that%20points%20along%20%5C%5C(B_0%5C%5C).%5Cn%5Cn%20%20%20%20Use%20the%20sliders%20below%20to%20see%20how%20random%20spins%20create%20a%20net%20magnetization%5Cn%20%20%20%20when%20a%20field%20is%20applied.%5Cn%20%20%20%20%22)
n_protons_slider%20%3D%20mo.ui.slider(start%3D10%2C%20stop%3D500%2C%20step%3D10%2C%20value%3D100%2C%20label%3D'Number%20of%20protons')%0Ab0_on_toggle%20%3D%20mo.ui.switch(label%3D'B%E2%82%80%20field%20ON'%2C%20value%3DFalse)
_widget%20%3D%20NetMagnetizationWidget(n_protons%3Dint(n_protons_slider.value)%2C%20b0_on%3Dbool(b0_on_toggle.value))%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5Bmo.hstack(%5Bn_protons_slider%2C%20b0_on_toggle%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_wrapped%2C%20mo.callout(mo.md('With%20the%20field%20**OFF**%2C%20spins%20point%20in%20random%20directions%20and%20jitter%20freely%20--%20the%20net%20magnetization%20(red%20arrow)%20is%20near%20zero.%20Toggle%20B%E2%82%80%20**ON**%20to%20watch%20the%20spins%20gradually%20align%2C%20and%20a%20net%20magnetization%20emerges%20along%20z.%20**Drag%20to%20rotate**%20the%203D%20view.')%2C%20kind%3D'info')%5D)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%203.%20Precession%20%26%20the%20Larmor%20Frequency%5Cn%5Cn%20%20%20%20When%20a%20spinning%20top%20is%20tilted%2C%20it%20doesn't%20just%20fall%20over%20--%20it%5Cn%20%20%20%20**precesses**%2C%20tracing%20a%20circle%20as%20it%20wobbles%20around%20the%20vertical%20axis.%5Cn%20%20%20%20Protons%20in%20a%20magnetic%20field%20do%20the%20same%20thing%3A%20their%20spin%20axes%20precess%5Cn%20%20%20%20around%20the%20direction%20of%20%5C%5C(B_0%5C%5C).%5Cn%5Cn%20%20%20%20The%20rate%20of%20precession%20is%20governed%20by%20the%20**Larmor%20equation**%3A%5Cn%5Cn%20%20%20%20%24%24%5C%5Comega_0%20%3D%20%5C%5Cgamma%20%5C%5Ccdot%20B_0%24%24%5Cn%5Cn%20%20%20%20where%3A%5Cn%20%20%20%20-%20%5C%5C(%5C%5Comega_0%5C%5C)%20is%20the%20Larmor%20(precession)%20frequency%5Cn%20%20%20%20-%20%5C%5C(%5C%5Cgamma%5C%5C)%20is%20the%20**gyromagnetic%20ratio**%20--%20a%20constant%20unique%20to%20each%20nucleus%5Cn%20%20%20%20-%20%5C%5C(B_0%5C%5C)%20is%20the%20magnetic%20field%20strength%5Cn%5Cn%20%20%20%20For%20hydrogen%20protons%2C%20%5C%5C(%5C%5Cgamma%20%3D%2042.576%5C%5C)%20MHz%2FT.%20This%20means%20at%203T%2C%5Cn%20%20%20%20protons%20precess%20at%20about%20**127.7%20MHz**%20--%20in%20the%20radiofrequency%20(RF)%5Cn%20%20%20%20range!%5Cn%5Cn%20%20%20%20Adjust%20the%20field%20strength%20below%20and%20see%20how%20the%20precession%20frequency%20changes.%5Cn%20%20%20%20%22)
b0_larmor_slider%20%3D%20mo.ui.slider(start%3D0.5%2C%20stop%3D7.0%2C%20step%3D0.1%2C%20value%3D3.0%2C%20label%3D'B%E2%82%80%20(Tesla)'%2C%20full_width%3DTrue)
_b0%20%3D%20b0_larmor_slider.value%0A_larmor_freq%20%3D%20GAMMA_H%20*%20_b0%0A_widget%20%3D%20PrecessionWidget(b0%3D_b0%2C%20flip_angle%3D30.0%2C%20show_relaxation%3DFalse)%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5Bb0_larmor_slider%2C%20_wrapped%5D)
Larmor frequencies of different nuclei at this field strength:
Nucleus
γ (MHz/T)
Larmor freq at 3.0T
1H
42.576
127.73 MHz
13C
10.708
32.12 MHz
23Na
11.262
33.79 MHz
31P
17.235
51.70 MHz
_b0%20%3D%20b0_larmor_slider.value%0A_larmor_freq%20%3D%20GAMMA_H%20*%20_b0%0Amo.vstack(%5Bmo.callout(mo.md(f'At%20**B%E2%82%80%20%3D%20%7B_b0%3A.1f%7D%20T**%2C%20the%20Larmor%20frequency%20for%20hydrogen%20is%20**%7B_larmor_freq%3A.1f%7D%20MHz**%20(%7B_larmor_freq%20%2F%201000.0%3A.4f%7D%20GHz).%20This%20is%20in%20the%20**radiofrequency**%20range%20--%20the%20same%20part%20of%20the%20electromagnetic%20spectrum%20used%20by%20FM%20radio!%5Cn%5Cn**Drag%20to%20rotate**%20the%203D%20view.%20The%20signal%20traces%20on%20the%20right%20show%20%7CMxy%7C%20(red)%20and%20Mz%20(teal)%20in%20real%20time.')%2C%20kind%3D'success')%2C%20mo.md('**Larmor%20frequencies%20of%20different%20nuclei%20at%20this%20field%20strength%3A**')%2C%20mo.md('%7C%20Nucleus%20%7C%20%CE%B3%20(MHz%2FT)%20%7C%20Larmor%20freq%20at%20'%20%2B%20f'%7B_b0%3A.1f%7DT%20%7C%5Cn%7C---------%7C-----------%7C----------%7C%5Cn'%20%2B%20'%5Cn'.join((f'%7C%20%7Bname%7D%20%7C%20%7Bratio%3A.3f%7D%20%7C%20%7Bratio%20*%20_b0%3A.2f%7D%20MHz%20%7C'%20for%20name%2C%20ratio%20in%20GAMMA.items())))%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%204.%20RF%20Excitation%20%26%20Resonance%5Cn%5Cn%20%20%20%20In%20an%20MRI%20machine%2C%20%24B_0%24%20is%20the%20strong%2C%20static%20magnetic%20field%20that%20runs%20along%20the%20bore%20of%20the%20scanner%20(the%20**longitudinal%20plane**%20or%20z-axis).%20It%20aligns%20hydrogen%20protons%20in%20your%20body%20roughly%20parallel%20to%20the%20field%2C%20creating%20a%20net%20magnetization%20%24M_0%24.%5Cn%20%20%20%20')
mo.image(str(IMG_DIR%20%2F%20'b0.png'))
mo.md('%5Cn%20%20%20%20Unfortunately%2C%20we%20can%5C't%20directly%20measure%20magnetization%5Cn%20%20%20%20along%20z%20--%20our%20receiver%20coils%20are%20only%20sensitive%20to%20magnetization%5Cn%20%20%20%20in%20the%20**transverse%20(xy)%20plane**.%5Cn%5Cn%20%20%20%20To%20get%20a%20signal%2C%20we%20need%20to%20**tip**%20the%20magnetization%20away%20from%20z.%5Cn%20%20%20%20We%20do%20this%20by%20applying%20a%20second%2C%20much%20weaker%20magnetic%20field%20called%5Cn%20%20%20%20%5C%5C(B_1%5C%5C)%2C%20oriented%20perpendicular%20to%20%5C%5C(B_0%5C%5C)%2C%20and%20oscillating%20at%20the%5Cn%20%20%20%20**Larmor%20frequency**.%20This%20is%20the%20radiofrequency%20(RF)%20pulse.%5Cn%5Cn%20%20%20%20Think%20of%20pushing%20a%20child%20on%20a%20swing%3A%20if%20you%20push%20at%20the%20swing%5C's%5Cn%20%20%20%20natural%20frequency%2C%20each%20push%20adds%20energy%20and%20the%20swing%20goes%20higher.%5Cn%20%20%20%20Push%20at%20the%20wrong%20frequency%2C%20and%20nothing%20much%20happens.%20This%20is%5Cn%20%20%20%20**resonance**%20--%20and%20it%5C's%20the%20%22R%22%20in%20MRI.%5Cn%5Cn%20%20%20%20The%20angle%20by%20which%20the%20magnetization%20is%20tipped%20is%20called%20the%20**flip%5Cn%20%20%20%20angle**%20(%5C%5C(%5C%5Calpha%5C%5C)).%20A%2090%C2%B0%20pulse%20tips%20%5C%5C(M%5C%5C)%20entirely%20into%20the%5Cn%20%20%20%20xy-plane.%20A%20180%C2%B0%20pulse%20inverts%20it.%5Cn%5Cn%20%20%20%20Try%20adjusting%20the%20flip%20angle%20and%20the%20B1%20frequency%20below.%5Cn%20%20%20%20')
flip_angle_slider%20%3D%20mo.ui.slider(start%3D0%2C%20stop%3D180%2C%20step%3D5%2C%20value%3D90%2C%20label%3D'Flip%20angle%20(degrees)'%2C%20full_width%3DTrue)
Transverse magnetization |Mxy| = 1.00 (this is our detectable signal strength)
Longitudinal magnetization Mz = 0.00
_flip%20%3D%20flip_angle_slider.value%0A_widget%20%3D%20PrecessionWidget(b0%3D3.0%2C%20flip_angle%3Dfloat(_flip)%2C%20show_relaxation%3DFalse)%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0A_mxy%20%3D%20abs(round(float(__import__('math').sin(__import__('math').radians(_flip)))%2C%202))%0A_mz%20%3D%20round(float(__import__('math').cos(__import__('math').radians(_flip)))%2C%202)%0Amo.vstack(%5Bflip_angle_slider%2C%20_wrapped%2C%20mo.md(f'Transverse%20magnetization%20%7CMxy%7C%20%3D%20**%7B_mxy%3A.2f%7D**%20(this%20is%20our%20detectable%20signal%20strength)%5Cn%5CnLongitudinal%20magnetization%20Mz%20%3D%20**%7B_mz%3A.2f%7D**')%2C%20mo.callout(mo.md('**Try%20this%3A**%20Set%20the%20flip%20angle%20to%2090%C2%B0%20and%20watch%20the%20vector%20tip%20fully%20into%20the%20xy-plane%20--%20maximum%20signal!%20At%20180%C2%B0%2C%20the%20vector%20inverts%20completely.%20The%20signal%20traces%20on%20the%20right%20show%20how%20%7CMxy%7C%20and%20Mz%20change.%20**Drag%20to%20rotate**%20the%203D%20view.')%2C%20kind%3D'info')%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%205.%20The%20Signal%20We%20Measure%3A%20Free%20Induction%20Decay%5Cn%5Cn%20%20%20%20After%20the%20RF%20pulse%20tips%20the%20magnetization%20into%20the%20transverse%20plane%2C%5Cn%20%20%20%20the%20precessing%20%5C%5C(M_%7Bxy%7D%5C%5C)%20component%20induces%20a%20voltage%20in%20the%20receiver%5Cn%20%20%20%20coil%20--%20just%20like%20the%20oscillating%20compass%20needle%20produced%20a%20signal%5Cn%20%20%20%20in%20Section%201.%20This%20signal%20is%20called%20the%20**Free%20Induction%20Decay%20(FID)**.%5Cn%5Cn%20%20%20%20The%20FID%20has%20two%20key%20features%3A%5Cn%20%20%20%201.%20It%20**oscillates**%20at%20the%20Larmor%20frequency%20(the%20precessing%20magnetization)%5Cn%20%20%20%202.%20It%20**decays**%20over%20time%20as%20the%20transverse%20magnetization%20dephases%5Cn%20%20%20%20%20%20%20(characterized%20by%20the%20time%20constant%20%5C%5C(T_2%5E*%5C%5C))%5Cn%5Cn%20%20%20%20We%20can%20extract%20the%20frequency%20content%20of%20the%20FID%20using%20a%20**Fourier%5Cn%20%20%20%20Transform**%20(FFT)%20--%20the%20same%20mathematical%20tool%20introduced%20in%20the%5Cn%20%20%20%20Dartbrains%20Signal%20Processing%20chapter.%20The%20FFT%20reveals%20a%20peak%20at%20the%5Cn%20%20%20%20Larmor%20frequency%2C%20confirming%20that%20the%20signal%20came%20from%20precessing%20protons.%5Cn%20%20%20%20')
fid_flip_slider%20%3D%20mo.ui.slider(start%3D5%2C%20stop%3D90%2C%20step%3D5%2C%20value%3D90%2C%20label%3D'Flip%20angle%20(%C2%B0)')%0Afid_t2star_slider%20%3D%20mo.ui.slider(start%3D10%2C%20stop%3D200%2C%20step%3D10%2C%20value%3D50%2C%20label%3D'T%E2%82%82*%20(ms)')%0Afid_show_fft%20%3D%20mo.ui.switch(label%3D'Show%20frequency%20spectrum%20(FFT)'%2C%20value%3DFalse)
_flip%20%3D%20fid_flip_slider.value%0A_t2star%20%3D%20fid_t2star_slider.value%0A_show_fft%20%3D%20fid_show_fft.value%0A_dt%20%3D%200.1%0A_t%20%3D%20np.arange(0%2C%20500%2C%20_dt)%0A_f0%20%3D%200.05%0A_sig%20%3D%20fid_signal(_t%2C%20_t2star%2C%20f0%3D_f0%2C%20flip_angle_deg%3D_flip)%0A_fig%20%3D%20go.Figure()%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3Dnp.real(_sig)%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3D2)%2C%20name%3D'FID%20(real%20part)'))%0A_envelope%20%3D%20np.sin(np.radians(_flip))%20*%20np.exp(-_t%20%2F%20_t2star)%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3D_envelope%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'red'%2C%20width%3D1.5%2C%20dash%3D'dash')%2C%20name%3D'T%E2%82%82*%20envelope'))%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3D-_envelope%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'red'%2C%20width%3D1.5%2C%20dash%3D'dash')%2C%20showlegend%3DFalse))%0A_fig.update_layout(title%3Df'Free%20Induction%20Decay%20(flip%3D%7B_flip%7D%C2%B0%2C%20T%E2%82%82*%3D%7B_t2star%7D%20ms)'%2C%20xaxis_title%3D'Time%20(ms)'%2C%20yaxis_title%3D'Signal%20(a.u.)'%2C%20yaxis%3Ddict(range%3D%5B-1.1%2C%201.1%5D)%2C%20width%3D700%2C%20height%3D300%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40))%0A_elements%20%3D%20%5Bmo.hstack(%5Bfid_flip_slider%2C%20fid_t2star_slider%2C%20fid_show_fft%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_fig%5D%0Aif%20_show_fft%3A%0A%20%20%20%20_freqs%2C%20_mag%20%3D%20compute_spectrum(_sig%2C%20_dt)%0A%20%20%20%20_fft_fig%20%3D%20go.Figure()%0A%20%20%20%20_fft_fig.add_trace(go.Scatter(x%3D_freqs%2C%20y%3D_mag%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%2300CC96'%2C%20width%3D2)%2C%20name%3D'Magnitude%20spectrum'))%0A%20%20%20%20_fft_fig.update_layout(title%3D'Frequency%20Spectrum%20(FFT%20of%20FID)'%2C%20xaxis_title%3D'Frequency%20(kHz)'%2C%20yaxis_title%3D'Magnitude'%2C%20yaxis%3Ddict(range%3D%5B0%2C%200.55%5D)%2C%20width%3D700%2C%20height%3D300%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40))%0A%20%20%20%20_elements.append(_fft_fig)%0A%20%20%20%20_elements.append(mo.md(f'The%20FFT%20shows%20a%20peak%20at%20**%7B_f0%20*%201000%3A.0f%7D%20Hz**%20--%20the%20precession%20frequency%20of%20our%20protons.%20The%20width%20of%20the%20peak%20is%20inversely%20related%20to%20%5C%5C(T_2%5E*%5C%5C)%3A%20shorter%20%5C%5C(T_2%5E*%5C%5C)%20means%20faster%20decay%2C%20which%20means%20a%20broader%20spectral%20peak.'))%0A_elements.append(mo.callout(mo.md(%22**Key%20takeaways%3A**%5Cn-%20The%20FID%20amplitude%20depends%20on%20the%20flip%20angle%20(maximum%20at%2090%C2%B0)%5Cn-%20The%20decay%20rate%20is%20determined%20by%20T%E2%82%82*%20(we'll%20explore%20this%20next)%5Cn-%20The%20Fourier%20transform%20reveals%20the%20precession%20frequency%5Cn-%20**This%20is%20the%20fundamental%20signal%20that%20MRI%20is%20built%20upon!**%22)%2C%20kind%3D'success'))%0Amo.vstack(_elements)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%20Part%202%3A%20Signal%20%26%20Contrast%5Cn%5Cn%20%20%20%20We've%20learned%20how%20an%20RF%20pulse%20tips%20the%20net%20magnetization%20into%20the%5Cn%20%20%20%20transverse%20plane%2C%20producing%20a%20Free%20Induction%20Decay%20signal.%20But%5Cn%20%20%20%20**why%20does%20the%20signal%20decay%3F**%20And%20how%20do%20MRI%20scanners%20produce%20images%5Cn%20%20%20%20where%20gray%20matter%2C%20white%20matter%2C%20and%20CSF%20all%20look%20different%3F%5Cn%5Cn%20%20%20%20The%20answers%20lie%20in%20**relaxation**%20--%20the%20processes%20by%20which%20the%5Cn%20%20%20%20magnetization%20returns%20to%20equilibrium%20after%20excitation.%20Different%5Cn%20%20%20%20tissues%20relax%20at%20different%20rates%2C%20and%20MRI%20pulse%20sequences%20exploit%5Cn%20%20%20%20these%20differences%20to%20create%20**contrast**.%5Cn%20%20%20%20%22)
mo.md('%5Cn%20%20%20%20%23%23%206.%20T1%20Relaxation%5Cn%5Cn%20%20%20%20After%20a%2090%C2%B0%20RF%20pulse%20tips%20all%20the%20magnetization%20into%20the%20xy-plane%2C%5Cn%20%20%20%20the%20longitudinal%20component%20%5C%5C(M_z%5C%5C)%20is%20zero.%20Over%20time%2C%20%5C%5C(M_z%5C%5C)%5Cn%20%20%20%20**recovers**%20back%20to%20its%20equilibrium%20value%20%5C%5C(M_0%5C%5C)%20through%20a%20process%5Cn%20%20%20%20called%20**T1%20relaxation**%20(also%20known%20as%20spin-lattice%20relaxation).%5Cn%5Cn%20%20%20%20This%20recovery%20follows%20an%20exponential%20curve%3A%5Cn%5Cn%20%20%20%20%24%24M_z(t)%20%3D%20M_0%20%5C%5Cleft(1%20-%20e%5E%7B-t%2FT_1%7D%5C%5Cright)%24%24%5Cn%5Cn%20%20%20%20The%20**T1%20time%20constant**%20is%20the%20time%20it%20takes%20for%20%5C%5C(M_z%5C%5C)%20to%20recover%5Cn%20%20%20%20to%20about%2063%25%20of%20%5C%5C(M_0%5C%5C).%20Crucially%2C%20**different%20tissues%20have%20different%5Cn%20%20%20%20T1%20values**%3A%5Cn%20%20%20%20-%20**Fat**%20has%20a%20short%20T1%20(fast%20recovery)%20because%20fat%20molecules%20are%5Cn%20%20%20%20%20%20large%20and%20tumble%20slowly%2C%20efficiently%20transferring%20energy%20to%20the%20lattice%5Cn%20%20%20%20-%20**CSF**%20has%20a%20long%20T1%20(slow%20recovery)%20because%20water%20molecules%20are%5Cn%20%20%20%20%20%20small%20and%20tumble%20quickly%2C%20making%20energy%20transfer%20less%20efficient%5Cn%20%20%20%20-%20**Gray%20and%20white%20matter**%20fall%20in%20between%5Cn%20%20%20%20')
t1_slider%20%3D%20mo.ui.slider(start%3D100%2C%20stop%3D5000%2C%20step%3D100%2C%20value%3D1300%2C%20label%3D'T%E2%82%81%20(ms)'%2C%20full_width%3DTrue)%0At1_field_select%20%3D%20mo.ui.dropdown(options%3D%7B'1.5T'%3A%20'1.5T'%2C%20'3T'%3A%20'3T'%7D%2C%20value%3D'3T'%2C%20label%3D'Field%20strength')%0At1_show_tissues%20%3D%20mo.ui.switch(label%3D'Show%20tissue%20curves'%2C%20value%3DTrue)
_t1_custom%20%3D%20t1_slider.value%0A_field%20%3D%20t1_field_select.value%0A_show_tissues%20%3D%20t1_show_tissues.value%0A_t%20%3D%20np.linspace(0%2C%208000%2C%20500)%0A_fig%20%3D%20go.Figure()%0A_recovery%20%3D%20t1_recovery(_t%2C%20_t1_custom)%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3D_recovery%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3D3)%2C%20name%3Df'Custom%20T%E2%82%81%20%3D%20%7B_t1_custom%7D%20ms'))%0A_fig.add_hline(y%3D0.63%2C%20line_dash%3D'dot'%2C%20line_color%3D'gray'%2C%20annotation_text%3D'63%25%20recovery%20(t%20%3D%20T%E2%82%81)')%0Aif%20_show_tissues%3A%0A%20%20%20%20_tissue_colors%20%3D%20%7B'Gray%20Matter'%3A%20'%23808080'%2C%20'White%20Matter'%3A%20'%23C8A882'%2C%20'CSF'%3A%20'%234169E1'%2C%20'Fat'%3A%20'%23FFD700'%2C%20'Muscle'%3A%20'%23CD5C5C'%7D%0A%20%20%20%20for%20_tissue%2C%20_props%20in%20TISSUE_PROPERTIES%5B_field%5D.items()%3A%0A%20%20%20%20%20%20%20%20_r%20%3D%20t1_recovery(_t%2C%20_props%5B'T1'%5D)%0A%20%20%20%20%20%20%20%20_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3D_r%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D_tissue_colors.get(_tissue%2C%20'gray')%2C%20width%3D2%2C%20dash%3D'dash')%2C%20name%3Df%22%7B_tissue%7D%20(T%E2%82%81%3D%7B_props%5B'T1'%5D%7D%20ms)%22))%0A_fig.update_layout(title%3Df'T%E2%82%81%20Recovery%20at%20%7B_field%7D'%2C%20xaxis_title%3D'Time%20after%20excitation%20(ms)'%2C%20yaxis_title%3D'Mz%20%2F%20M%E2%82%80'%2C%20yaxis%3Ddict(range%3D%5B0%2C%201.05%5D)%2C%20width%3D750%2C%20height%3D400%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40))%0Amo.vstack(%5Bmo.hstack(%5Bt1_slider%2C%20t1_field_select%2C%20t1_show_tissues%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_fig%2C%20mo.callout(mo.md('Notice%20how%20**fat**%20(short%20T%E2%82%81)%20recovers%20quickly%20while%20**CSF**%20(long%20T%E2%82%81)%20takes%20much%20longer.%20Gray%20and%20white%20matter%20are%20in%20between%20but%20have%20*different*%20T%E2%82%81%20values%20--%20this%20difference%20is%20what%20creates%20**T%E2%82%81-weighted%20contrast**%20in%20MRI%20images.')%2C%20kind%3D'info')%5D)
T₁ relaxation describes the return of longitudinal magnetization
to equilibrium. The recovery follows the Bloch equation for ||(M_z||) :
||[\frac{dM_z}{dt} = \frac{M_0 - M_z}{T_1}||] with the solution (after a 90° excitation):
||[M_z(t) = M_0 \left(1 - e^{-t/T_1}\right)||] The physical mechanism involves energy exchange between the
excited spin system and the surrounding molecular lattice
(hence "spin-lattice" relaxation). The efficiency depends on
molecular tumbling rates:
Optimal T₁ relaxation occurs when the molecular tumbling
frequency matches the Larmor frequency
Small, fast-tumbling molecules (like free water) are
inefficient → long T₁
Large, slow-tumbling molecules (like fat) are more
efficient → short T₁
T₁ increases with field strength because the Larmor
frequency moves further from typical tumbling frequencies
mo.accordion(%7B'Deep%20Dive%3A%20The%20physics%20of%20T%E2%82%81%20relaxation'%3A%20mo.md('%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20T%E2%82%81%20relaxation%20describes%20the%20return%20of%20longitudinal%20magnetization%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20to%20equilibrium.%20The%20recovery%20follows%20the%20Bloch%20equation%20for%20%5C%5C(M_z%5C%5C)%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24%5C%5Cfrac%7BdM_z%7D%7Bdt%7D%20%3D%20%5C%5Cfrac%7BM_0%20-%20M_z%7D%7BT_1%7D%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20with%20the%20solution%20(after%20a%2090%C2%B0%20excitation)%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24M_z(t)%20%3D%20M_0%20%5C%5Cleft(1%20-%20e%5E%7B-t%2FT_1%7D%5C%5Cright)%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20physical%20mechanism%20involves%20energy%20exchange%20between%20the%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20excited%20spin%20system%20and%20the%20surrounding%20molecular%20lattice%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20(hence%20%22spin-lattice%22%20relaxation).%20The%20efficiency%20depends%20on%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20molecular%20tumbling%20rates%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20**Optimal%20T%E2%82%81%20relaxation**%20occurs%20when%20the%20molecular%20tumbling%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20frequency%20matches%20the%20Larmor%20frequency%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20**Small%2C%20fast-tumbling%20molecules**%20(like%20free%20water)%20are%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20inefficient%20%E2%86%92%20long%20T%E2%82%81%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20**Large%2C%20slow-tumbling%20molecules**%20(like%20fat)%20are%20more%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20efficient%20%E2%86%92%20short%20T%E2%82%81%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20T%E2%82%81%20**increases%20with%20field%20strength**%20because%20the%20Larmor%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20frequency%20moves%20further%20from%20typical%20tumbling%20frequencies%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20')%7D)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%207.%20T2%20Relaxation%5Cn%5Cn%20%20%20%20While%20%5C%5C(M_z%5C%5C)%20is%20recovering%20along%20the%20z-axis%2C%20the%20transverse%5Cn%20%20%20%20magnetization%20%5C%5C(M_%7Bxy%7D%5C%5C)%20is%20**decaying**%20in%20the%20xy-plane.%20This%20happens%5Cn%20%20%20%20because%20individual%20proton%20spins%20gradually%20lose%20phase%20coherence%20--%5Cn%20%20%20%20they%20precess%20at%20slightly%20different%20frequencies%20due%20to%20interactions%5Cn%20%20%20%20with%20neighboring%20spins.%20This%20is%20**T2%20relaxation**%20(spin-spin%20relaxation)%3A%5Cn%5Cn%20%20%20%20%24%24M_%7Bxy%7D(t)%20%3D%20M_%7Bxy%7D(0)%20%5C%5Ccdot%20e%5E%7B-t%2FT_2%7D%24%24%5Cn%5Cn%20%20%20%20In%20practice%2C%20additional%20dephasing%20from%20%5C%5C(B_0%5C%5C)%20field%20inhomogeneities%5Cn%20%20%20%20makes%20the%20signal%20decay%20even%20faster%2C%20characterized%20by%20%5C%5C(T_2%5E*%5C%5C)%3A%5Cn%5Cn%20%20%20%20%24%24%5C%5Cfrac%7B1%7D%7BT_2%5E*%7D%20%3D%20%5C%5Cfrac%7B1%7D%7BT_2%7D%20%2B%20%5C%5Cfrac%7B1%7D%7BT_2'%7D%24%24%5Cn%5Cn%20%20%20%20where%20%5C%5C(T_2'%5C%5C)%20represents%20dephasing%20from%20field%20inhomogeneities.%5Cn%20%20%20%20**T2%20is%20always%20shorter%20than%20or%20equal%20to%20T1**%20--%20the%20transverse%20signal%5Cn%20%20%20%20always%20decays%20before%20the%20longitudinal%20signal%20fully%20recovers.%5Cn%20%20%20%20%22)
t2_slider%20%3D%20mo.ui.slider(start%3D10%2C%20stop%3D300%2C%20step%3D10%2C%20value%3D80%2C%20label%3D'T%E2%82%82%20(ms)'%2C%20full_width%3DTrue)%0At2prime_slider%20%3D%20mo.ui.slider(start%3D10%2C%20stop%3D500%2C%20step%3D10%2C%20value%3D100%2C%20label%3D%22T%E2%82%82'%20(ms)%20%E2%80%94%20field%20inhomogeneity%22%2C%20full_width%3DTrue)%0At2_show_tissues%20%3D%20mo.ui.switch(label%3D'Show%20tissue%20curves'%2C%20value%3DTrue)%0At2_field_select%20%3D%20mo.ui.dropdown(options%3D%7B'1.5T'%3A%20'1.5T'%2C%20'3T'%3A%20'3T'%7D%2C%20value%3D'3T'%2C%20label%3D'Field%20strength')
T₂ = 44 ms * (always shorter than T₂ = 80 ms due to field inhomogeneities)
_t2_custom%20%3D%20t2_slider.value%0A_t2prime%20%3D%20t2prime_slider.value%0A_field%20%3D%20t2_field_select.value%0A_t2star%20%3D%201.0%20%2F%20(1.0%20%2F%20_t2_custom%20%2B%201.0%20%2F%20_t2prime)%0A_t%20%3D%20np.linspace(0%2C%20500%2C%20500)%0A_fig%20%3D%20go.Figure()%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3Dt2_decay(_t%2C%20_t2_custom)%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3D3)%2C%20name%3Df'T%E2%82%82%20%3D%20%7B_t2_custom%7D%20ms'))%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3Dt2_decay(_t%2C%20_t2star)%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23EF553B'%2C%20width%3D3%2C%20dash%3D'dash')%2C%20name%3Df'T%E2%82%82*%20%3D%20%7B_t2star%3A.0f%7D%20ms'))%0A_fig.add_hline(y%3D0.37%2C%20line_dash%3D'dot'%2C%20line_color%3D'gray'%2C%20annotation_text%3D'37%25%20remaining%20(t%20%3D%20T%E2%82%82)')%0Aif%20t2_show_tissues.value%3A%0A%20%20%20%20_tissue_colors%20%3D%20%7B'Gray%20Matter'%3A%20'%23808080'%2C%20'White%20Matter'%3A%20'%23C8A882'%2C%20'CSF'%3A%20'%234169E1'%2C%20'Fat'%3A%20'%23FFD700'%2C%20'Muscle'%3A%20'%23CD5C5C'%7D%0A%20%20%20%20for%20_tissue%2C%20_props%20in%20TISSUE_PROPERTIES%5B_field%5D.items()%3A%0A%20%20%20%20%20%20%20%20_d%20%3D%20t2_decay(_t%2C%20_props%5B'T2'%5D)%0A%20%20%20%20%20%20%20%20_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3D_d%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D_tissue_colors.get(_tissue%2C%20'gray')%2C%20width%3D2%2C%20dash%3D'dot')%2C%20name%3Df%22%7B_tissue%7D%20(T%E2%82%82%3D%7B_props%5B'T2'%5D%7D%20ms)%22))%0A_fig.update_layout(title%3Df'T%E2%82%82%20and%20T%E2%82%82*%20Decay%20at%20%7B_field%7D'%2C%20xaxis_title%3D'Time%20after%20excitation%20(ms)'%2C%20yaxis_title%3D'Mxy%20%2F%20Mxy(0)'%2C%20yaxis%3Ddict(range%3D%5B0%2C%201.05%5D)%2C%20width%3D750%2C%20height%3D400%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40))%0Amo.vstack(%5Bmo.vstack(%5Bmo.hstack(%5Bt2_slider%2C%20t2prime_slider%5D%2C%20gap%3D2)%2C%20mo.hstack(%5Bt2_field_select%2C%20t2_show_tissues%5D%2C%20justify%3D'start'%2C%20gap%3D2)%5D)%2C%20_fig%2C%20mo.md(f'T%E2%82%82*%20%3D%20**%7B_t2star%3A.0f%7D%20ms**%20(always%20shorter%20than%20T%E2%82%82%20%3D%20%7B_t2_custom%7D%20ms%20due%20to%20field%20inhomogeneities)')%2C%20mo.callout(mo.md(%22**T%E2%82%82%20vs%20T%E2%82%82*%3A**%20T%E2%82%82%20is%20an%20intrinsic%20tissue%20property%20(spin-spin%20interactions).%20T%E2%82%82*%20includes%20*additional*%20dephasing%20from%20magnetic%20field%20non-uniformities.%20Spin%20echo%20sequences%20can%20recover%20the%20T%E2%82%82'%20component%20(getting%20back%20to%20'true'%20T%E2%82%82)%2C%20but%20gradient%20echo%20sequences%20are%20sensitive%20to%20T%E2%82%82*.%20This%20distinction%20will%20become%20important%20for%20fMRI%20later%20in%20this%20notebook!%22)%2C%20kind%3D'warn')%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%208.%20T1%20and%20T2%20Together%3A%20The%20Full%20Picture%5Cn%5Cn%20%20%20%20After%20an%20RF%20excitation%20pulse%2C%20**both%20relaxation%20processes%20happen%5Cn%20%20%20%20simultaneously**%3A%20%5C%5C(M_z%5C%5C)%20recovers%20(T1)%20while%20%5C%5C(M_%7Bxy%7D%5C%5C)%20decays%20(T2).%5Cn%20%20%20%20The%20combined%20motion%20of%20the%20magnetization%20vector%20traces%20a%20**spiral**%5Cn%20%20%20%20path%20as%20it%20precesses%2C%20dephases%20in%20the%20transverse%20plane%2C%20and%20recovers%5Cn%20%20%20%20along%20the%20longitudinal%20axis.%5Cn%5Cn%20%20%20%20This%20is%20the%20complete%20Bloch%20equation%20picture.%20The%20visualization%20below%5Cn%20%20%20%20shows%20the%203D%20trajectory%20of%20the%20magnetization%20vector%20after%20a%2090%C2%B0%20pulse.%5Cn%20%20%20%20')
bloch_t1_slider%20%3D%20mo.ui.slider(start%3D200%2C%20stop%3D4000%2C%20step%3D100%2C%20value%3D1300%2C%20label%3D'T%E2%82%81%20(ms)')%0Abloch_t2_slider%20%3D%20mo.ui.slider(start%3D10%2C%20stop%3D300%2C%20step%3D10%2C%20value%3D80%2C%20label%3D'T%E2%82%82%20(ms)')%0Abloch_b0_slider%20%3D%20mo.ui.slider(start%3D0.5%2C%20stop%3D7.0%2C%20step%3D0.5%2C%20value%3D3.0%2C%20label%3D'B%E2%82%80%20(T)')
_t1%20%3D%20bloch_t1_slider.value%0A_t2%20%3D%20bloch_t2_slider.value%0A_b0%20%3D%20bloch_b0_slider.value%0A_widget%20%3D%20PrecessionWidget(b0%3Dfloat(_b0)%2C%20flip_angle%3D90.0%2C%20t1%3Dfloat(_t1)%2C%20t2%3Dfloat(_t2)%2C%20show_relaxation%3DTrue)%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5Bmo.hstack(%5Bbloch_t1_slider%2C%20bloch_t2_slider%2C%20bloch_b0_slider%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_wrapped%2C%20mo.callout(mo.md('**The%20spiral%20tells%20the%20whole%20story%3A**%20The%20magnetization%20simultaneously%20precesses%20(circles%20in%20xy)%2C%20dephases%20(%7CMxy%7C%20decays%20via%20T%E2%82%82)%2C%20and%20recovers%20(Mz%20returns%20to%20equilibrium%20via%20T%E2%82%81).%20Try%20making%20T%E2%82%82%20very%20short%20--%20the%20signal%20collapses%20quickly.%20Make%20T%E2%82%81%20very%20short%20--%20Mz%20snaps%20back%20fast.%5Cn%5CnThe%20signal%20traces%20on%20the%20right%20show%20%7CMxy%7C%20(red)%20and%20Mz%20(teal)%20in%20real%20time.%20**Drag%20to%20rotate**%20the%203D%20view.')%2C%20kind%3D'success')%5D)
The Bloch equations describe the time evolution of the
magnetization vector ||(\vec{M} = (M_x, M_y, M_z)||) in a
magnetic field:
||[\frac{dM_x}{dt} = \gamma (\vec{M} \times \vec{B})_x - \frac{M_x}{T_2}||] ||[\frac{dM_y}{dt} = \gamma (\vec{M} \times \vec{B})_y - \frac{M_y}{T_2}||] ||[\frac{dM_z}{dt} = \gamma (\vec{M} \times \vec{B})_z - \frac{M_z - M_0}{T_1}||] The cross-product term describes precession, while the decay
terms describe relaxation. In matrix form, for a single time
step ||(\Delta t||) with only ||(B_0||) along z:
Precession : Rotate ||(M||) about z by angle ||(\Delta\phi = \gamma B_0 \Delta t||)
T2 decay : Multiply ||(M_x||) and ||(M_y||) by ||(e^{-\Delta t / T_2}||)
T1 recovery : Update ||(M_z \rightarrow M_z \cdot e^{-\Delta t / T_1} + M_0 (1 - e^{-\Delta t / T_1})||)
This is exactly how our simulation module implements the Bloch
equations -- using rotation matrices for precession and
exponential factors for relaxation.
mo.accordion(%7B'Deep%20Dive%3A%20The%20complete%20Bloch%20equations'%3A%20mo.md('%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20Bloch%20equations%20describe%20the%20time%20evolution%20of%20the%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20magnetization%20vector%20%5C%5C(%5C%5Cvec%7BM%7D%20%3D%20(M_x%2C%20M_y%2C%20M_z)%5C%5C)%20in%20a%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20magnetic%20field%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24%5C%5Cfrac%7BdM_x%7D%7Bdt%7D%20%3D%20%5C%5Cgamma%20(%5C%5Cvec%7BM%7D%20%5C%5Ctimes%20%5C%5Cvec%7BB%7D)_x%20-%20%5C%5Cfrac%7BM_x%7D%7BT_2%7D%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24%5C%5Cfrac%7BdM_y%7D%7Bdt%7D%20%3D%20%5C%5Cgamma%20(%5C%5Cvec%7BM%7D%20%5C%5Ctimes%20%5C%5Cvec%7BB%7D)_y%20-%20%5C%5Cfrac%7BM_y%7D%7BT_2%7D%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24%5C%5Cfrac%7BdM_z%7D%7Bdt%7D%20%3D%20%5C%5Cgamma%20(%5C%5Cvec%7BM%7D%20%5C%5Ctimes%20%5C%5Cvec%7BB%7D)_z%20-%20%5C%5Cfrac%7BM_z%20-%20M_0%7D%7BT_1%7D%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20cross-product%20term%20describes%20precession%2C%20while%20the%20decay%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20terms%20describe%20relaxation.%20In%20matrix%20form%2C%20for%20a%20single%20time%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20step%20%5C%5C(%5C%5CDelta%20t%5C%5C)%20with%20only%20%5C%5C(B_0%5C%5C)%20along%20z%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201.%20**Precession**%3A%20Rotate%20%5C%5C(M%5C%5C)%20about%20z%20by%20angle%20%5C%5C(%5C%5CDelta%5C%5Cphi%20%3D%20%5C%5Cgamma%20B_0%20%5C%5CDelta%20t%5C%5C)%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%202.%20**T2%20decay**%3A%20Multiply%20%5C%5C(M_x%5C%5C)%20and%20%5C%5C(M_y%5C%5C)%20by%20%5C%5C(e%5E%7B-%5C%5CDelta%20t%20%2F%20T_2%7D%5C%5C)%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%203.%20**T1%20recovery**%3A%20Update%20%5C%5C(M_z%20%5C%5Crightarrow%20M_z%20%5C%5Ccdot%20e%5E%7B-%5C%5CDelta%20t%20%2F%20T_1%7D%20%2B%20M_0%20(1%20-%20e%5E%7B-%5C%5CDelta%20t%20%2F%20T_1%7D)%5C%5C)%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20This%20is%20exactly%20how%20our%20simulation%20module%20implements%20the%20Bloch%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20equations%20--%20using%20rotation%20matrices%20for%20precession%20and%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20exponential%20factors%20for%20relaxation.%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20')%7D)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%209.%20Tissue%20Contrast%3A%20How%20TE%20and%20TR%20Create%20Different%20Images%5Cn%5Cn%20%20%20%20This%20is%20where%20MRI%20gets%20its%20remarkable%20soft-tissue%20contrast.%20By%20choosing%5Cn%20%20%20%20when%20we%20**repeat**%20the%20excitation%20pulse%20(%5C%5C(TR%5C%5C)%20%3D%20Repetition%20Time)%20and%5Cn%20%20%20%20when%20we%20**read**%20the%20signal%20(%5C%5C(TE%5C%5C)%20%3D%20Echo%20Time)%2C%20we%20can%20make%20the%20image%5Cn%20%20%20%20sensitive%20to%20different%20tissue%20properties%3A%5Cn%5Cn%20%20%20%20%7C%20Weighting%20%7C%20TR%20%7C%20TE%20%7C%20Sensitive%20to%20%7C%5Cn%20%20%20%20%7C-----------%7C----%7C----%7C-------------%7C%5Cn%20%20%20%20%7C%20**T1-weighted**%20%7C%20Short%20(~500ms)%20%7C%20Short%20(~10ms)%20%7C%20T1%20differences%20(anatomy)%20%7C%5Cn%20%20%20%20%7C%20**T2-weighted**%20%7C%20Long%20(~3000ms)%20%7C%20Long%20(~80ms)%20%7C%20T2%20differences%20(pathology)%20%7C%5Cn%20%20%20%20%7C%20**PD-weighted**%20%7C%20Long%20(~3000ms)%20%7C%20Short%20(~10ms)%20%7C%20Proton%20density%20%7C%5Cn%5Cn%20%20%20%20The%20spin%20echo%20signal%20equation%20combines%20both%20relaxation%20effects%3A%5Cn%5Cn%20%20%20%20%24%24S%20%3D%20PD%20%5C%5Ccdot%20(1%20-%20e%5E%7B-TR%2FT_1%7D)%20%5C%5Ccdot%20e%5E%7B-TE%2FT_2%7D%24%24%5Cn%5Cn%20%20%20%20The%20first%20term%20(%5C%5C(1%20-%20e%5E%7B-TR%2FT_1%7D%5C%5C))%20is%20T1-weighting%3A%20short%20TR%20means%5Cn%20%20%20%20tissues%20haven't%20fully%20recovered%2C%20so%20T1%20differences%20matter.%20The%20second%5Cn%20%20%20%20term%20(%5C%5C(e%5E%7B-TE%2FT_2%7D%5C%5C))%20is%20T2-weighting%3A%20long%20TE%20means%20more%20T2%20decay%5Cn%20%20%20%20has%20occurred%2C%20so%20T2%20differences%20matter.%5Cn%5Cn%20%20%20%20**This%20is%20the%20most%20important%20interactive%20plot%20in%20this%20notebook.**%20Use%20the%5Cn%20%20%20%20sliders%20below%20to%20explore%20how%20TE%20and%20TR%20change%20the%20contrast%20between%20tissues.%5Cn%20%20%20%20%22)
te_slider%20%3D%20mo.ui.slider(start%3D5%2C%20stop%3D200%2C%20step%3D5%2C%20value%3D10%2C%20label%3D'TE%20(ms)'%2C%20full_width%3DTrue)%0Atr_slider%20%3D%20mo.ui.slider(start%3D100%2C%20stop%3D6000%2C%20step%3D100%2C%20value%3D500%2C%20label%3D'TR%20(ms)'%2C%20full_width%3DTrue)%0Acontrast_field%20%3D%20mo.ui.dropdown(options%3D%7B'1.5T'%3A%20'1.5T'%2C%20'3T'%3A%20'3T'%7D%2C%20value%3D'3T'%2C%20label%3D'Field%20strength')
_te%20%3D%20te_slider.value%0A_tr%20%3D%20tr_slider.value%0A_field%20%3D%20contrast_field.value%0A_tissues%20%3D%20TISSUE_PROPERTIES%5B_field%5D%0A_tissue_names%20%3D%20list(_tissues.keys())%0A_signals%20%3D%20%5B%5D%0Afor%20_name%20in%20_tissue_names%3A%0A%20%20%20%20_p%20%3D%20_tissues%5B_name%5D%0A%20%20%20%20_s%20%3D%20spin_echo_signal(_te%2C%20_tr%2C%20_p%5B'T1'%5D%2C%20_p%5B'T2'%5D%2C%20_p%5B'PD'%5D)%0A%20%20%20%20_signals.append(_s)%0Aif%20_tr%20%3C%20800%20and%20_te%20%3C%2030%3A%0A%20%20%20%20_weighting%20%3D%20'T%E2%82%81-weighted'%0Aelif%20_tr%20%3E%202000%20and%20_te%20%3E%2060%3A%0A%20%20%20%20_weighting%20%3D%20'T%E2%82%82-weighted'%0Aelif%20_tr%20%3E%202000%20and%20_te%20%3C%2030%3A%0A%20%20%20%20_weighting%20%3D%20'PD-weighted'%0Aelse%3A%0A%20%20%20%20_weighting%20%3D%20'Mixed%20weighting'%0A_bar_fig%20%3D%20plot_contrast_bars(_tissue_names%2C%20_signals%2C%20title%3Df'%7B_weighting%7D')%0A_bar_fig.update_layout(width%3D300%2C%20height%3D300%2C%20margin%3Ddict(l%3D40%2C%20r%3D5%2C%20t%3D30%2C%20b%3D60)%2C%20xaxis_tickangle%3D-35%2C%20xaxis_tickfont%3Ddict(size%3D9))%0A_t_t1%20%3D%20np.linspace(0%2C%206000%2C%20500)%0A_t_t2%20%3D%20np.linspace(0%2C%20300%2C%20500)%0A_tissue_colors%20%3D%20%7B'Gray%20Matter'%3A%20'%23808080'%2C%20'White%20Matter'%3A%20'%23C8A882'%2C%20'CSF'%3A%20'%234169E1'%2C%20'Fat'%3A%20'%23FFD700'%2C%20'Muscle'%3A%20'%23CD5C5C'%7D%0A_t1_fig%20%3D%20go.Figure()%0Afor%20_name%20in%20_tissue_names%3A%0A%20%20%20%20_p%20%3D%20_tissues%5B_name%5D%0A%20%20%20%20_color%20%3D%20_tissue_colors.get(_name%2C%20'gray')%0A%20%20%20%20_t1_fig.add_trace(go.Scatter(x%3D_t_t1%2C%20y%3Dt1_recovery(_t_t1%2C%20_p%5B'T1'%5D%2C%20_p%5B'PD'%5D)%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D_color%2C%20width%3D2)%2C%20name%3D_name))%0A_t1_fig.add_vline(x%3D_tr%2C%20line_dash%3D'dash'%2C%20line_color%3D'red'%2C%20annotation_text%3Df'TR%3D%7B_tr%7D')%0A_t1_fig.update_layout(title%3D'T%E2%82%81%20Recovery'%2C%20width%3D350%2C%20height%3D300%2C%20margin%3Ddict(l%3D40%2C%20r%3D5%2C%20t%3D30%2C%20b%3D40)%2C%20xaxis_title%3D'Time%20(ms)'%2C%20yaxis_title%3D'Signal'%2C%20yaxis%3Ddict(range%3D%5B0%2C%201.05%5D)%2C%20legend%3Ddict(font%3Ddict(size%3D8)%2C%20x%3D0.55%2C%20y%3D0.35))%0A_t2_fig%20%3D%20go.Figure()%0Afor%20_name%20in%20_tissue_names%3A%0A%20%20%20%20_p%20%3D%20_tissues%5B_name%5D%0A%20%20%20%20_color%20%3D%20_tissue_colors.get(_name%2C%20'gray')%0A%20%20%20%20_t2_fig.add_trace(go.Scatter(x%3D_t_t2%2C%20y%3D_p%5B'PD'%5D%20*%20t2_decay(_t_t2%2C%20_p%5B'T2'%5D)%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D_color%2C%20width%3D2)%2C%20name%3D_name%2C%20showlegend%3DFalse))%0A_t2_fig.add_vline(x%3D_te%2C%20line_dash%3D'dash'%2C%20line_color%3D'red'%2C%20annotation_text%3Df'TE%3D%7B_te%7D')%0A_t2_fig.update_layout(title%3D'T%E2%82%82%20Decay'%2C%20width%3D350%2C%20height%3D300%2C%20margin%3Ddict(l%3D40%2C%20r%3D5%2C%20t%3D30%2C%20b%3D40)%2C%20xaxis_title%3D'Time%20(ms)'%2C%20yaxis_title%3D'Signal'%2C%20yaxis%3Ddict(range%3D%5B0%2C%201.05%5D))%0Amo.vstack(%5Bmo.hstack(%5Bte_slider%2C%20tr_slider%2C%20contrast_field%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20mo.hstack(%5B_bar_fig%2C%20_t1_fig%2C%20_t2_fig%5D%2C%20justify%3D'center')%2C%20mo.callout(mo.md(f'**Current%20weighting%3A%20%7B_weighting%7D**%20%E2%80%94%20Try%3A%20TR%3D500%2C%20TE%3D10%20(T%E2%82%81w)%20%7C%20TR%3D4000%2C%20TE%3D80%20(T%E2%82%82w)%20%7C%20TR%3D4000%2C%20TE%3D10%20(PD)%5Cn%5CnThe%20red%20dashed%20lines%20show%20where%20TR%20and%20TE%20sample%20the%20recovery%2Fdecay%20curves.%20The%20bar%20chart%20shows%20the%20resulting%20signal%20for%20each%20tissue.')%2C%20kind%3D'info')%5D)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2010.%20Spin%20Echo%20%26%20Gradient%20Echo%5Cn%5Cn%20%20%20%20We've%20been%20talking%20about%20the%20signal%20at%20time%20TE%20after%20excitation.%20But%5Cn%20%20%20%20how%20do%20we%20actually%20*collect*%20the%20signal%20at%20a%20specific%20echo%20time%3F%20There%5Cn%20%20%20%20are%20two%20fundamental%20approaches%3A%5Cn%5Cn%20%20%20%20%23%23%23%20Spin%20Echo%20(SE)%5Cn%20%20%20%20A%20**180%C2%B0%20refocusing%20pulse**%20is%20applied%20at%20time%20TE%2F2%20after%20the%20initial%5Cn%20%20%20%2090%C2%B0%20excitation.%20This%20reverses%20the%20dephasing%20caused%20by%20static%20field%5Cn%20%20%20%20inhomogeneities%2C%20causing%20the%20spins%20to%20**rephase**%20and%20form%20an%20echo%5Cn%20%20%20%20at%20time%20TE.%20The%20spin%20echo%20signal%20depends%20on%20**T2**%20(not%20T2*)%2C%20because%5Cn%20%20%20%20the%20refocusing%20pulse%20undoes%20the%20T2'%20dephasing.%5Cn%20%20%20%20%22)
mo.image(str(IMG_DIR%20%2F%20'spin_echo_pulse_sequence.svg'))
mo.md('%5Cn%20%20%20%20The%20diagram%20shows%20one%20full%20spin%20echo%20cycle.%5Cn%5Cn%20%20%20%20A%20**spin%20echo%20pulse%20sequence**%20begins%20with%20a%2090%C2%B0%20RF%20pulse%20that%20tips%20the%20net%20magnetization%20from%20the%20longitudinal%20axis%20into%20the%20transverse%20plane.%20Immediately%20after%20excitation%2C%20spins%20begin%20to%20dephase%20due%20to%20local%20field%20inhomogeneities%2C%20producing%20a%20decaying%20free%20induction%20decay%20(FID).%5Cn%5Cn%20%20%20%20A%20180%C2%B0%20refocusing%20pulse%20applied%20at%20time%20TE%2F2%20reverses%20this%20dephasing%2C%20causing%20spins%20to%20rephase%20and%20form%20an%20echo%20at%20time%20**TE**.%5Cn%5Cn%20%20%20%20The%20sequence%20repeats%20every%20**TR**%20(indicated%20by%20the%20faded%2090%C2%B0%20pulse%20at%20the%20right%20edge).%5Cn%5Cn%20%20%20%20Three%20spatial%20encoding%20gradients%20operate%20alongside%20the%20RF%20pulses%3A%5Cn%5Cn%20%20%20%20-%20**Gss%20(slice%20select)**%20is%20applied%20during%20both%20RF%20pulses%20to%20restrict%20excitation%20to%20a%20single%20imaging%20slice%5Cn%20%20%20%20-%20**Gpe%20(phase%20encode)**%20applies%20a%20brief%20gradient%20of%20varying%20amplitude%20on%20each%20repetition%2C%20stepping%20through%20k-space%20line%20by%20line%5Cn%20%20%20%20-%20**Gro%20(readout%2Ffrequency%20encode)**%20is%20switched%20on%20during%20the%20echo%20to%20spatially%20encode%20signal%20along%20the%20remaining%20axis.%5Cn%5Cn%20%20%20%20Together%2C%20these%20three%20gradients%20provide%20the%20spatial%20information%20needed%20to%20reconstruct%20a%202D%20image%20from%20the%20acquired%20signal.%5Cn%20%20%20%20')
mo.md('%5Cn%20%20%20%20%23%23%23%20Gradient%20Echo%20(GRE)%5Cn%20%20%20%20Instead%20of%20a%20180%C2%B0%20pulse%2C%20a%20**gradient%20reversal**%20is%20used%20to%20form%20the%5Cn%20%20%20%20echo.%20This%20is%20faster%20but%20does%20NOT%20refocus%20static%20field%20inhomogeneities%2C%5Cn%20%20%20%20so%20the%20signal%20depends%20on%20**T2***%20(not%20T2).%20Gradient%20echoes%20are%20the%5Cn%20%20%20%20basis%20of%20most%20fMRI%20sequences%20(because%20fMRI%20needs%20T2*%20sensitivity!).%5Cn%20%20%20%20')
mo.image(str(IMG_DIR%20%2F%20'gradient_echo_pulse_sequence.svg'))
mo.md('%5Cn%20%20%20%20A%20**gradient%20echo%20pulse%20sequence**%20begins%20with%20a%20low%20flip%20angle%20(%CE%B1)%20RF%20pulse%20%E2%80%94%20typically%20much%20less%20than%2090%C2%B0%20%E2%80%94%20that%20tips%20a%20fraction%20of%20the%20longitudinal%20magnetization%20into%20the%20transverse%20plane.%5Cn%5Cn%20%20%20%20Unlike%20the%20spin%20echo%2C%20there%20is%20no%20180%C2%B0%20refocusing%20pulse.%5Cn%5Cn%20%20%20%20Instead%2C%20the%20echo%20is%20formed%20entirely%20by%20gradient%20manipulation%3A%20a%20negative%20dephasing%20lobe%20on%20the%20**readout%20gradient%20(Gro)**%20deliberately%20dephases%20the%20spins%2C%20and%20then%20a%20positive%20lobe%20of%20opposite%20polarity%20rephases%20them%20to%20produce%20the%20gradient%20echo%20at%20time%20TE.%5Cn%5Cn%20%20%20%20Because%20the%20180%C2%B0%20pulse%20is%20absent%2C%20static%20field%20inhomogeneities%20are%20not%20corrected%2C%20so%20the%20signal%20decays%20with%20T2*%20rather%20than%20T2.%5Cn%5Cn%20%20%20%20The%20**slice%20select%20gradient%20(Gss)**%20is%20applied%20during%20the%20%CE%B1%20pulse%20to%20restrict%20excitation%20to%20a%20single%20slice%2C%20and%20the%20**phase%20encode%20gradient%20(Gpe)**%20steps%20through%20different%20amplitudes%20on%20each%20repetition%20to%20fill%20k-space.%5Cn%5Cn%20%20%20%20The%20combination%20of%20a%20small%20flip%20angle%20and%20no%20refocusing%20pulse%20allows%20very%20short%20TR%20and%20TE%2C%20making%20gradient%20echo%20sequences%20the%20basis%20for%20fast%20imaging%20methods%20such%20as%20FLASH%2C%20SPGR%2C%20and%20MPRAGE.%5Cn%5Cn%20%20%20%20Here%20is%20an%20interactive%20figure%20showing%20this%20process%20over%20time%20for%20each%20sequence%20type.%5Cn%20%20%20%20')
echo_type%20%3D%20mo.ui.radio(options%3D%7B'Spin%20Echo%20(90%C2%B0-180%C2%B0)'%3A%20'spin_echo'%2C%20'Gradient%20Echo'%3A%20'gradient_echo'%7D%2C%20value%3D'Spin%20Echo%20(90%C2%B0-180%C2%B0)'%2C%20label%3D'Sequence%20type')%0Aecho_speed%20%3D%20mo.ui.slider(start%3D0.3%2C%20stop%3D3.0%2C%20step%3D0.1%2C%20value%3D1.0%2C%20label%3D'Animation%20speed')
Spin Echo : 90° → wait TE/2 → 180° (refocus) → wait TE/2 → Echo
The 180° pulse reverses all static dephasing. The echo signal reflects true T₂ decay only. Used for anatomical imaging (T₁w, T₂w).
_seq_type%20%3D%20echo_type.value%0A_speed%20%3D%20echo_speed.value%0A_widget%20%3D%20SpinEnsembleWidget(sequence_type%3D_seq_type%2C%20speed%3D_speed)%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Aif%20_seq_type%20%3D%3D%20'spin_echo'%3A%0A%20%20%20%20_seq_desc%20%3D%20'**Spin%20Echo**%3A%2090%C2%B0%20%E2%86%92%20wait%20TE%2F2%20%E2%86%92%20180%C2%B0%20(refocus)%20%E2%86%92%20wait%20TE%2F2%20%E2%86%92%20Echo%5Cn%5CnThe%20180%C2%B0%20pulse%20reverses%20all%20static%20dephasing.%20The%20echo%20signal%20reflects%20**true%20T%E2%82%82**%20decay%20only.%20Used%20for%20anatomical%20imaging%20(T%E2%82%81w%2C%20T%E2%82%82w).'%0Aelse%3A%0A%20%20%20%20_seq_desc%20%3D%20'**Gradient%20Echo**%3A%20%CE%B1%C2%B0%20%E2%86%92%20gradient%20dephase%20%E2%86%92%20gradient%20rephase%20%E2%86%92%20Echo%5Cn%5CnNo%20refocusing%20pulse%2C%20so%20static%20field%20inhomogeneities%20are%20NOT%20reversed.%20The%20echo%20signal%20reflects%20**T%E2%82%82***%20decay.%20Faster%20than%20spin%20echo.%20Used%20for%20**fMRI**%20(BOLD%20signal%20depends%20on%20T%E2%82%82*!).'%0Amo.vstack(%5Bmo.hstack(%5Becho_type%2C%20echo_speed%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_wrapped%2C%20mo.md(_seq_desc)%2C%20mo.callout(mo.md(%22**Why%20does%20this%20matter%20for%20fMRI%3F**%20The%20BOLD%20signal%20(which%20we'll%20cover%20next)%20depends%20on%20local%20magnetic%20field%20changes%20caused%20by%20deoxyhemoglobin.%20These%20are%20T%E2%82%82*%20effects%20--%20they%20would%20be%20refocused%20away%20by%20a%20spin%20echo!%20That's%20why%20fMRI%20uses%20**gradient%20echo**%20sequences.%5Cn%5CnWatch%20the%20signal%20trace%20on%20the%20right%3A%20in%20**spin%20echo**%2C%20the%20signal%20fully%20recovers%20at%20the%20echo.%20In%20**gradient%20echo**%2C%20residual%20dephasing%20remains.%22)%2C%20kind%3D'warn')%5D)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%20Part%203%3A%20Imaging%20%26%20fMRI%5Cn%5Cn%20%20%20%20We%20now%20know%20how%20to%20generate%20a%20signal%20and%20how%20different%20tissues%20produce%5Cn%20%20%20%20different%20signals.%20But%20there's%20a%20critical%20problem%3A%20**where%20did%20the%5Cn%20%20%20%20signal%20come%20from%3F**%5Cn%5Cn%20%20%20%20If%20the%20entire%20volume%20inside%20the%20scanner%20experiences%20the%20same%20%5C%5C(B_0%5C%5C)%5Cn%20%20%20%20field%2C%20all%20protons%20precess%20at%20the%20same%20frequency%2C%20and%20we%20can't%20tell%5Cn%20%20%20%20whether%20the%20signal%20is%20coming%20from%20your%20frontal%20cortex%20or%20your%20cerebellum.%5Cn%20%20%20%20We%20need%20**spatial%20encoding**%20--%20a%20way%20to%20tag%20different%20locations%20with%5Cn%20%20%20%20different%20frequencies%20or%20phases%20so%20we%20can%20reconstruct%20an%20image.%5Cn%20%20%20%20%22)
VIDEO
mo.Html('%5Cn%20%20%20%20%20%20%3Ciframe%5Cn%20%20%20%20%20%20%20%20%20%20width%3D%22560%22%20height%3D%22315%22%5Cn%20%20%20%20%20%20%20%20%20%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FPxqDjhO9FUs%22%5Cn%20%20%20%20%20%20%20%20%20%20frameborder%3D%220%22%20allowfullscreen%3E%5Cn%20%20%20%20%20%20%3C%2Fiframe%3E%5Cn%20%20%20%20%20%20')
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2011.%20The%20Localization%20Problem%3A%20Why%20We%20Need%20Gradients%5Cn%5Cn%20%20%20%20In%20a%20perfectly%20uniform%20%5C%5C(B_0%5C%5C)%20field%2C%20every%20proton%20in%20the%20body%5Cn%20%20%20%20precesses%20at%20the%20same%20Larmor%20frequency.%20Our%20receiver%20coil%20picks%20up%5Cn%20%20%20%20the%20*sum*%20of%20all%20these%20signals%2C%20with%20no%20way%20to%20tell%20where%20each%5Cn%20%20%20%20contribution%20came%20from.%5Cn%5Cn%20%20%20%20The%20solution%3A%20**gradient%20coils**.%20These%20are%20additional%20electromagnetic%5Cn%20%20%20%20coils%20that%20make%20the%20magnetic%20field%20vary%20*linearly*%20across%20space.%20If%5Cn%20%20%20%20we%20add%20a%20gradient%20along%20the%20x-axis%3A%5Cn%5Cn%20%20%20%20%24%24B(x)%20%3D%20B_0%20%2B%20G_x%20%5C%5Ccdot%20x%24%24%5Cn%5Cn%20%20%20%20then%20the%20Larmor%20frequency%20also%20varies%20with%20position%3A%5Cn%5Cn%20%20%20%20%24%24f(x)%20%3D%20%5C%5Cgamma%20%5C%5Ccdot%20(B_0%20%2B%20G_x%20%5C%5Ccdot%20x)%24%24%5Cn%5Cn%20%20%20%20Now%20protons%20at%20different%20x-positions%20precess%20at%20different%20frequencies%5Cn%20%20%20%20--%20and%20we%20can%20separate%20them%20using%20the%20Fourier%20transform!%5Cn%20%20%20%20')
grad_strength_slider%20%3D%20mo.ui.slider(start%3D0.0%2C%20stop%3D40.0%2C%20step%3D1.0%2C%20value%3D0.0%2C%20label%3D'Gradient%20strength%20Gx%20(mT%2Fm)'%2C%20full_width%3DTrue)
Gradient: 0 mT/m → Frequency spread across 30cm FOV: 0.0 kHz (uniform field, no spatial encoding!)
_gx%20%3D%20grad_strength_slider.value%0A_b0%20%3D%203.0%0A_positions%20%3D%20np.linspace(-0.15%2C%200.15%2C%20200)%0A_b_field%20%3D%20_b0%20%2B%20_gx%20%2F%201000%20*%20_positions%0A_freq%20%3D%20GAMMA_H%20*%20_b_field%0A_fig%20%3D%20make_subplots(rows%3D1%2C%20cols%3D2%2C%20subplot_titles%3D%5B'Magnetic%20Field%20B(x)'%2C%20'Larmor%20Frequency%20f(x)'%5D)%0A_fig.add_trace(go.Scatter(x%3D_positions%20*%20100%2C%20y%3D_b_field%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3D3)%2C%20name%3D'B(x)')%2C%20row%3D1%2C%20col%3D1)%0A_fig.add_trace(go.Scatter(x%3D_positions%20*%20100%2C%20y%3D_freq%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23EF553B'%2C%20width%3D3)%2C%20name%3D'f(x)')%2C%20row%3D1%2C%20col%3D2)%0A_fig.update_xaxes(title_text%3D'Position%20(cm)'%2C%20row%3D1%2C%20col%3D1)%0A_fig.update_xaxes(title_text%3D'Position%20(cm)'%2C%20row%3D1%2C%20col%3D2)%0A_fig.update_yaxes(title_text%3D'B%20(Tesla)'%2C%20row%3D1%2C%20col%3D1)%0A_fig.update_yaxes(title_text%3D'Frequency%20(MHz)'%2C%20row%3D1%2C%20col%3D2)%0A_freq_range%20%3D%20_freq%5B-1%5D%20-%20_freq%5B0%5D%0A_fig.update_layout(width%3D800%2C%20height%3D350%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40)%2C%20yaxis%3Ddict(range%3D%5B2.99%2C%203.01%5D)%2C%20yaxis2%3Ddict(range%3D%5B127.3%2C%20128.2%5D))%0Amo.vstack(%5Bmo.hstack(%5Bgrad_strength_slider%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_fig%2C%20mo.md(f%22**Gradient%3A%20%7B_gx%3A.0f%7D%20mT%2Fm**%20%E2%86%92%20Frequency%20spread%20across%2030cm%20FOV%3A%20**%7Babs(_freq_range%20*%201000)%3A.1f%7D%20kHz**%20(%7B('uniform%20field%2C%20no%20spatial%20encoding!'%20if%20_gx%20%3D%3D%200%20else%20'spatial%20encoding%20active')%7D)%22)%2C%20mo.callout(mo.md('With%20**no%20gradient**%20(Gx%3D0)%2C%20the%20field%20and%20frequency%20are%20the%20same%20everywhere%20--%20no%20spatial%20information.%20As%20you%20increase%20the%20gradient%2C%20frequency%20varies%20across%20space%2C%20and%20the%20Fourier%20transform%20of%20the%20signal%20directly%20maps%20to%20spatial%20position!')%2C%20kind%3D'info')%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2012.%20Slice%20Selection%5Cn%5Cn%20%20%20%20MRI%20typically%20images%20one%20**slice**%20at%20a%20time.%20To%20select%20a%20specific%5Cn%20%20%20%20slice%2C%20we%20apply%20a%20gradient%20along%20the%20z-axis%20(head-to-foot)%20during%5Cn%20%20%20%20the%20RF%20pulse.%20The%20RF%20pulse%20has%20a%20limited%20bandwidth%20--%20it%20only%20excites%5Cn%20%20%20%20protons%20within%20a%20narrow%20range%20of%20frequencies.%20Since%20the%20z-gradient%5Cn%20%20%20%20makes%20frequency%20vary%20with%20position%2C%20only%20protons%20in%20one%20slice%5Cn%20%20%20%20are%20on-resonance%20and%20get%20excited.%5Cn%5Cn%20%20%20%20**Slice%20thickness**%20is%20controlled%20by%3A%5Cn%20%20%20%20%24%24%5C%5CDelta%20z%20%3D%20%5C%5Cfrac%7B%5C%5CDelta%20f%7D%7B%5C%5Cgamma%20%5C%5Ccdot%20G_z%7D%24%24%5Cn%5Cn%20%20%20%20where%20%5C%5C(%5C%5CDelta%20f%5C%5C)%20is%20the%20RF%20pulse%20bandwidth%20and%20%5C%5C(G_z%5C%5C)%20is%20the%5Cn%20%20%20%20slice-select%20gradient%20strength.%20Stronger%20gradient%20%3D%20thinner%20slice.%5Cn%20%20%20%20Wider%20RF%20bandwidth%20%3D%20thicker%20slice.%5Cn%20%20%20%20')
ss_grad_slider%20%3D%20mo.ui.slider(start%3D5%2C%20stop%3D40%2C%20step%3D1%2C%20value%3D20%2C%20label%3D'Slice-select%20gradient%20Gz%20(mT%2Fm)')%0Ass_bw_slider%20%3D%20mo.ui.slider(start%3D500%2C%20stop%3D5000%2C%20step%3D100%2C%20value%3D2000%2C%20label%3D'RF%20bandwidth%20(Hz)')
With Gz = 20 mT/m and RF bandwidth = 2000 Hz , the selected slice is 2.3 mm thick.
The red segment shows the positions where protons are within the RF bandwidth and will be excited. All other protons are off-resonance and unaffected.
_gz%20%3D%20ss_grad_slider.value%20%2F%201000%0A_bw%20%3D%20ss_bw_slider.value%0A_b0%20%3D%203.0%0A_slice_thickness%20%3D%20_bw%20%2F%20(GAMMA_H%20*%201000000.0%20*%20_gz)%20*%201000%0A_z_pos%20%3D%20np.linspace(-100%2C%20100%2C%20500)%0A_freq_hz%20%3D%20GAMMA_H%20*%201000000.0%20*%20(_b0%20%2B%20_gz%20*%20_z_pos%20%2F%201000)%20-%20GAMMA_H%20*%201000000.0%20*%20_b0%0A_center_freq%20%3D%200%0A_excited%20%3D%20np.abs(_freq_hz%20-%20_center_freq)%20%3C%20_bw%20%2F%202%0A_fig%20%3D%20go.Figure()%0A_fig.add_trace(go.Scatter(x%3D_z_pos%2C%20y%3D_freq_hz%20%2F%201000%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3D2)%2C%20name%3D'Frequency%20offset'))%0A_fig.add_trace(go.Scatter(x%3D_z_pos%5B_excited%5D%2C%20y%3D_freq_hz%5B_excited%5D%20%2F%201000%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'red'%2C%20width%3D4)%2C%20name%3D'Excited%20slice'))%0A_fig.add_hrect(y0%3D-_bw%20%2F%202000%2C%20y1%3D_bw%20%2F%202000%2C%20fillcolor%3D'rgba(255%2C%200%2C%200%2C%200.1)'%2C%20line_width%3D0%2C%20annotation_text%3D'RF%20bandwidth')%0A_fig.update_layout(title%3Df'Slice%20Selection%3A%20thickness%20%3D%20%7B_slice_thickness%3A.1f%7D%20mm'%2C%20xaxis_title%3D'Position%20along%20z%20(mm)'%2C%20yaxis_title%3D'Frequency%20offset%20(kHz)'%2C%20yaxis%3Ddict(range%3D%5B-5%2C%205%5D)%2C%20width%3D700%2C%20height%3D400%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40))%0Amo.vstack(%5Bmo.hstack(%5Bss_grad_slider%2C%20ss_bw_slider%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_fig%2C%20mo.md(f'With%20Gz%20%3D%20**%7B_gz%20*%201000%3A.0f%7D%20mT%2Fm**%20and%20RF%20bandwidth%20%3D%20**%7B_bw%7D%20Hz**%2C%20the%20selected%20slice%20is%20**%7B_slice_thickness%3A.1f%7D%20mm**%20thick.%5Cn%5CnThe%20red%20segment%20shows%20the%20positions%20where%20protons%20are%20within%20the%20RF%20bandwidth%20and%20will%20be%20excited.%20All%20other%20protons%20are%20off-resonance%20and%20unaffected.')%2C%20mo.callout(mo.md('**Try%20this%3A**%20Increase%20the%20gradient%20strength%20--%20the%20slice%20gets%20thinner%20(better%20resolution%20but%20less%20signal).%20Increase%20the%20RF%20bandwidth%20--%20the%20slice%20gets%20thicker%20(more%20signal%20but%20lower%20resolution).%20This%20is%20a%20fundamental%20tradeoff%20in%20MRI.')%2C%20kind%3D'info')%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2013.%20Frequency%20%26%20Phase%20Encoding%5Cn%5Cn%20%20%20%20After%20selecting%20a%20slice%2C%20we%20still%20need%20to%20encode%20position%20within%5Cn%20%20%20%20that%202D%20slice.%20MRI%20uses%20two%20clever%20tricks%3A%5Cn%5Cn%20%20%20%20**Frequency%20encoding%20(readout%20direction%2C%20x)%3A**%20During%20signal%20readout%2C%5Cn%20%20%20%20a%20gradient%20along%20x%20makes%20protons%20at%20different%20x-positions%20precess%20at%5Cn%20%20%20%20different%20frequencies.%20The%20Fourier%20transform%20of%20the%20readout%20signal%5Cn%20%20%20%20directly%20gives%20us%20the%20spatial%20profile%20along%20x.%5Cn%5Cn%20%20%20%20**Phase%20encoding%20(y-direction)%3A**%20Before%20readout%2C%20a%20brief%20gradient%5Cn%20%20%20%20pulse%20along%20y%20gives%20protons%20at%20different%20y-positions%20different%20*phases*.%5Cn%20%20%20%20This%20is%20repeated%20many%20times%20with%20different%20gradient%20strengths%20to%20fill%5Cn%20%20%20%20out%20the%20y-dimension.%20Each%20repetition%20fills%20one%20line%20of%20k-space.%5Cn%5Cn%20%20%20%20The%20combination%20gives%20each%20voxel%20a%20unique%20(frequency%2C%20phase)%20signature%5Cn%20%20%20%20that%20can%20be%20decoded%20by%20a%202D%20Fourier%20transform.%5Cn%20%20%20%20')
Watch how the spin arrows in each voxel respond to gradients:
No gradients : all spins precess at the same rate
Frequency encoding (Gx) : columns spin at different rates
Phase encoding (Gy) : rows accumulate different phase offsets
Both : each voxel gets a unique (frequency, phase) signature
The 2D Fourier transform decodes these signatures back into an image.
_widget%20%3D%20EncodingWidget(speed%3D1.0)%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5B_wrapped%2C%20mo.md('Watch%20how%20the%20spin%20arrows%20in%20each%20voxel%20respond%20to%20gradients%3A%5Cn-%20**No%20gradients**%3A%20all%20spins%20precess%20at%20the%20same%20rate%5Cn-%20**Frequency%20encoding%20(Gx)**%3A%20columns%20spin%20at%20different%20rates%5Cn-%20**Phase%20encoding%20(Gy)**%3A%20rows%20accumulate%20different%20phase%20offsets%5Cn-%20**Both**%3A%20each%20voxel%20gets%20a%20unique%20(frequency%2C%20phase)%20signature%5Cn%5CnThe%202D%20Fourier%20transform%20decodes%20these%20signatures%20back%20into%20an%20image.')%5D)
The MRI signal at time ||(t||) during readout, for a given
phase-encode step with gradient area ||(A_y||) , is:
||[S(t) = \int\int \rho(x, y) \cdot e^{-i 2\pi (\gamma G_x x t + \gamma A_y y)} \, dx \, dy||] where ||(\rho(x, y)||) is the spin density (our image).
If we define spatial frequencies:
||(k_x = \gamma G_x t||) (varies during readout)
||(k_y = \gamma A_y||) (set by phase-encode gradient)
then the signal equation becomes:
||[S(k_x, k_y) = \int\int \rho(x, y) \cdot e^{-i 2\pi (k_x x + k_y y)} \, dx \, dy||] This is exactly the 2D Fourier transform of the image!
Therefore, the image is simply the inverse Fourier transform
of the acquired data:
||[\rho(x, y) = \mathcal{F}^{-1}\{S(k_x, k_y)\}||] The space of ||((k_x, k_y)||) is called k-space .
mo.accordion(%7B'Deep%20Dive%3A%20The%20Fourier%20encoding%20equations'%3A%20mo.md('%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20MRI%20signal%20at%20time%20%5C%5C(t%5C%5C)%20during%20readout%2C%20for%20a%20given%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20phase-encode%20step%20with%20gradient%20area%20%5C%5C(A_y%5C%5C)%2C%20is%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24S(t)%20%3D%20%5C%5Cint%5C%5Cint%20%5C%5Crho(x%2C%20y)%20%5C%5Ccdot%20e%5E%7B-i%202%5C%5Cpi%20(%5C%5Cgamma%20G_x%20x%20t%20%2B%20%5C%5Cgamma%20A_y%20y)%7D%20%5C%5C%2C%20dx%20%5C%5C%2C%20dy%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20where%20%5C%5C(%5C%5Crho(x%2C%20y)%5C%5C)%20is%20the%20spin%20density%20(our%20image).%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20If%20we%20define%20spatial%20frequencies%3A%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20%5C%5C(k_x%20%3D%20%5C%5Cgamma%20G_x%20t%5C%5C)%20(varies%20during%20readout)%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20%5C%5C(k_y%20%3D%20%5C%5Cgamma%20A_y%5C%5C)%20(set%20by%20phase-encode%20gradient)%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20then%20the%20signal%20equation%20becomes%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24S(k_x%2C%20k_y)%20%3D%20%5C%5Cint%5C%5Cint%20%5C%5Crho(x%2C%20y)%20%5C%5Ccdot%20e%5E%7B-i%202%5C%5Cpi%20(k_x%20x%20%2B%20k_y%20y)%7D%20%5C%5C%2C%20dx%20%5C%5C%2C%20dy%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20This%20is%20exactly%20the%20**2D%20Fourier%20transform**%20of%20the%20image!%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Therefore%2C%20the%20image%20is%20simply%20the%20inverse%20Fourier%20transform%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20of%20the%20acquired%20data%3A%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%24%5C%5Crho(x%2C%20y)%20%3D%20%5C%5Cmathcal%7BF%7D%5E%7B-1%7D%5C%5C%7BS(k_x%2C%20k_y)%5C%5C%7D%24%24%5Cn%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20The%20space%20of%20%5C%5C((k_x%2C%20k_y)%5C%5C)%20is%20called%20**k-space**.%5Cn%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20')%7D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2014.%20K-Space%3A%20Where%20MRI%20Data%20Lives%5Cn%20%20%20%20')
VIDEO
mo.Html('%5Cn%20%20%20%20%20%20%3Ciframe%5Cn%20%20%20%20%20%20%20%20%20%20width%3D%22560%22%20height%3D%22315%22%5Cn%20%20%20%20%20%20%20%20%20%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FFI5frNsRTI4%22%5Cn%20%20%20%20%20%20%20%20%20%20frameborder%3D%220%22%20allowfullscreen%3E%5Cn%20%20%20%20%20%20%3C%2Fiframe%3E%5Cn%20%20%20%20%20%20')
mo.md(%22%5Cn%20%20%20%20The%20raw%20data%20from%20an%20MRI%20scan%20doesn't%20look%20like%20an%20image%20--%20it%20lives%5Cn%20%20%20%20in%20**k-space**%2C%20the%20spatial%20frequency%20domain.%20K-space%20and%20the%20image%5Cn%20%20%20%20are%20related%20by%20the%202D%20Fourier%20transform%3A%5Cn%5Cn%20%20%20%20%24%24%5C%5Ctext%7BImage%7D%20%3D%20%5C%5Ctext%7BFFT%7D%5E%7B-1%7D(%5C%5Ctext%7BK-space%7D)%24%24%5Cn%5Cn%20%20%20%20Different%20regions%20of%20k-space%20encode%20different%20features%3A%5Cn%20%20%20%20-%20**Center%20of%20k-space**%20%E2%86%92%20overall%20contrast%2C%20brightness%2C%20low-frequency%5Cn%20%20%20%20%20%20shapes%5Cn%20%20%20%20-%20**Edges%20of%20k-space**%20%E2%86%92%20fine%20details%2C%20sharp%20edges%2C%20high%20spatial%5Cn%20%20%20%20%20%20frequency%5Cn%5Cn%20%20%20%20This%20means%20you%20don't%20need%20ALL%20of%20k-space%20to%20get%20a%20useful%20image.%5Cn%20%20%20%20Keeping%20only%20the%20center%20gives%20you%20a%20blurry%20but%20recognizable%20image.%5Cn%20%20%20%20Keeping%20only%20the%20edges%20gives%20you%20an%20edge%20map%20with%20no%20contrast.%5Cn%5Cn%20%20%20%20Try%20masking%20different%20regions%20below%20to%20build%20intuition!%5Cn%20%20%20%20%22)
kspace_mask_type%20%3D%20mo.ui.dropdown(options%3D%7B'Progressive%20fill%20(animated)'%3A%20'progressive'%2C%20'Center%20only%20(low%20frequencies)'%3A%20'center'%2C%20'Periphery%20only%20(high%20frequencies)'%3A%20'periphery'%2C%20'Every%204th%20line%20(undersampled)'%3A%20'undersampled'%7D%2C%20value%3D'Progressive%20fill%20(animated)'%2C%20label%3D'K-space%20mode')%0Akspace_radius%20%3D%20mo.ui.slider(start%3D0.05%2C%20stop%3D0.5%2C%20step%3D0.05%2C%20value%3D0.2%2C%20label%3D'Mask%20radius')%0Akspace_speed%20%3D%20mo.ui.slider(start%3D0.5%2C%20stop%3D5.0%2C%20step%3D0.5%2C%20value%3D2.0%2C%20label%3D'Fill%20speed')
Progressive fill shows how an MRI scanner acquires k-space line by line, with the image emerging gradually. Try other modes:
Center only : Blurry but recognizable -- contrast lives in the center
Periphery only : Only edges visible -- detail lives at the edges
Undersampled : Aliasing artifacts from skipping lines
_widget%20%3D%20KSpaceWidget(mask_type%3Dkspace_mask_type.value%2C%20radius_fraction%3Dfloat(kspace_radius.value)%2C%20speed%3Dfloat(kspace_speed.value))%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5Bmo.hstack(%5Bkspace_mask_type%2C%20kspace_radius%2C%20kspace_speed%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_wrapped%2C%20mo.md('**Progressive%20fill**%20shows%20how%20an%20MRI%20scanner%20acquires%20k-space%20line%20by%20line%2C%20with%20the%20image%20emerging%20gradually.%20Try%20other%20modes%3A%5Cn-%20**Center%20only**%3A%20Blurry%20but%20recognizable%20--%20contrast%20lives%20in%20the%20center%5Cn-%20**Periphery%20only**%3A%20Only%20edges%20visible%20--%20detail%20lives%20at%20the%20edges%5Cn-%20**Undersampled**%3A%20Aliasing%20artifacts%20from%20skipping%20lines')%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2015.%20BOLD%20%26%20the%20Hemodynamic%20Response%5Cn%20%20%20%20')
VIDEO
mo.Html('%5Cn%20%20%20%20%20%20%3Ciframe%5Cn%20%20%20%20%20%20%20%20%20%20width%3D%22560%22%20height%3D%22315%22%5Cn%20%20%20%20%20%20%20%20%20%20src%3D%22https%3A%2F%2Fwww.youtube.com%2Fembed%2FjG2WQpgpnMs%22%5Cn%20%20%20%20%20%20%20%20%20%20frameborder%3D%220%22%20allowfullscreen%3E%5Cn%20%20%20%20%20%20%3C%2Fiframe%3E%5Cn%20%20%20%20%20%20')
mo.md(%22%5Cn%20%20%20%20Now%20we%20arrive%20at%20**functional%20MRI%20(fMRI)**%20--%20using%20MRI%20to%20measure%5Cn%20%20%20%20brain%20*activity*.%20But%20MRI%20doesn't%20measure%20neural%20activity%20directly.%5Cn%20%20%20%20Instead%2C%20it%20measures%20a%20downstream%20consequence%3A%20changes%20in%20**blood%5Cn%20%20%20%20oxygenation**.%5Cn%5Cn%20%20%20%20The%20key%20insight%3A%20**deoxyhemoglobin%20is%20paramagnetic**%20(slightly%20magnetic)%2C%5Cn%20%20%20%20while%20**oxyhemoglobin%20is%20diamagnetic**%20(not%20magnetic).%20When%20a%20brain%5Cn%20%20%20%20region%20becomes%20active%3A%5Cn%5Cn%20%20%20%201.%20Neurons%20fire%20and%20consume%20oxygen%20locally%5Cn%20%20%20%202.%20The%20vascular%20system%20responds%20by%20increasing%20blood%20flow%20to%20that%20region%5Cn%20%20%20%203.%20Blood%20flow%20*overshoots*%20metabolic%20demand%20--%20more%20oxygen%20arrives%5Cn%20%20%20%20%20%20%20than%20is%20consumed%5Cn%20%20%20%204.%20The%20result%3A%20less%20deoxyhemoglobin%20locally%5Cn%20%20%20%205.%20Less%20deoxyhemoglobin%20%E2%86%92%20less%20local%20field%20distortion%20%E2%86%92%20**increased%5Cn%20%20%20%20%20%20%20T%E2%82%82*%20signal**%5Cn%5Cn%20%20%20%20This%20is%20the%20**Blood%20Oxygen%20Level%20Dependent%20(BOLD)**%20signal.%20The%5Cn%20%20%20%20temporal%20shape%20of%20the%20BOLD%20response%20to%20a%20brief%20neural%20event%20is%20called%5Cn%20%20%20%20the%20**Hemodynamic%20Response%20Function%20(HRF)**.%5Cn%20%20%20%20%22)
hrf_peak_slider%20%3D%20mo.ui.slider(start%3D3.0%2C%20stop%3D9.0%2C%20step%3D0.5%2C%20value%3D6.0%2C%20label%3D'Peak%20time%20(s)')%0Ahrf_undershoot_slider%20%3D%20mo.ui.slider(start%3D10.0%2C%20stop%3D25.0%2C%20step%3D1.0%2C%20value%3D16.0%2C%20label%3D'Undershoot%20time%20(s)')%0Ahrf_ratio_slider%20%3D%20mo.ui.slider(start%3D0.0%2C%20stop%3D0.5%2C%20step%3D0.05%2C%20value%3D0.167%2C%20label%3D'Undershoot%20ratio')
The canonical HRF has several notable features:
Initial dip (small, often not detectable at typical fMRI resolution)
Peak at ~6s after stimulus
Post-stimulus undershoot at ~16s
Returns to baseline after ~25-30s
This sluggish hemodynamic response means fMRI has poor temporal resolution (~seconds) compared to EEG (milliseconds), even though the neural events happen on the millisecond timescale.
_peak%20%3D%20hrf_peak_slider.value%0A_undershoot%20%3D%20hrf_undershoot_slider.value%0A_ratio%20%3D%20hrf_ratio_slider.value%0A_t%20%3D%20np.linspace(0%2C%2030%2C%20300)%0A_h%20%3D%20hrf(_t%2C%20peak_time%3D_peak%2C%20undershoot_time%3D_undershoot%2C%20undershoot_ratio%3D_ratio)%0A_fig%20%3D%20go.Figure()%0A_fig.add_trace(go.Scatter(x%3D_t%2C%20y%3D_h%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3D3)%2C%20name%3D'HRF'))%0A_fig.add_hline(y%3D0%2C%20line_dash%3D'dot'%2C%20line_color%3D'gray')%0A_peak_idx%20%3D%20np.argmax(_h)%0A_fig.add_annotation(x%3D_t%5B_peak_idx%5D%2C%20y%3D_h%5B_peak_idx%5D%2C%20text%3Df'Peak%20(~%7B_t%5B_peak_idx%5D%3A.1f%7Ds)'%2C%20arrowhead%3D2%2C%20ay%3D-40)%0Aif%20_ratio%20%3E%200%3A%0A%20%20%20%20_undershoot_idx%20%3D%20np.argmin(_h%5B_peak_idx%3A%5D)%20%2B%20_peak_idx%0A%20%20%20%20if%20_h%5B_undershoot_idx%5D%20%3C%200%3A%0A%20%20%20%20%20%20%20%20_fig.add_annotation(x%3D_t%5B_undershoot_idx%5D%2C%20y%3D_h%5B_undershoot_idx%5D%2C%20text%3Df'Undershoot%20(~%7B_t%5B_undershoot_idx%5D%3A.1f%7Ds)'%2C%20arrowhead%3D2%2C%20ay%3D40)%0A_fig.update_layout(title%3D'Hemodynamic%20Response%20Function%20(HRF)'%2C%20xaxis_title%3D'Time%20after%20stimulus%20(s)'%2C%20yaxis_title%3D'BOLD%20signal%20change%20(a.u.)'%2C%20yaxis%3Ddict(range%3D%5B-0.3%2C%201.1%5D)%2C%20width%3D700%2C%20height%3D350%2C%20margin%3Ddict(l%3D60%2C%20r%3D20%2C%20t%3D40%2C%20b%3D40))%0Amo.vstack(%5Bmo.hstack(%5Bhrf_peak_slider%2C%20hrf_undershoot_slider%2C%20hrf_ratio_slider%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_fig%2C%20mo.md(f'The%20canonical%20HRF%20has%20several%20notable%20features%3A%5Cn-%20**Initial%20dip**%20(small%2C%20often%20not%20detectable%20at%20typical%20fMRI%20resolution)%5Cn-%20**Peak**%20at%20~%7B_peak%3A.0f%7Ds%20after%20stimulus%5Cn-%20**Post-stimulus%20undershoot**%20at%20~%7B_undershoot%3A.0f%7Ds%5Cn-%20Returns%20to%20baseline%20after%20~25-30s%5Cn%5CnThis%20sluggish%20hemodynamic%20response%20means%20fMRI%20has%20poor%20**temporal%20resolution**%20(~seconds)%20compared%20to%20EEG%20(milliseconds)%2C%20even%20though%20the%20neural%20events%20happen%20on%20the%20millisecond%20timescale.')%5D)
mo.md('%5Cn%20%20%20%20%23%23%23%20Convolution%3A%20From%20Events%20to%20Predicted%20BOLD%20Signal%5Cn%5Cn%20%20%20%20In%20an%20fMRI%20experiment%2C%20we%20present%20multiple%20stimuli%20over%20time.%20The%5Cn%20%20%20%20predicted%20BOLD%20signal%20is%20the%20**convolution**%20of%20the%20stimulus%20timing%5Cn%20%20%20%20with%20the%20HRF%3A%5Cn%5Cn%20%20%20%20%24%24%5C%5Ctext%7BPredicted%20BOLD%7D(t)%20%3D%20%5C%5Ctext%7Bstimulus%7D(t)%20*%20%5C%5Ctext%7BHRF%7D(t)%24%24%5Cn%5Cn%20%20%20%20This%20is%20the%20foundation%20of%20the%20**General%20Linear%20Model%20(GLM)**%20used%5Cn%20%20%20%20in%20fMRI%20analysis%20(covered%20in%20detail%20in%20later%20Dartbrains%20chapters).%5Cn%5Cn%20%20%20%20Try%20adjusting%20the%20stimulus%20timing%20below%20to%20see%20how%20the%20predicted%20BOLD%5Cn%20%20%20%20signal%20changes.%5Cn%20%20%20%20')
stim_pattern%20%3D%20mo.ui.dropdown(options%3D%7B'Single%20event'%3A%20'single'%2C%20'3%20events%20(spaced)'%3A%20'spaced'%2C%20'Block%20design%20(10s%20on%2Foff)'%3A%20'block'%2C%20'Rapid%20event-related'%3A%20'rapid'%7D%2C%20value%3D'Single%20event'%2C%20label%3D'Stimulus%20pattern')%0Aconv_speed%20%3D%20mo.ui.slider(start%3D0.5%2C%20stop%3D4.0%2C%20step%3D0.5%2C%20value%3D1.5%2C%20label%3D'Animation%20speed')
_widget%20%3D%20ConvolutionWidget(pattern%3Dstim_pattern.value%2C%20speed%3Dfloat(conv_speed.value))%0A_wrapped%20%3D%20mo.ui.anywidget(_widget)%0Amo.vstack(%5Bmo.hstack(%5Bstim_pattern%2C%20conv_speed%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20_wrapped%2C%20mo.callout(mo.md('Watch%20how%20each%20stimulus%20event%20spawns%20its%20own%20HRF%20response%20(purple%20ghost%20curves)%2C%20and%20the%20predicted%20BOLD%20signal%20(blue)%20is%20their%20sum.%20In%20block%20designs%2C%20the%20BOLD%20builds%20up%20during%20ON%20periods.%20In%20rapid%20event-related%20designs%2C%20individual%20HRFs%20overlap%20--%20this%20is%20**linear%20superposition**.')%2C%20kind%3D'info')%5D)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2016.%20fMRI%20Pulse%20Sequences%3A%20Echo%20Planar%20Imaging%20(EPI)%5Cn%5Cn%20%20%20%20Standard%20MRI%20acquires%20one%20line%20of%20k-space%20per%20TR%20--%20far%20too%20slow%20for%5Cn%20%20%20%20fMRI%2C%20which%20needs%20to%20image%20the%20whole%20brain%20every%201-2%20seconds.%5Cn%5Cn%20%20%20%20The%20solution%20is%20**Echo%20Planar%20Imaging%20(EPI)**%3A%20after%20a%20single%20RF%5Cn%20%20%20%20excitation%2C%20rapidly%20oscillating%20gradients%20traverse%20*all*%20of%20k-space%5Cn%20%20%20%20in%20about%2050-100%20milliseconds.%20This%20is%20the%20workhorse%20sequence%20for%20fMRI.%5Cn%5Cn%20%20%20%20**Typical%20fMRI%20parameters%3A**%5Cn%5Cn%20%20%20%20%7C%20Parameter%20%7C%20Structural%20(T%E2%82%81w%20MPRAGE)%20%7C%20Functional%20(GRE-EPI)%20%7C%5Cn%20%20%20%20%7C-----------%7C------------------------%7C---------------------%7C%5Cn%20%20%20%20%7C%20Weighting%20%7C%20T%E2%82%81%20%7C%20T%E2%82%82*%20%7C%5Cn%20%20%20%20%7C%20TR%20%7C%20~2000%20ms%20%7C%20500-2000%20ms%20%7C%5Cn%20%20%20%20%7C%20TE%20%7C%20~3%20ms%20%7C%20~30%20ms%20%7C%5Cn%20%20%20%20%7C%20Flip%20angle%20%7C%20~9%C2%B0%20%7C%20~70-90%C2%B0%20%7C%5Cn%20%20%20%20%7C%20Resolution%20%7C%20~1%20mm%C2%B3%20%7C%20~2-3%20mm%C2%B3%20%7C%5Cn%20%20%20%20%7C%20Volumes%20%7C%201%20(whole%20brain)%20%7C%20100s-1000s%20%7C%5Cn%20%20%20%20%7C%20Duration%20%7C%20~5%20min%20%7C%205-60%20min%20%7C%5Cn%20%20%20%20')
epi_tr_slider%20%3D%20mo.ui.slider(start%3D500%2C%20stop%3D3000%2C%20step%3D100%2C%20value%3D1000%2C%20label%3D'TR%20(ms)')%0Aepi_te_slider%20%3D%20mo.ui.slider(start%3D15%2C%20stop%3D50%2C%20step%3D5%2C%20value%3D30%2C%20label%3D'TE%20(ms)')%0Aepi_matrix_slider%20%3D%20mo.ui.slider(start%3D32%2C%20stop%3D128%2C%20step%3D16%2C%20value%3D64%2C%20label%3D'Matrix%20size')
Parameter
Value
Spatial Resolution
3.4 mm
Temporal Resolution
1.0 s
Slices per TR
~27
BOLD sensitivity
Good (TE=30ms)
Readout duration
~32 ms
_tr%20%3D%20epi_tr_slider.value%0A_te%20%3D%20epi_te_slider.value%0A_matrix%20%3D%20epi_matrix_slider.value%0A_fov%20%3D%20220%0A_voxel_size%20%3D%20_fov%20%2F%20_matrix%0A_readout_time%20%3D%20_matrix%20*%200.5%0A_n_slices%20%3D%20int(_tr%20%2F%20(_readout_time%20%2B%205))%0A_metrics%20%3D%20%7B'Spatial%20Resolution'%3A%20f'%7B_voxel_size%3A.1f%7D%20mm'%2C%20'Temporal%20Resolution'%3A%20f'%7B_tr%20%2F%201000%3A.1f%7D%20s'%2C%20'Slices%20per%20TR'%3A%20f'~%7B_n_slices%7D'%2C%20'BOLD%20sensitivity'%3A%20f%22%7B('Good'%20if%2025%20%3C%3D%20_te%20%3C%3D%2035%20else%20'Suboptimal')%7D%20(TE%3D%7B_te%7Dms)%22%2C%20'Readout%20duration'%3A%20f'~%7B_readout_time%3A.0f%7D%20ms'%7D%0A_fig%20%3D%20go.Figure()%0A_n_lines%20%3D%20_matrix%0A_kx_all%20%3D%20%5B%5D%0A_ky_all%20%3D%20%5B%5D%0A_colors%20%3D%20%5B%5D%0Afor%20_line%20in%20range(_n_lines)%3A%0A%20%20%20%20_y%20%3D%20_line%20%2F%20_n_lines%20-%200.5%0A%20%20%20%20if%20_line%20%25%202%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20_kx_all.extend(%5B-0.5%2C%200.5%2C%20None%5D)%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20_kx_all.extend(%5B0.5%2C%20-0.5%2C%20None%5D)%0A%20%20%20%20_ky_all.extend(%5B_y%2C%20_y%2C%20None%5D)%0A_fig.add_trace(go.Scatter(x%3D_kx_all%2C%20y%3D_ky_all%2C%20mode%3D'lines'%2C%20line%3Ddict(color%3D'%23636EFA'%2C%20width%3Dmax(0.5%2C%203%20-%20_n_lines%20%2F%2040))%2C%20name%3Df'%7B_matrix%7D%20PE%20lines'))%0A_fig.update_layout(title%3Df'EPI%20Trajectory%20(%7B_matrix%7D%20lines)'%2C%20xaxis_title%3D'kx'%2C%20yaxis_title%3D'ky'%2C%20xaxis%3Ddict(range%3D%5B-0.6%2C%200.6%5D)%2C%20yaxis%3Ddict(range%3D%5B-0.6%2C%200.6%5D%2C%20scaleanchor%3D'x')%2C%20width%3D350%2C%20height%3D350%2C%20margin%3Ddict(l%3D50%2C%20r%3D10%2C%20t%3D35%2C%20b%3D40))%0A_table_md%20%3D%20'%7C%20Parameter%20%7C%20Value%20%7C%5Cn%7C-----------%7C-------%7C%5Cn'%0Afor%20_k%2C%20_v%20in%20_metrics.items()%3A%0A%20%20%20%20_table_md%20%2B%3D%20f'%7C%20%7B_k%7D%20%7C%20%7B_v%7D%20%7C%5Cn'%0Amo.vstack(%5Bmo.hstack(%5Bepi_tr_slider%2C%20epi_te_slider%2C%20epi_matrix_slider%5D%2C%20justify%3D'start'%2C%20gap%3D2)%2C%20mo.hstack(%5B_fig%2C%20mo.md(_table_md)%5D%2C%20justify%3D'center')%2C%20mo.callout(mo.md('**Key%20tradeoffs%20in%20fMRI%3A**%5Cn-%20**Larger%20matrix**%20%E2%86%92%20better%20spatial%20resolution%20but%20slower%20readout%2C%20more%20distortion%5Cn-%20**Shorter%20TR**%20%E2%86%92%20better%20temporal%20resolution%20but%20fewer%20slices%5Cn-%20**TE%20~30ms%20at%203T**%20%E2%86%92%20optimal%20BOLD%20sensitivity%20(matches%20T%E2%82%82*%20of%20gray%20matter%20~40-50ms)%5Cn-%20Modern%20**multiband%2Fsimultaneous%20multi-slice**%20techniques%20can%20excite%20multiple%20slices%20at%20once%2C%20allowing%20sub-second%20whole-brain%20TR%20with%20good%20resolution')%2C%20kind%3D'warn')%5D)
mo.md(%22%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%2017.%20Putting%20It%20All%20Together%3A%20From%20Proton%20to%20Activation%20Map%5Cn%5Cn%20%20%20%20Let's%20trace%20the%20complete%20chain%20from%20physics%20to%20functional%20brain%20imaging%3A%5Cn%5Cn%20%20%20%20%60%60%60%5Cn%20%20%20%20Strong%20magnetic%20field%20(B%E2%82%80)%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20Protons%20align%20%E2%86%92%20net%20magnetization%20(M%E2%82%80)%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20RF%20pulse%20at%20Larmor%20frequency%20%E2%86%92%20tips%20M%20into%20transverse%20plane%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20Precessing%20Mxy%20induces%20signal%20in%20coil%20(FID)%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20Gradients%20encode%20spatial%20position%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20Raw%20signal%20fills%20k-space%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%202D%20Inverse%20FFT%20%E2%86%92%20image%20for%20each%20slice%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20Repeat%20with%20T%E2%82%82*-weighted%20GRE-EPI%20every%20~1s%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20BOLD%20signal%20changes%20reflect%20neural%20activity%20(via%20hemodynamics)%5Cn%20%20%20%20%20%20%20%20%E2%94%82%5Cn%20%20%20%20%20%20%20%20%E2%96%BC%5Cn%20%20%20%20Statistical%20analysis%20(GLM)%20%E2%86%92%20activation%20maps%5Cn%20%20%20%20%60%60%60%5Cn%5Cn%20%20%20%20**What%20we%20gain%3A**%5Cn%20%20%20%20-%20Non-invasive%20measurement%20of%20brain%20activity%5Cn%20%20%20%20-%20Whole-brain%20coverage%5Cn%20%20%20%20-%20Reasonable%20spatial%20resolution%20(~2-3mm)%5Cn%20%20%20%20-%20No%20ionizing%20radiation%20(unlike%20PET%2FCT)%5Cn%5Cn%20%20%20%20**What%20we%20lose%20%2F%20must%20be%20aware%20of%3A**%5Cn%20%20%20%20-%20Temporal%20resolution%20is%20limited%20(~seconds%2C%20not%20milliseconds)%5Cn%20%20%20%20-%20BOLD%20is%20an%20*indirect*%20measure%20of%20neural%20activity%5Cn%20%20%20%20-%20Signal%20can%20be%20affected%20by%20head%20motion%2C%20physiological%20noise%2C%5Cn%20%20%20%20%20%20susceptibility%20artifacts%20(especially%20near%20sinuses%20and%20ear%20canals)%5Cn%20%20%20%20-%20The%20hemodynamic%20response%20varies%20across%20brain%20regions%20and%20individuals%5Cn%5Cn%20%20%20%20These%20limitations%20--%20and%20how%20to%20address%20them%20--%20are%20covered%20in%20the%5Cn%20%20%20%20subsequent%20Dartbrains%20chapters%20on%20preprocessing%2C%20the%20GLM%2C%20and%5Cn%20%20%20%20statistical%20analysis.%5Cn%20%20%20%20%22)
mo.md('%5Cn%20%20%20%20---%5Cn%20%20%20%20%23%23%20Summary%5Cn%5Cn%20%20%20%20%7C%20Topic%20%7C%20Key%20Concepts%20%7C%5Cn%20%20%20%20%7C-------%7C-------------%7C%5Cn%20%20%20%20%7C%20**Magnetism%20%26%20Resonance**%20%7C%20B%E2%82%80%20alignment%2C%20precession%2C%20Larmor%20equation%2C%20RF%20excitation%2C%20FID%20%7C%5Cn%20%20%20%20%7C%20**Signal%20%26%20Contrast**%20%7C%20T%E2%82%81%2FT%E2%82%82%20relaxation%2C%20Bloch%20equations%2C%20TE%2FTR%20contrast%2C%20spin%20echo%20vs%20gradient%20echo%20%7C%5Cn%20%20%20%20%7C%20**Imaging%20%26%20fMRI**%20%7C%20Gradients%2C%20spatial%20encoding%2C%20k-space%2C%20BOLD%20signal%2C%20HRF%2C%20EPI%20%7C%5Cn%5Cn%20%20%20%20These%20concepts%20form%20the%20foundation%20for%20everything%20else%20in%20neuroimaging.%5Cn%20%20%20%20Understanding%20*why*%20the%20signal%20looks%20the%20way%20it%20does%20--%20and%20*what%20can%20go%5Cn%20%20%20%20wrong*%20--%20is%20essential%20for%20designing%20good%20experiments%2C%20preprocessing%20data%5Cn%20%20%20%20correctly%2C%20and%20interpreting%20results%20with%20appropriate%20caution.%5Cn%5Cn%20%20%20%20**Continue%20your%20learning%3A**%20The%20subsequent%20Dartbrains%20chapters%20cover%5Cn%20%20%20%20signal%20processing%2C%20preprocessing%20with%20fMRIPrep%2C%20the%20General%20Linear%20Model%2C%5Cn%20%20%20%20group%20analysis%2C%20and%20multivariate%20pattern%20analysis.%5Cn%20%20%20%20')