Grid cell spatial period is thought to be dictated by a mapping between the speed-direction modulated excitatory inputs, and consequent modulation of the firing rate, yet, the exact underlying mechanisms are not known. Here, through experiments on the medial entorhinal cortex stellate cells, subjected to in-vivo like stochastic synaptic activity through the dynamic clamp, we show that such mapping can emerge from a theta-frequency resonance in the signal gain, which is HCN sensitive, robust to noise, and is potent enough to modulate the synaptic responses in the theta frequency. This modulation also extends to the corresponding theta-gamma modulation of the firing rate, the slope of whose excitation mediated increase is steeper in the presence of HCN channels. We also show that in the cells devoid of HCN channels, inhibition can emulate their role. Considering the dorso-ventral gradients of HCN and inhibition, which are present aligned to the grid spacing gradient in the medial entorhinal cortex, these findings should be noteworthy.