update week 43
This commit is contained in:
@@ -366,225 +366,7 @@ We rather code the convolutions in the minimal memory footprint that they requir
|
||||
|
||||
Does the number of floating point operations change here when we use the commutative property?
|
||||
|
||||
!split
|
||||
===== Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms) =====
|
||||
|
||||
For problems with so-called harmonic oscillations, given by for example the following differential equation
|
||||
!bt
|
||||
\[
|
||||
m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t),
|
||||
\]
|
||||
!et
|
||||
where $F(t)$ is an applied external force acting on the system (often called a driving force), one can use the theory of Fourier transformations to find the solutions of this type of equations.
|
||||
|
||||
If one has several driving forces, $F(t)=\sum_n F_n(t)$, one can find
|
||||
the particular solution to each $F_n$, $x_{pn}(t)$, and the particular
|
||||
solution for the entire driving force is then given by a series like
|
||||
|
||||
!bt
|
||||
\begin{equation}
|
||||
x_p(t)=\sum_nx_{pn}(t).
|
||||
\end{equation}
|
||||
!et
|
||||
|
||||
!split
|
||||
===== Principle of Superposition =====
|
||||
|
||||
This is known as the principle of superposition. It only applies when
|
||||
the homogenous equation is linear. If there were an anharmonic term
|
||||
such as $x^3$ in the homogenous equation, then when one summed various
|
||||
solutions, $x=(\sum_n x_n)^2$, one would get cross
|
||||
terms. Superposition is especially useful when $F(t)$ can be written
|
||||
as a sum of sinusoidal terms, because the solutions for each
|
||||
sinusoidal (sine or cosine) term is analytic.
|
||||
|
||||
Driving forces are often periodic, even when they are not
|
||||
sinusoidal. Periodicity implies that for some time $\tau$
|
||||
|
||||
!bt
|
||||
\begin{eqnarray}
|
||||
F(t+\tau)=F(t).
|
||||
\end{eqnarray}
|
||||
!et
|
||||
|
||||
One example of a non-sinusoidal periodic force is a square wave. Many
|
||||
components in electric circuits are non-linear, e.g. diodes, which
|
||||
makes many wave forms non-sinusoidal even when the circuits are being
|
||||
driven by purely sinusoidal sources.
|
||||
|
||||
!split
|
||||
===== Simple Code Example =====
|
||||
|
||||
The code here shows a typical example of such a square wave generated using the functionality included in the _scipy_ Python package. We have used a period of $\tau=0.2$.
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import math
|
||||
from scipy import signal
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# number of points
|
||||
n = 500
|
||||
# start and final times
|
||||
t0 = 0.0
|
||||
tn = 1.0
|
||||
# Period
|
||||
t = np.linspace(t0, tn, n, endpoint=False)
|
||||
SqrSignal = np.zeros(n)
|
||||
SqrSignal = 1.0+signal.square(2*np.pi*5*t)
|
||||
plt.plot(t, SqrSignal)
|
||||
plt.ylim(-0.5, 2.5)
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
|
||||
For the sinusoidal example the
|
||||
period is $\tau=2\pi/\omega$. However, higher harmonics can also
|
||||
satisfy the periodicity requirement. In general, any force that
|
||||
satisfies the periodicity requirement can be expressed as a sum over
|
||||
harmonics,
|
||||
|
||||
!bt
|
||||
\begin{equation}
|
||||
F(t)=\frac{f_0}{2}+\sum_{n>0} f_n\cos(2n\pi t/\tau)+g_n\sin(2n\pi t/\tau).
|
||||
\end{equation}
|
||||
!et
|
||||
|
||||
!split
|
||||
===== Wrapping up Fourier transforms =====
|
||||
|
||||
We can write down the answer for
|
||||
$x_{pn}(t)$, by substituting $f_n/m$ or $g_n/m$ for $F_0/m$. By
|
||||
writing each factor $2n\pi t/\tau$ as $n\omega t$, with $\omega\equiv
|
||||
2\pi/\tau$,
|
||||
|
||||
!bt
|
||||
\begin{equation}
|
||||
label{eq:fourierdef1}
|
||||
F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t).
|
||||
\end{equation}
|
||||
!et
|
||||
|
||||
The solutions for $x(t)$ then come from replacing $\omega$ with
|
||||
$n\omega$ for each term in the particular solution,
|
||||
|
||||
!bt
|
||||
\begin{eqnarray}
|
||||
x_p(t)&=&\frac{f_0}{2k}+\sum_{n>0} \alpha_n\cos(n\omega t-\delta_n)+\beta_n\sin(n\omega t-\delta_n),\\
|
||||
\nonumber
|
||||
\alpha_n&=&\frac{f_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\
|
||||
\nonumber
|
||||
\beta_n&=&\frac{g_n/m}{\sqrt{((n\omega)^2-\omega_0^2)+4\beta^2n^2\omega^2}},\\
|
||||
\nonumber
|
||||
\delta_n&=&\tan^{-1}\left(\frac{2\beta n\omega}{\omega_0^2-n^2\omega^2}\right).
|
||||
\end{eqnarray}
|
||||
!et
|
||||
|
||||
!split
|
||||
===== Finding the Coefficients =====
|
||||
|
||||
Because the forces have been applied for a long time, any non-zero
|
||||
damping eliminates the homogenous parts of the solution, so one need
|
||||
only consider the particular solution for each $n$.
|
||||
|
||||
The problem is considered solved if one can find expressions for the
|
||||
coefficients $f_n$ and $g_n$, even though the solutions are expressed
|
||||
as an infinite sum. The coefficients can be extracted from the
|
||||
function $F(t)$ by
|
||||
|
||||
!bt
|
||||
\begin{eqnarray}
|
||||
label{eq:fourierdef2}
|
||||
f_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\cos(2n\pi t/\tau),\\
|
||||
\nonumber
|
||||
g_n&=&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~F(t)\sin(2n\pi t/\tau).
|
||||
\end{eqnarray}
|
||||
!et
|
||||
|
||||
To check the consistency of these expressions and to verify
|
||||
Eq. (ref{eq:fourierdef2}), one can insert the expansion of $F(t)$ in
|
||||
Eq. (ref{eq:fourierdef1}) into the expression for the coefficients in
|
||||
Eq. (ref{eq:fourierdef2}) and see whether
|
||||
|
||||
!bt
|
||||
\begin{eqnarray}
|
||||
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~\left\{
|
||||
\frac{f_0}{2}+\sum_{m>0}f_m\cos(m\omega t)+g_m\sin(m\omega t)
|
||||
\right\}\cos(n\omega t).
|
||||
\end{eqnarray}
|
||||
!et
|
||||
|
||||
Immediately, one can throw away all the terms with $g_m$ because they
|
||||
convolute an even and an odd function. The term with $f_0/2$
|
||||
disappears because $\cos(n\omega t)$ is equally positive and negative
|
||||
over the interval and will integrate to zero. For all the terms
|
||||
$f_m\cos(m\omega t)$ appearing in the sum, one can use angle addition
|
||||
formulas to see that $\cos(m\omega t)\cos(n\omega
|
||||
t)=(1/2)(\cos[(m+n)\omega t]+\cos[(m-n)\omega t]$. This will integrate
|
||||
to zero unless $m=n$. In that case the $m=n$ term gives
|
||||
|
||||
!bt
|
||||
\begin{equation}
|
||||
\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2},
|
||||
\end{equation}
|
||||
!et
|
||||
|
||||
and
|
||||
|
||||
!bt
|
||||
\begin{eqnarray}
|
||||
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\
|
||||
\nonumber
|
||||
&=&f_n~\checkmark.
|
||||
\end{eqnarray}
|
||||
!et
|
||||
|
||||
The same method can be used to check for the consistency of $g_n$.
|
||||
|
||||
|
||||
|
||||
!split
|
||||
===== Final words on Fourier Transforms =====
|
||||
|
||||
The code here uses the Fourier series applied to a
|
||||
square wave signal. The code here
|
||||
visualizes the various approximations given by Fourier series compared
|
||||
with a square wave with period $T=0.2$ (dimensionless time), width $0.1$ and max value of the force $F=2$. We
|
||||
see that when we increase the number of components in the Fourier
|
||||
series, the Fourier series approximation gets closer and closer to the
|
||||
square wave signal.
|
||||
|
||||
!bc pycod
|
||||
import numpy as np
|
||||
import math
|
||||
from scipy import signal
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# number of points
|
||||
n = 500
|
||||
# start and final times
|
||||
t0 = 0.0
|
||||
tn = 1.0
|
||||
# Period
|
||||
T =0.2
|
||||
# Max value of square signal
|
||||
Fmax= 2.0
|
||||
# Width of signal
|
||||
Width = 0.1
|
||||
t = np.linspace(t0, tn, n, endpoint=False)
|
||||
SqrSignal = np.zeros(n)
|
||||
FourierSeriesSignal = np.zeros(n)
|
||||
SqrSignal = 1.0+signal.square(2*np.pi*5*t+np.pi*Width/T)
|
||||
a0 = Fmax*Width/T
|
||||
FourierSeriesSignal = a0
|
||||
Factor = 2.0*Fmax/np.pi
|
||||
for i in range(1,500):
|
||||
FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*2*np.pi/T)
|
||||
plt.plot(t, SqrSignal)
|
||||
plt.plot(t, FourierSeriesSignal)
|
||||
plt.ylim(-0.5, 2.5)
|
||||
plt.show()
|
||||
!ec
|
||||
|
||||
|
||||
!split
|
||||
|
||||
Reference in New Issue
Block a user