Simple harmonic motion (SHM)
Simple harmonic motion (SHM) is a type of sinusoidal oscillation of position. In SHM, the magnitude of acceleration of an object is directly proportional to its displacement from its equilibrium position (i.e. $$a\propto x$$).
A mass attached to a spring oscillating in the vertical plane undergoes simple harmonic motion.
The acceleration in SHM is negatively proportional to the displacement (i.e. $$\vecphy{a}\propto\vecphy{x}$$). This means that the acceleration and displacement are always in opposite directions.
Many macroscopic physical phenomena, such as the motion of a simple pendulum and molecular vibrations can be approximated as simple harmonic motions.
Regular oscillations easily described as SHM occur from the tiniest fluctuations to the movements of binary stars around their centres of mass.
Simple harmonic motion is periodic, which means that it has a fixed period and frequency. However, not all oscillations are periodic.
Nonperiodic oscillation refers to oscillation that has either no fixed period or no period at all.
Variable stars undergo oscillations in luminous intensity that are nonperiodic. A car moving in a straight line along a road undergoes nonperiodic motion.
The displacement $$(\vecphy{x})$$, velocity $$(\vecphy{v})$$ and acceleration $$(\vecphy{a})$$ of an object undergoing simple harmonic motion in terms of time $$(t)$$ are given by different sets of equations.
Like all kinematics equations, these can only be applied to linear motion with respect to a particular axis with a specified positive direction. This means that the quantities are represented as scalars, with negative signs to imply motion in the opposite direction.
When the motion begins from the equilibrium position (i.e. when $$t=0$$, $$x=0$$), the displacement function is a sine. When the motion begins from an extreme position (i.e. when $$t=0$$, $$x=\pm x_{0}$$), the displacement function is a cosine.
Equilibrium position  Positive extreme position  Negative extreme position 

$$$x=x_{0}\sin\omega t$$$  $$$x=x_{0}\cos\omega t$$$  $$$x=x_{0}\cos\omega t$$$ 
$$$v=\omega x_{0}\cos\omega t$$$  $$$v=\omega x_{0}\sin\omega t$$$  $$$v=\omega x_{0}\sin\omega t$$$ 
$$$a=\omega^{2}x_{0}\sin\omega t$$$  $$$a=\omega^{2}x_{0}\cos\omega t$$$  $$$a=\omega^{2}x_{0}\cos\omega t$$$ 
The difference in the equations reflects the fact that the cosine function is just a moved sine function (at $$t=0$$, the cosine function takes value 1 and the sine takes value 0).
$$x_{0}=$$maximum displacement; $$\omega=$$angular frequency.
The equations for the velocity $$(\vecphy{v})$$ and acceleration $$(\vecphy{a})$$ in terms of displacement $$(\vecphy{x})$$ can be derived from the equations in terms of equilibrium or extreme positions and the equation for displacement in terms of time ($$x=x_{0}\sin\omega t$$).
Like all kinematics equations, these can only be applied to linear motion with respect to a particular axis with a specified positive direction. This means that the quantities are represented as scalars, with negative signs to imply motion in the opposite direction.
$$$\begin{align*}v&=\pm\omega\sqrt{x_{0}^{2}x^{2}}\\a&=\omega^{2}x\end{align*}$$$The equation for acceleration is the defining equation for simple harmonic motion (showing the proportionality of $$a$$ and $$x$$).
Some remarks:

$$x$$ is and must always be smaller than $$x_{0}$$ for the velocity to be a real number.

The $$\pm$$ sign corresponds to the fact that the harmonic oscillator periodically changes direction, with velocities of the same magnitude but opposite directions occurring at the same displacement.

The minus sign in $$a=\omega^{2}x$$ stands for the fact that the oscillator strives to restore the equilibrium whenever the displacement is nonzero.
$$x_{0}=$$maximum displacement; $$\omega=$$angular frequency.
The potential energy $$(E_{\text{p}})$$ and kinetic energy $$(E_{\text{k}})$$ of an object undergoing simple harmonic motion vary in an opposing fashion.
When the potential energy of the object is maximal, its kinetic energy is minimal and when its kinetic energy is maximal, its potential energy is minimal.
The object has maximum kinetic energy at maximum velocity (which occurs at the equilibrium point) and zero kinetic energy when its velocity is zero (which occurs at the amplitudes).
Similarly, the object has maximum potential energy at minimum velocity and minimum potential energy at maximum velocity.
The total energy $$(E_{\text{T}}=E_{\text{k}}+E_{\text{p}})$$ of an object undergoing simple harmonic motion is given by:$$$E=\frac{1}{2}m\omega^{2}x_{0}^{2}$$$The total energy of the system is thus conserved (i.e. the system is closed). The total energy is equivalent to the maximum kinetic or potential energy of the object.
The kinetic energy $$(E_{\text{k}})$$ and the potential energy $$(E_{\text{p}})$$ of an object undergoing simple harmonic motion in terms of time $$(t)$$ are given by different sets of equations.
When the motion begins from the equilibrium point (i.e. when $$t=0$$, $$x=0$$), $$v=\omega x_{0}\cos\omega t$$. When the motion begins from an extreme position (i.e. when $$t=0$$, $$x=\pm x_{0}$$), $$v=\mp\omega x_{0}\sin\omega t$$.
The expression for kinetic energy is obtained by plugging the equation for the velocity of a simple harmonic oscillator with respect to time in the kinetic energy equation (i.e. $$E_{\text{k}}=mv^{2}/2$$).
The expression for potential energy $$E_{p}$$ is determined by taking the total energy minus the kinetic energy (i.e. $$E_{\text{p}}=E_{\text{T}}E_{\text{k}}$$).
Equilibrium position  Positive extreme position  Negative extreme position  

$$v$$  $$\omega x_{0}\cos\omega t$$  $$\omega x_{0}\sin\omega t$$  $$\omega x_{0}\sin\omega t$$ 
$$E_{\text{k}}$$  $$\frac{1}{2}m\omega^{2}x_{0}^{2}\cos^{2}\omega t$$  $$\frac{1}{2}m\omega^{2}x_{0}^{2}\sin^{2}\omega t$$  $$\frac{1}{2}m\omega^{2}x_{0}^{2}\sin^{2}\omega t$$ 
$$E_{\text{p}}$$  $$\frac{1}{2}m\omega^{2}x_{0}^{2}\sin^{2}\omega t$$  $$\frac{1}{2}m\omega^{2}x_{0}^{2}\cos^{2}\omega t$$  $$\frac{1}{2}m\omega^{2}x_{0}^{2}\cos^{2}\omega t$$ 
The potential energy of a simple harmonic oscillator is made up of different types of energy or combinations thereof:
Elastic potential energy in the case of a springmass system
Gravitational potential energy in the case of a simple pendulum
$$m=$$mass of the object; $$x_{0}=$$maximum displacement; $$v=$$velocity of the object; $$\omega=$$angular frequency.
The kinetic energy $$(K)$$ and the potential energy $$(U)$$ in terms of displacement $$(x)$$ are derived from the equation for the velocity in terms of displacement ($$v=\pm\sqrt{x_{0}^{2}x^{2}}$$). This is given by:$$$\begin{align*}E_{\text{k}}&= \frac{1}{2}mv^{2}\\&=\frac{1}{2}m\omega^{2}(x_{0}^{2}x^{2})\\E_{\text{p}}&=E_{\text{T}} E_{\text{k}}\\&=\frac{1}{2}m\omega^{2}x^{2}\end{align*}$$$
Note that both energies are positive since $$x$$ is always smaller than $$x_{0}$$.
$$m=$$mass of the object; $$x_{0}=$$maximum displacement; $$\omega=$$angular frequency.