How to determine the instantaneous head direction by a population vector scheme?

The excerpt note is from the Song et al., 2005 paper. The example code is implemented by Fangwen. The whole example code is here.

Pengcheng Song, and Xiao-Jing Wang. “Angular path integration by moving “hill of activity”: a spiking neuron model without recurrent excitation of the head-direction system.” Journal of Neuroscience 25, no. 4 (2005): 1002-1014.

In the model, the peak location of the bell-shaped activity profile of the excitatory population provides a natural choice of the internal representation of the animal’s instantaneous head direction. It was determined by a population vector scheme (Georgopoulos et al., 1986), as follows:

Where is the firing rate of neuron , of which the preferred direction is . When a “hill of activity” moves at a constant propagation speed, the latter was used as a natural internal representation of the animal’s angular head velocity (AHV).

Georgopoulos, Apostolos P., Andrew B. Schwartz, and Ronald E. Kettner. “Neuronal population coding of movement direction.” Science (1986): 1416-1419.

[value, z] = max(HDCELLS);
z_HDCELLS=zeros(1,HD_DIMENSION_THETA);
z_HDCELLS(HD_AVG_TH_WRAP(z:z+HD_CELLS_TO_AVG*2)) = HDCELLS(HD_AVG_TH_WRAP(z:z+HD_CELLS_TO_AVG*2));
out_theta = mod(atan2(sum(HD_TH_SUM_SIN_LOOKUP*(z_HDCELLS')), sum(HD_TH_SUM_COS_LOOKUP * (z_HDCELLS')))/HD_CELL_SIZE_THETA, HD_DIMENSION_THETA);