Strange Behavior in Spring Computer Model

To learn more about oscillatory motion which I am learning about in my high school physics class, I have created a computer model of a damped spring where the damping force is proportional to velocity. The graph of position vs time appears as expected, a sine wave with amplitude decaying over the course of time.

I was interested in seeing the curve encompassing the peaks of the graph (the green line in this image). To do so, I created a new column in Excel which calculated the total energy of the system using the values of position and velocity the computer program outputted, then expressed that energy as a displacement from equilibrium using x = sqrt(2E/k).

When I graphed the results, I expected to see a smooth curve. However, I instead saw strange curves in between each peak: .

I am somewhat unsure about the origin of these. Should the "total energy" curve (the red one; although this isn't truly the energy) flatten out at each point at which the velocity equals zero in the real world? Or was my assumption that damping force is proportional to velocity a faulty one? If the latter is true, what would be a more accurate method of representing the damping force?

is not the total energy but rather the envelope of the position: if the displacement goes as $$x(t)=e^{-\gamma t}\cos(\omega t),$$ the green line is the function $e^{-\gamma t}$. As you have observed, this is not proportional to the decay in total energy, though it will approach it in the adiabatic limit $\gamma/\omega\ll1$, as you can see by calculating the analytic expression for the total energy.