Grid Cell Demo 03: From Grid Cells to fMRI Hexadirectional Signal

May 14, 2026·
Shaoyang Cui
Shaoyang Cui
· 2 min read

This demo now focuses only on voxel-level fMRI outputs and decoding.

Core intuition:

  1. Within one voxel, many cells with different spatial phases can reduce position-locked map contrast after averaging.
  2. But if local cells share a similar grid orientation $\phi$, the six-fold directional term can survive at population level.
  3. After HRF convolution, we can still decode hexadirectional structure from BOLD.

Decoding protocol in this page:

  1. Use first half of time points as training data.
  2. Fit $\cos(6\theta)$ and $\sin(6\theta)$ GLM terms to estimate population $\hat\phi$.
  3. Use second half as test data.
  4. Build test regressor $\cos(6(\theta-\hat\phi))$ and estimate test $\beta_{\text{hex}}$.
  5. Compare recovered $\hat\phi$ against ground-truth $\phi$ (modulo 60 degrees).
  6. Visualize aligned vs misaligned bins and directional preference on a 360-degree polar plot.

You can customize:

  • voxel cell count
  • initial phase distribution
  • HRF kernel
  • signal/noise settings
  • trajectory length

and inspect how recovery quality changes.

Voxel-level fMRI simulation + decoding. We generate synthetic Right EC BOLD with a forward HRF, then decode hexadirectional structure with a GLM that uses a potentially different decode HRF on regressors.

Forward HRF Kernel

Decode HRF Kernel

phi true / phi estimated0.0 deg / 0.0 deg
phi error (mod 60)0.00 deg
beta_hex train0.000
beta_hex test0.000
aligned - misaligned (test)0.000
cv setupleave-one-run-out

BOLD and Decoded Predictor

Aligned vs Misaligned Bins (Test)

Cell Orientation: Ground Truth vs Decoded

Folded 60 deg Profile