We present numerical simulations and experimental results of the self-modulation of a long proton bunch in a plasma with linear density gradients along the beam path. Simulation results agree with the experimental results reported in arXiv:2007.14894v2: with negative gradients, the charge of the modulated bunch is lower than with positive gradients. In addition, the bunch modulation frequency varies with gradient. Simulation results show that dephasing of the wakefields with respect to the relativistic protons along the plasma is the main cause for the loss of charge. The study of the modulation frequency reveals details about the evolution of the self-modulation process along the plasma. In particular for negative gradients, the modulation frequency across time-resolved images of the bunch indicates the position along the plasma where protons leave the wakefields. Simulations and experimental results are in excellent agreement.