## Math
#### Matlab Transfer Function + Laplace
```
s = tf('s'); % define laplace variable
sysG = (3*s + 7)/(2*s^2+5*s+6) % transfer function
```
### LTI System
- **SISO**: Scalar Input, Scalar Output
- **Causal:** Output depends only on input up to that time
- **Linear**
- If $u(t)\to y(t)$, then $qu(t)\to qy(t)$
- If $u_{1}(t)\to y_{1}(t)$ and $u_{2}(t)\to y_{2}(t)$, then $u_{1}(t)+u_{2}(t) \to y_{1}(t)+y_{2}(t)$
- **Time Invariant**
- Shifting input in time shifts output correspondingly
### Unit Step
$
\underline{1}(t)=\begin{cases}
0 & \text{if }t<0 \\
1 & \text{if } t\geq0
\end{cases}
$
$
\underline{1}(t)= \int_{-\epsilon}^{\infty} \delta(t) \, dt
$
#### Step Response
```
t = 0:dt:t_max % time vector
y = step(sysG,t); % step response
plot(t,y); % plot step response
```
### Unit Impulse
$
\delta(t) = \begin{cases}
0 & \text{if }t\neq0 \\
\infty & \text{if } t=0
\end{cases}
$
$
\delta(t) = \frac{d}{dt} \underline{1}(t)
$
### Impulse Response Function
Response of the system to the input $u(t) = \delta(t)$
- Complete description of the system’s response to any input $u(t)$ given zero initial conditions
- $h(t)<0=0$ due to causality
- Integrate starting from $- \epsilon$, an infinitesimally small number
### Euler’s Equation
$
e^{\pm j \omega t} = \cos(\omega t) \pm j\sin(\omega t)
$
### Convolution
Integrates the impulse response function over any input
$
y(t) = \int_{-\epsilon}^{t}u(\tau)h(t-\tau)~ d\tau
$
### Fourier Transform
Convert a function from time domain to frequency domain
$
\int_{-\infty}^{\infty} f(t)e^{-j\omega t} \, dt \to F(\omega)
$
Doesn’t work when $f(t)$ doesn’t go to zero as $t\to \pm \infty$
[3b1b video](https://www.youtube.com/watch?v=spUNpyF58BY)
### Inverse Fourier Transform
$
f(t) = \int_{-\infty}^{\infty} F(\omega)e^{j\omega t} \, d\omega
$
## System Modeling
| | Mechanical | Electrical | Fluidic | Thermal |
| -------------------- | ------------------ | ------------------------- | ------------------------------------------ | ------------------------------------ |
| Force / Voltage | $F$, [N] | $V$, [V] | $\Delta P$ [Pa] | $\Delta T$ [K] |
| Velocity / Current | $v$, [m/s] | $I$, [A] | $Q$, [$\text{m}^{3}/\text{s}$] | $Q$, [J/s] |
| Inertia / Inductance | ${} F=m\dot{v} {}$ | $V=L \frac{dI}{dt}$ | ${} \Delta P = \frac{\rho L}{A}\dot{Q} {}$ | N/A |
| Damping / Resistance | ${} F=bv {}$ | ${} V=IR {}$ | ${} \Delta P=QR_{f} {}$ | $R = \frac{L}{kA}$ or $\frac{1}{hA}$ |
| Spring / Capacitance | $F=kx$ | ${} I=C \frac{dV}{dt} {}$ | $Q = \frac{A}{\rho g}\Delta \dot{P}$ | $Q=mc\Delta T$ |
## Laplace Transform
Convert a function from time domain to s-domain
$
L[f(t)] = \int_{-\epsilon}^{\infty}e^{-st}f(t) \,dt = F(s)
$
$s$ is a complex number which is a function of $\omega$:
$
s = \sigma + i\omega
$
$\sigma$ is chosen to make the transform converge ([steve brunton explanation](https://youtu.be/7UvtU75NXTg))
$\epsilon$ is a infinitesimally small number that ensures the bottom bound of the integral is zero
### Laplace Identities
![[Pasted image 20241007002201.png|400]]
### Common Laplace Transforms
![[Pasted image 20241007002227.png|400]]
![[Pasted image 20241009004708.png|400]]
$\begin{array}{l} \\
F(s) & & & f(t) \\
\frac{2\omega s}{(s^{2}+\omega^{2})^{2}}& & & t\sin\omega t \\
\frac{1}{(s+\alpha)^{2}} & & & te^{-\alpha t}\\
\frac{\omega}{s^{2}+\omega^{2}} & & & \sin\omega t\\
\frac{s}{s^{2}+\omega^{2}} & & & \cos\omega t\\
\frac{s+a}{(s+a)^{2}+b^{2}} & & & e^{-at}\cos bt \\
\frac{b}{(s+a)^{2}+b^{2}} & & & e^{-at}\sin bt \\
\frac{1}{s+a} & & & e^{-at} \\
\frac{1}{(s+a)^{2}} & & & te^{-at}
\end{array}$
### Harmonic Signals
Replace sinusoidal signal with difference of complex exponentials:
$
\sin(\omega t) = \frac{e^{i\omega t}-e^{-i\omega t}}{2i}
$
### Derivatives
$
L(\dot{f}) = sF(s) - f(-\epsilon)
$
(derivation via integration by parts)
Formulas exist for higher derivatives such as:
$
L(\ddot{f})=s^{2}F(s) - sf(-\epsilon) - \dot{f}(-\epsilon)
$
or more generally,
$
L(f^{m}(t))=s ^{m}F(s) - s ^{m-1}f(-\epsilon)-s ^{m-2}\dot{f}(-\epsilon)-\dots-f^{(m-1)}(-\epsilon)
$
If zero initial conditions, this generalizes to
$
L(\left( \frac{d}{dt} \right) ^{n}f~) = s^{n}F(s)
$
### Integrals
Similarly, by integration of parts, we have
$
L\left( \int_{-\epsilon}^{t} f(\tau) \, d\tau \right) = \frac{1}{s}F(s)
$
and nested integrals increase the negative power of s:
$
L\left( \iint f \right) = \frac{1}{s^{2}}F(s)
$
## Transfer Function
Convolution in the time domain is equivalent to multiplication in the $s$ domain
$
Y(s) = H(s)U(s)
$
$H(s)$ is a complete description of an LTI system given zero initial conditions
## Inverse Laplace Transforms
If $s$-domain gives us a sum of pure harmonics or exponentials, we can simply look up the inverse Laplace transforms for each part.
### Cover-Up Method
Taking the inverse of rational functions with partial fractions. The function
$
F(s) = K \frac{(s-z_{1})(s-z_{2})\dots(s-z_{m})}{(s-p_{1})(s-p_{2})\dots(s-p_{m})}
$
can be rewritten in the form
$
F(s) = \frac{C_{1}}{s-p_{1}} + \frac{C_{2}}{s-p_{2}} + \dots + \frac{C_{n}}{s-p_{n}}
$
For each $i$, multiply both sides by ${} s-p_{i} {}$ and let $s=p_{i}$ such that we are left with only
$
C_{i} = (s-p_{i})F(s)
$
Plugging in the coefficients and taking the inverse Laplace transform gives us
$
f(t) = \sum_{i=1}^{n}C_{i}e^{p_{i}t}
$
### Matlab Partial Fraction Expansion
```
num = conv([1 z1], [1 z2]); % numerator
den = conv([1 p1], [1 p2]); % denominator
[r,p,k] = residue(num,den); % residues
```
resulting in `r = [C1 C2 C3]` and `p = [p1 p2 p3]`
## Diff Eqs
### Final Value Theorem
If all poles of $sF(s)$ are in the left half of the $s$-plane, then
$
\lim_{ t \to \infty} f(t) = sF(0^{+})
$
### Initial Value Theorem
$
f(0^{+}) = \lim_{ s \to \infty } sF(s)
$
### Solving ODEs
$
m\ddot{y}(t) + by(t) + k = u(t)
$
1. Take Laplace transform of both sides and make sure to account for initial conditions:
$
\begin{align}
&L(\dot{f}) = sF(s) - f(0^{-}) \\
&L(\ddot{f})=s^{2}F(s) - sf(0^{-}) - \dot{f}(0^{-})
\end{align}
$
2. Solve for $Y(s)$
3. Partial fraction expansion via cover-up method or Matlab `residue` function
4. Take inverse Laplace transform of fraction components