Skip to content

Instantly share code, notes, and snippets.

@raphaelvallat
Created March 13, 2018 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphaelvallat/e64c392fdf197ee7725c841444e0afb8 to your computer and use it in GitHub Desktop.
Save raphaelvallat/e64c392fdf197ee7725c841444e0afb8 to your computer and use it in GitHub Desktop.
Hemodynamic Response Function
# Thanks to http://www.jarrodmillman.com/rcsds/lectures/convolution_background.html
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gamma
def hrf(x):
""" Return values for HRF at given times """
# Gamma pdf for the peak
peak_values = gamma.pdf(x, 6)
# Gamma pdf for the undershoot
undershoot_values = gamma.pdf(x, 12)
# Combine them
values = peak_values - 0.35 * undershoot_values
# Scale max to 0.6
return values / np.max(values) * 0.6
# TR = Repetition Time
TR = 1.
# Time vector
x = np.arange(0, 30, TR)
# Start plot
fig, ax = plt.subplots()
ax.plot(x, hrf(x), 'darkslategrey', marker='o')
ax.set_xlabel('Time (s)')
ax.set_ylabel('HRF model of signal')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment