I'm currently learning state space representations but I am really struggling with the concept. More specifically, I'm not seeing how the selection of state variables is made based off of an output and how the state variables are even related to begin with.
What exactly is our state vector equation doing and how is this related to the output?
$$ \dot{x} = A\,x + B\,u \\ y = C\,x + D\,u $$
The easiest way is to look at a simple example like a mass-spring-damper system with an external force $u$. The equation of motion is given by
$$m\ddot{x}+b\dot{x}+cx = u$$
Now, we want to translate this system into the state-space-representation by introducing the following substitutions $x = x_1$ and $\dot{x}=\dot{x}_1=x_2$. Note that this transformation is not unique. You could also choose $x=2x_1$. Using these substitutions we can write the equation of motion as
$$m\dot{x}_2+bx_2+cx_1=u.$$ Solving for $\dot{x}_2$ results in
$$\dot{x}_2 = -\dfrac c m x_1 - \dfrac b m x_2 +\dfrac{1}{m}u$$
Combining this equation with $\dot{x}_1=x_2$ results in a system of equations
$$\dot{x}_1=x_2$$ $$\dot{x}_2 = -\dfrac c m x_1 - \dfrac b m x_2 +\dfrac{1}{m}u$$
or in matrix representation using $\boldsymbol{x}=[x_1,x_2]^T$
$$\dot{\boldsymbol{x}}=\begin{bmatrix}0 & 1\\ -c/m & b/m \end{bmatrix}\boldsymbol{x} + \begin{bmatrix}0\\1/m \end{bmatrix}u.$$
The matrices in front of the state vector $\boldsymbol{x}$ and the control input vector $u$ are the $\boldsymbol{A}$ and $\boldsymbol{B}$ matrices. I hope this explains the system equation. The system equation describes the dynamics of the system given your control input.
In contrast to this, the output equation describes the measurement design of the system. Hence, it describes what you measure from the system. For example, if you say that you only measure the velocity of the mass then the output equation is given by
$$y=\dot{x}=x_2=[0,\,1]\boldsymbol{x}+[0]u.$$
If you measure other things you will get other output equations.