Energy in SHM
Consider a spring system $$ m\ddot x = -kx \implies x=a_0 \cos(\omega t+\phi), \quad \omega^2=\frac km. $$
Its potential energy is $$ U = \frac12 kx^2 = \frac12 ka_0^2\cos^2(\omega t+\phi) \implies \langle U\rangle = \frac14 ka_0^2. $$ Its kinetic energy is $$ K = \frac12 m\dot x^2 = \frac12 ma_0^2\omega^2\sin^2(\omega t+\phi) = \frac12 ka_0^2\sin^2(\omega t+\phi) \implies \langle K\rangle = \frac14 ka_0^2. $$ The total energy is conserved: $$ E = U+K = \frac12 ka_0^2. $$
When the total energy of the system is in the form $$ E = \frac12 \alpha \dot x^2 + \frac12 \beta x^2 $$ is conserved, the system is in simple harmonic motion with angular frequency $$ \omega = \sqrt{\frac\beta\alpha}. $$ (Derivation)