update week 43
This commit is contained in:
@@ -74,25 +74,6 @@ doconce format html week43.do.txt --html_style=bootstrap --pygments_html_style=d
|
||||
2,
|
||||
None,
|
||||
'a-more-efficient-way-of-coding-the-above-convolution'),
|
||||
('Convolution Examples: Principle of Superposition and Periodic '
|
||||
'Forces (Fourier Transforms)',
|
||||
2,
|
||||
None,
|
||||
'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'),
|
||||
('Principle of Superposition',
|
||||
2,
|
||||
None,
|
||||
'principle-of-superposition'),
|
||||
('Simple Code Example', 2, None, 'simple-code-example'),
|
||||
('Wrapping up Fourier transforms',
|
||||
2,
|
||||
None,
|
||||
'wrapping-up-fourier-transforms'),
|
||||
('Finding the Coefficients', 2, None, 'finding-the-coefficients'),
|
||||
('Final words on Fourier Transforms',
|
||||
2,
|
||||
None,
|
||||
'final-words-on-fourier-transforms'),
|
||||
('Two-dimensional Objects', 2, None, 'two-dimensional-objects'),
|
||||
('Cross-Correlation', 2, None, 'cross-correlation'),
|
||||
('More on Dimensionalities', 2, None, 'more-on-dimensionalities'),
|
||||
@@ -233,12 +214,6 @@ MathJax.Hub.Config({
|
||||
<!-- navigation toc: --> <li><a href="#convolution-examples-polynomial-multiplication" style="font-size: 80%;">Convolution Examples: Polynomial multiplication</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#efficient-polynomial-multiplication" style="font-size: 80%;">Efficient Polynomial Multiplication</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#a-more-efficient-way-of-coding-the-above-convolution" style="font-size: 80%;">A more efficient way of coding the above Convolution</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms" style="font-size: 80%;">Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#principle-of-superposition" style="font-size: 80%;">Principle of Superposition</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#simple-code-example" style="font-size: 80%;">Simple Code Example</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#wrapping-up-fourier-transforms" style="font-size: 80%;">Wrapping up Fourier transforms</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#finding-the-coefficients" style="font-size: 80%;">Finding the Coefficients</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#final-words-on-fourier-transforms" style="font-size: 80%;">Final words on Fourier Transforms</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#two-dimensional-objects" style="font-size: 80%;">Two-dimensional Objects</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#cross-correlation" style="font-size: 80%;">Cross-Correlation</a></li>
|
||||
<!-- navigation toc: --> <li><a href="#more-on-dimensionalities" style="font-size: 80%;">More on Dimensionalities</a></li>
|
||||
@@ -311,7 +286,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Oct 26, 2022</h4>
|
||||
<h4>Oct 27, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -712,279 +687,6 @@ We rather code the convolutions in the minimal memory footprint that they requir
|
||||
|
||||
<p>Does the number of floating point operations change here when we use the commutative property?</p>
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms" class="anchor">Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms) </h2>
|
||||
|
||||
<p>For problems with so-called harmonic oscillations, given by for example the following differential equation</p>
|
||||
$$
|
||||
m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t),
|
||||
$$
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
x_p(t)=\sum_nx_{pn}(t).
|
||||
\label{_auto1}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="principle-of-superposition" class="anchor">Principle of Superposition </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<p>Driving forces are often periodic, even when they are not
|
||||
sinusoidal. Periodicity implies that for some time \( \tau \)
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
F(t+\tau)=F(t).
|
||||
\end{eqnarray}
|
||||
$$
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="simple-code-example" class="anchor">Simple Code Example </h2>
|
||||
|
||||
<p>The code here shows a typical example of such a square wave generated using the functionality included in the <b>scipy</b> Python package. We have used a period of \( \tau=0.2 \).</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">math</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> signal
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># number of points </span>
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
||||
<span style="color: #408080; font-style: italic"># start and final times </span>
|
||||
t0 <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
tn <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
||||
<span style="color: #408080; font-style: italic"># Period </span>
|
||||
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(t0, tn, n, endpoint<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
SqrSignal <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)
|
||||
SqrSignal <span style="color: #666666">=</span> <span style="color: #666666">1.0+</span>signal<span style="color: #666666">.</span>square(<span style="color: #666666">2*</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*5*</span>t)
|
||||
plt<span style="color: #666666">.</span>plot(t, SqrSignal)
|
||||
plt<span style="color: #666666">.</span>ylim(<span style="color: #666666">-0.5</span>, <span style="color: #666666">2.5</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>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,
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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).
|
||||
\label{_auto2}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="wrapping-up-fourier-transforms" class="anchor">Wrapping up Fourier transforms </h2>
|
||||
|
||||
<p>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 \),
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>The solutions for \( x(t) \) then come from replacing \( \omega \) with
|
||||
\( n\omega \) for each term in the particular solution,
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="finding-the-coefficients" class="anchor">Finding the Coefficients </h2>
|
||||
|
||||
<p>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 \).
|
||||
</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>To check the consistency of these expressions and to verify
|
||||
Eq. \eqref{eq:fourierdef2}, one can insert the expansion of \( F(t) \) in
|
||||
Eq. \eqref{eq:fourierdef1} into the expression for the coefficients in
|
||||
Eq. \eqref{eq:fourierdef2} and see whether
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2},
|
||||
\label{_auto3}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\
|
||||
\nonumber
|
||||
&=&f_n~\checkmark.
|
||||
\end{eqnarray}
|
||||
$$
|
||||
|
||||
<p>The same method can be used to check for the consistency of \( g_n \).</p>
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="final-words-on-fourier-transforms" class="anchor">Final words on Fourier Transforms </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">math</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> signal
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># number of points </span>
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
||||
<span style="color: #408080; font-style: italic"># start and final times </span>
|
||||
t0 <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
tn <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
||||
<span style="color: #408080; font-style: italic"># Period </span>
|
||||
T <span style="color: #666666">=0.2</span>
|
||||
<span style="color: #408080; font-style: italic"># Max value of square signal </span>
|
||||
Fmax<span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
|
||||
<span style="color: #408080; font-style: italic"># Width of signal </span>
|
||||
Width <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>
|
||||
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(t0, tn, n, endpoint<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
SqrSignal <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)
|
||||
FourierSeriesSignal <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)
|
||||
SqrSignal <span style="color: #666666">=</span> <span style="color: #666666">1.0+</span>signal<span style="color: #666666">.</span>square(<span style="color: #666666">2*</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*5*</span>t<span style="color: #666666">+</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>Width<span style="color: #666666">/</span>T)
|
||||
a0 <span style="color: #666666">=</span> Fmax<span style="color: #666666">*</span>Width<span style="color: #666666">/</span>T
|
||||
FourierSeriesSignal <span style="color: #666666">=</span> a0
|
||||
Factor <span style="color: #666666">=</span> <span style="color: #666666">2.0*</span>Fmax<span style="color: #666666">/</span>np<span style="color: #666666">.</span>pi
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">1</span>,<span style="color: #666666">500</span>):
|
||||
FourierSeriesSignal <span style="color: #666666">+=</span> Factor<span style="color: #666666">/</span>(i)<span style="color: #666666">*</span>np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>i<span style="color: #666666">*</span>Width<span style="color: #666666">/</span>T)<span style="color: #666666">*</span>np<span style="color: #666666">.</span>cos(i<span style="color: #666666">*</span>t<span style="color: #666666">*2*</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">/</span>T)
|
||||
plt<span style="color: #666666">.</span>plot(t, SqrSignal)
|
||||
plt<span style="color: #666666">.</span>plot(t, FourierSeriesSignal)
|
||||
plt<span style="color: #666666">.</span>ylim(<span style="color: #666666">-0.5</span>, <span style="color: #666666">2.5</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- !split -->
|
||||
<h2 id="two-dimensional-objects" class="anchor">Two-dimensional Objects </h2>
|
||||
|
||||
@@ -2483,7 +2185,7 @@ samples
|
||||
$$
|
||||
\begin{equation}
|
||||
x = g(z; \theta^{(g)})
|
||||
\label{_auto4}
|
||||
\label{_auto1}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2500,7 +2202,7 @@ value given by
|
||||
$$
|
||||
\begin{equation}
|
||||
d(x; \theta^{(d)})
|
||||
\label{_auto5}
|
||||
\label{_auto2}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2513,7 +2215,7 @@ which a function
|
||||
$$
|
||||
\begin{equation}
|
||||
v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto6}
|
||||
\label{_auto3}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2524,7 +2226,7 @@ conjugate reward
|
||||
$$
|
||||
\begin{equation}
|
||||
-v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto7}
|
||||
\label{_auto4}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2559,7 +2261,7 @@ $$
|
||||
\begin{equation}
|
||||
g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto8}
|
||||
\label{_auto5}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2569,7 +2271,7 @@ $$
|
||||
v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x)
|
||||
+ \mathbb{E}_{x\sim p_\mathrm{model}}
|
||||
\log (1 - d(x))
|
||||
\label{_auto9}
|
||||
\label{_auto6}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2580,7 +2282,7 @@ approximation of a partition function. In the case where
|
||||
$$
|
||||
\begin{equation}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto10}
|
||||
\label{_auto7}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Oct 26, 2022</h4>
|
||||
<h4>Oct 27, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -623,301 +623,6 @@ We rather code the convolutions in the minimal memory footprint that they requir
|
||||
<p>Does the number of floating point operations change here when we use the commutative property?</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms">Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms) </h2>
|
||||
|
||||
<p>For problems with so-called harmonic oscillations, given by for example the following differential equation</p>
|
||||
<p> <br>
|
||||
$$
|
||||
m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t),
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{equation}
|
||||
x_p(t)=\sum_nx_{pn}(t).
|
||||
\tag{1}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="principle-of-superposition">Principle of Superposition </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<p>Driving forces are often periodic, even when they are not
|
||||
sinusoidal. Periodicity implies that for some time \( \tau \)
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
F(t+\tau)=F(t).
|
||||
\end{eqnarray}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="simple-code-example">Simple Code Example </h2>
|
||||
|
||||
<p>The code here shows a typical example of such a square wave generated using the functionality included in the <b>scipy</b> Python package. We have used a period of \( \tau=0.2 \).</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="font-size: 80%; line-height: 125%;"><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">math</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> signal
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
<span style="color: #228B22"># number of points </span>
|
||||
n = <span style="color: #B452CD">500</span>
|
||||
<span style="color: #228B22"># start and final times </span>
|
||||
t0 = <span style="color: #B452CD">0.0</span>
|
||||
tn = <span style="color: #B452CD">1.0</span>
|
||||
<span style="color: #228B22"># Period </span>
|
||||
t = np.linspace(t0, tn, n, endpoint=<span style="color: #8B008B; font-weight: bold">False</span>)
|
||||
SqrSignal = np.zeros(n)
|
||||
SqrSignal = <span style="color: #B452CD">1.0</span>+signal.square(<span style="color: #B452CD">2</span>*np.pi*<span style="color: #B452CD">5</span>*t)
|
||||
plt.plot(t, SqrSignal)
|
||||
plt.ylim(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">2.5</span>)
|
||||
plt.show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>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,
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\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).
|
||||
\tag{2}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="wrapping-up-fourier-transforms">Wrapping up Fourier transforms </h2>
|
||||
|
||||
<p>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 \),
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{equation}
|
||||
\tag{3}
|
||||
F(t)=\frac{f_0}{2}+\sum_{n>0}f_n\cos(n\omega t)+g_n\sin(n\omega t).
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>The solutions for \( x(t) \) then come from replacing \( \omega \) with
|
||||
\( n\omega \) for each term in the particular solution,
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
<p> <br>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="finding-the-coefficients">Finding the Coefficients </h2>
|
||||
|
||||
<p>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 \).
|
||||
</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
\tag{4}
|
||||
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}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>To check the consistency of these expressions and to verify
|
||||
Eq. <a href="#mjx-eqn-4">(4)</a>, one can insert the expansion of \( F(t) \) in
|
||||
Eq. <a href="#mjx-eqn-3">(3)</a> into the expression for the coefficients in
|
||||
Eq. <a href="#mjx-eqn-4">(4)</a> and see whether
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{equation}
|
||||
\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2},
|
||||
\tag{5}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>and</p>
|
||||
|
||||
<p> <br>
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\
|
||||
\nonumber
|
||||
&=&f_n~\checkmark.
|
||||
\end{eqnarray}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
<p>The same method can be used to check for the consistency of \( g_n \).</p>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="final-words-on-fourier-transforms">Final words on Fourier Transforms </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="font-size: 80%; line-height: 125%;"><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">math</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> signal
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
<span style="color: #228B22"># number of points </span>
|
||||
n = <span style="color: #B452CD">500</span>
|
||||
<span style="color: #228B22"># start and final times </span>
|
||||
t0 = <span style="color: #B452CD">0.0</span>
|
||||
tn = <span style="color: #B452CD">1.0</span>
|
||||
<span style="color: #228B22"># Period </span>
|
||||
T =<span style="color: #B452CD">0.2</span>
|
||||
<span style="color: #228B22"># Max value of square signal </span>
|
||||
Fmax= <span style="color: #B452CD">2.0</span>
|
||||
<span style="color: #228B22"># Width of signal </span>
|
||||
Width = <span style="color: #B452CD">0.1</span>
|
||||
t = np.linspace(t0, tn, n, endpoint=<span style="color: #8B008B; font-weight: bold">False</span>)
|
||||
SqrSignal = np.zeros(n)
|
||||
FourierSeriesSignal = np.zeros(n)
|
||||
SqrSignal = <span style="color: #B452CD">1.0</span>+signal.square(<span style="color: #B452CD">2</span>*np.pi*<span style="color: #B452CD">5</span>*t+np.pi*Width/T)
|
||||
a0 = Fmax*Width/T
|
||||
FourierSeriesSignal = a0
|
||||
Factor = <span style="color: #B452CD">2.0</span>*Fmax/np.pi
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">1</span>,<span style="color: #B452CD">500</span>):
|
||||
FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*<span style="color: #B452CD">2</span>*np.pi/T)
|
||||
plt.plot(t, SqrSignal)
|
||||
plt.plot(t, FourierSeriesSignal)
|
||||
plt.ylim(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">2.5</span>)
|
||||
plt.show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 id="two-dimensional-objects">Two-dimensional Objects </h2>
|
||||
|
||||
@@ -2439,7 +2144,7 @@ samples
|
||||
$$
|
||||
\begin{equation}
|
||||
x = g(z; \theta^{(g)})
|
||||
\tag{6}
|
||||
\tag{1}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2458,7 +2163,7 @@ value given by
|
||||
$$
|
||||
\begin{equation}
|
||||
d(x; \theta^{(d)})
|
||||
\tag{7}
|
||||
\tag{2}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2473,7 +2178,7 @@ which a function
|
||||
$$
|
||||
\begin{equation}
|
||||
v(\theta^{(g)}, \theta^{(d)})
|
||||
\tag{8}
|
||||
\tag{3}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2486,7 +2191,7 @@ conjugate reward
|
||||
$$
|
||||
\begin{equation}
|
||||
-v(\theta^{(g)}, \theta^{(d)})
|
||||
\tag{9}
|
||||
\tag{4}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2524,7 +2229,7 @@ $$
|
||||
\begin{equation}
|
||||
g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\tag{10}
|
||||
\tag{5}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2536,7 +2241,7 @@ $$
|
||||
v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x)
|
||||
+ \mathbb{E}_{x\sim p_\mathrm{model}}
|
||||
\log (1 - d(x))
|
||||
\tag{11}
|
||||
\tag{6}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
@@ -2549,7 +2254,7 @@ approximation of a partition function. In the case where
|
||||
$$
|
||||
\begin{equation}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\tag{12}
|
||||
\tag{7}
|
||||
\end{equation}
|
||||
$$
|
||||
<p> <br>
|
||||
|
||||
@@ -101,25 +101,6 @@ div.toc p,a {
|
||||
2,
|
||||
None,
|
||||
'a-more-efficient-way-of-coding-the-above-convolution'),
|
||||
('Convolution Examples: Principle of Superposition and Periodic '
|
||||
'Forces (Fourier Transforms)',
|
||||
2,
|
||||
None,
|
||||
'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'),
|
||||
('Principle of Superposition',
|
||||
2,
|
||||
None,
|
||||
'principle-of-superposition'),
|
||||
('Simple Code Example', 2, None, 'simple-code-example'),
|
||||
('Wrapping up Fourier transforms',
|
||||
2,
|
||||
None,
|
||||
'wrapping-up-fourier-transforms'),
|
||||
('Finding the Coefficients', 2, None, 'finding-the-coefficients'),
|
||||
('Final words on Fourier Transforms',
|
||||
2,
|
||||
None,
|
||||
'final-words-on-fourier-transforms'),
|
||||
('Two-dimensional Objects', 2, None, 'two-dimensional-objects'),
|
||||
('Cross-Correlation', 2, None, 'cross-correlation'),
|
||||
('More on Dimensionalities', 2, None, 'more-on-dimensionalities'),
|
||||
@@ -247,7 +228,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Oct 26, 2022</h4>
|
||||
<h4>Oct 27, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -641,279 +622,6 @@ We rather code the convolutions in the minimal memory footprint that they requir
|
||||
|
||||
<p>Does the number of floating point operations change here when we use the commutative property?</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms">Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms) </h2>
|
||||
|
||||
<p>For problems with so-called harmonic oscillations, given by for example the following differential equation</p>
|
||||
$$
|
||||
m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t),
|
||||
$$
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
x_p(t)=\sum_nx_{pn}(t).
|
||||
\label{_auto1}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="principle-of-superposition">Principle of Superposition </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<p>Driving forces are often periodic, even when they are not
|
||||
sinusoidal. Periodicity implies that for some time \( \tau \)
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
F(t+\tau)=F(t).
|
||||
\end{eqnarray}
|
||||
$$
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="simple-code-example">Simple Code Example </h2>
|
||||
|
||||
<p>The code here shows a typical example of such a square wave generated using the functionality included in the <b>scipy</b> Python package. We have used a period of \( \tau=0.2 \).</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="line-height: 125%;"><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">math</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> signal
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
<span style="color: #228B22"># number of points </span>
|
||||
n = <span style="color: #B452CD">500</span>
|
||||
<span style="color: #228B22"># start and final times </span>
|
||||
t0 = <span style="color: #B452CD">0.0</span>
|
||||
tn = <span style="color: #B452CD">1.0</span>
|
||||
<span style="color: #228B22"># Period </span>
|
||||
t = np.linspace(t0, tn, n, endpoint=<span style="color: #8B008B; font-weight: bold">False</span>)
|
||||
SqrSignal = np.zeros(n)
|
||||
SqrSignal = <span style="color: #B452CD">1.0</span>+signal.square(<span style="color: #B452CD">2</span>*np.pi*<span style="color: #B452CD">5</span>*t)
|
||||
plt.plot(t, SqrSignal)
|
||||
plt.ylim(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">2.5</span>)
|
||||
plt.show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>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,
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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).
|
||||
\label{_auto2}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="wrapping-up-fourier-transforms">Wrapping up Fourier transforms </h2>
|
||||
|
||||
<p>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 \),
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>The solutions for \( x(t) \) then come from replacing \( \omega \) with
|
||||
\( n\omega \) for each term in the particular solution,
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="finding-the-coefficients">Finding the Coefficients </h2>
|
||||
|
||||
<p>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 \).
|
||||
</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>To check the consistency of these expressions and to verify
|
||||
Eq. \eqref{eq:fourierdef2}, one can insert the expansion of \( F(t) \) in
|
||||
Eq. \eqref{eq:fourierdef1} into the expression for the coefficients in
|
||||
Eq. \eqref{eq:fourierdef2} and see whether
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2},
|
||||
\label{_auto3}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\
|
||||
\nonumber
|
||||
&=&f_n~\checkmark.
|
||||
\end{eqnarray}
|
||||
$$
|
||||
|
||||
<p>The same method can be used to check for the consistency of \( g_n \).</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="final-words-on-fourier-transforms">Final words on Fourier Transforms </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #eeeedd">
|
||||
<pre style="line-height: 125%;"><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">math</span>
|
||||
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">scipy</span> <span style="color: #8B008B; font-weight: bold">import</span> signal
|
||||
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
|
||||
|
||||
<span style="color: #228B22"># number of points </span>
|
||||
n = <span style="color: #B452CD">500</span>
|
||||
<span style="color: #228B22"># start and final times </span>
|
||||
t0 = <span style="color: #B452CD">0.0</span>
|
||||
tn = <span style="color: #B452CD">1.0</span>
|
||||
<span style="color: #228B22"># Period </span>
|
||||
T =<span style="color: #B452CD">0.2</span>
|
||||
<span style="color: #228B22"># Max value of square signal </span>
|
||||
Fmax= <span style="color: #B452CD">2.0</span>
|
||||
<span style="color: #228B22"># Width of signal </span>
|
||||
Width = <span style="color: #B452CD">0.1</span>
|
||||
t = np.linspace(t0, tn, n, endpoint=<span style="color: #8B008B; font-weight: bold">False</span>)
|
||||
SqrSignal = np.zeros(n)
|
||||
FourierSeriesSignal = np.zeros(n)
|
||||
SqrSignal = <span style="color: #B452CD">1.0</span>+signal.square(<span style="color: #B452CD">2</span>*np.pi*<span style="color: #B452CD">5</span>*t+np.pi*Width/T)
|
||||
a0 = Fmax*Width/T
|
||||
FourierSeriesSignal = a0
|
||||
Factor = <span style="color: #B452CD">2.0</span>*Fmax/np.pi
|
||||
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">1</span>,<span style="color: #B452CD">500</span>):
|
||||
FourierSeriesSignal += Factor/(i)*np.sin(np.pi*i*Width/T)*np.cos(i*t*<span style="color: #B452CD">2</span>*np.pi/T)
|
||||
plt.plot(t, SqrSignal)
|
||||
plt.plot(t, FourierSeriesSignal)
|
||||
plt.ylim(-<span style="color: #B452CD">0.5</span>, <span style="color: #B452CD">2.5</span>)
|
||||
plt.show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="two-dimensional-objects">Two-dimensional Objects </h2>
|
||||
|
||||
@@ -2412,7 +2120,7 @@ samples
|
||||
$$
|
||||
\begin{equation}
|
||||
x = g(z; \theta^{(g)})
|
||||
\label{_auto4}
|
||||
\label{_auto1}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2429,7 +2137,7 @@ value given by
|
||||
$$
|
||||
\begin{equation}
|
||||
d(x; \theta^{(d)})
|
||||
\label{_auto5}
|
||||
\label{_auto2}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2442,7 +2150,7 @@ which a function
|
||||
$$
|
||||
\begin{equation}
|
||||
v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto6}
|
||||
\label{_auto3}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2453,7 +2161,7 @@ conjugate reward
|
||||
$$
|
||||
\begin{equation}
|
||||
-v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto7}
|
||||
\label{_auto4}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2488,7 +2196,7 @@ $$
|
||||
\begin{equation}
|
||||
g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto8}
|
||||
\label{_auto5}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2498,7 +2206,7 @@ $$
|
||||
v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x)
|
||||
+ \mathbb{E}_{x\sim p_\mathrm{model}}
|
||||
\log (1 - d(x))
|
||||
\label{_auto9}
|
||||
\label{_auto6}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2509,7 +2217,7 @@ approximation of a partition function. In the case where
|
||||
$$
|
||||
\begin{equation}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto10}
|
||||
\label{_auto7}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
@@ -178,25 +178,6 @@ div.toc p,a {
|
||||
2,
|
||||
None,
|
||||
'a-more-efficient-way-of-coding-the-above-convolution'),
|
||||
('Convolution Examples: Principle of Superposition and Periodic '
|
||||
'Forces (Fourier Transforms)',
|
||||
2,
|
||||
None,
|
||||
'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'),
|
||||
('Principle of Superposition',
|
||||
2,
|
||||
None,
|
||||
'principle-of-superposition'),
|
||||
('Simple Code Example', 2, None, 'simple-code-example'),
|
||||
('Wrapping up Fourier transforms',
|
||||
2,
|
||||
None,
|
||||
'wrapping-up-fourier-transforms'),
|
||||
('Finding the Coefficients', 2, None, 'finding-the-coefficients'),
|
||||
('Final words on Fourier Transforms',
|
||||
2,
|
||||
None,
|
||||
'final-words-on-fourier-transforms'),
|
||||
('Two-dimensional Objects', 2, None, 'two-dimensional-objects'),
|
||||
('Cross-Correlation', 2, None, 'cross-correlation'),
|
||||
('More on Dimensionalities', 2, None, 'more-on-dimensionalities'),
|
||||
@@ -324,7 +305,7 @@ MathJax.Hub.Config({
|
||||
</center>
|
||||
<br>
|
||||
<center>
|
||||
<h4>Oct 26, 2022</h4>
|
||||
<h4>Oct 27, 2022</h4>
|
||||
</center> <!-- date -->
|
||||
<br>
|
||||
|
||||
@@ -718,279 +699,6 @@ We rather code the convolutions in the minimal memory footprint that they requir
|
||||
|
||||
<p>Does the number of floating point operations change here when we use the commutative property?</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms">Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms) </h2>
|
||||
|
||||
<p>For problems with so-called harmonic oscillations, given by for example the following differential equation</p>
|
||||
$$
|
||||
m\frac{d^2x}{dt^2}+\eta\frac{dx}{dt}+x(t)=F(t),
|
||||
$$
|
||||
|
||||
<p>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.</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
x_p(t)=\sum_nx_{pn}(t).
|
||||
\label{_auto1}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="principle-of-superposition">Principle of Superposition </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<p>Driving forces are often periodic, even when they are not
|
||||
sinusoidal. Periodicity implies that for some time \( \tau \)
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
F(t+\tau)=F(t).
|
||||
\end{eqnarray}
|
||||
$$
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="simple-code-example">Simple Code Example </h2>
|
||||
|
||||
<p>The code here shows a typical example of such a square wave generated using the functionality included in the <b>scipy</b> Python package. We have used a period of \( \tau=0.2 \).</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">math</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> signal
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># number of points </span>
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
||||
<span style="color: #408080; font-style: italic"># start and final times </span>
|
||||
t0 <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
tn <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
||||
<span style="color: #408080; font-style: italic"># Period </span>
|
||||
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(t0, tn, n, endpoint<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
SqrSignal <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)
|
||||
SqrSignal <span style="color: #666666">=</span> <span style="color: #666666">1.0+</span>signal<span style="color: #666666">.</span>square(<span style="color: #666666">2*</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*5*</span>t)
|
||||
plt<span style="color: #666666">.</span>plot(t, SqrSignal)
|
||||
plt<span style="color: #666666">.</span>ylim(<span style="color: #666666">-0.5</span>, <span style="color: #666666">2.5</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p>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,
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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).
|
||||
\label{_auto2}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="wrapping-up-fourier-transforms">Wrapping up Fourier transforms </h2>
|
||||
|
||||
<p>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 \),
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>The solutions for \( x(t) \) then come from replacing \( \omega \) with
|
||||
\( n\omega \) for each term in the particular solution,
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="finding-the-coefficients">Finding the Coefficients </h2>
|
||||
|
||||
<p>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 \).
|
||||
</p>
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>To check the consistency of these expressions and to verify
|
||||
Eq. \eqref{eq:fourierdef2}, one can insert the expansion of \( F(t) \) in
|
||||
Eq. \eqref{eq:fourierdef1} into the expression for the coefficients in
|
||||
Eq. \eqref{eq:fourierdef2} and see whether
|
||||
</p>
|
||||
|
||||
$$
|
||||
\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}
|
||||
$$
|
||||
|
||||
<p>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
|
||||
</p>
|
||||
|
||||
$$
|
||||
\begin{equation}
|
||||
\int_{-\tau/2}^{\tau/2}dt~\cos^2(m\omega t)=\frac{\tau}{2},
|
||||
\label{_auto3}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
<p>and</p>
|
||||
|
||||
$$
|
||||
\begin{eqnarray}
|
||||
f_n&=?&\frac{2}{\tau}\int_{-\tau/2}^{\tau/2} dt~f_n/2\\
|
||||
\nonumber
|
||||
&=&f_n~\checkmark.
|
||||
\end{eqnarray}
|
||||
$$
|
||||
|
||||
<p>The same method can be used to check for the consistency of \( g_n \).</p>
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="final-words-on-fourier-transforms">Final words on Fourier Transforms </h2>
|
||||
|
||||
<p>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.
|
||||
</p>
|
||||
|
||||
|
||||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||||
<div class="cell border-box-sizing code_cell rendered">
|
||||
<div class="input">
|
||||
<div class="inner_cell">
|
||||
<div class="input_area">
|
||||
<div class="highlight" style="background: #f8f8f8">
|
||||
<pre style="line-height: 125%;"><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">math</span>
|
||||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">scipy</span> <span style="color: #008000; font-weight: bold">import</span> signal
|
||||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
|
||||
|
||||
<span style="color: #408080; font-style: italic"># number of points </span>
|
||||
n <span style="color: #666666">=</span> <span style="color: #666666">500</span>
|
||||
<span style="color: #408080; font-style: italic"># start and final times </span>
|
||||
t0 <span style="color: #666666">=</span> <span style="color: #666666">0.0</span>
|
||||
tn <span style="color: #666666">=</span> <span style="color: #666666">1.0</span>
|
||||
<span style="color: #408080; font-style: italic"># Period </span>
|
||||
T <span style="color: #666666">=0.2</span>
|
||||
<span style="color: #408080; font-style: italic"># Max value of square signal </span>
|
||||
Fmax<span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
|
||||
<span style="color: #408080; font-style: italic"># Width of signal </span>
|
||||
Width <span style="color: #666666">=</span> <span style="color: #666666">0.1</span>
|
||||
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(t0, tn, n, endpoint<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>)
|
||||
SqrSignal <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)
|
||||
FourierSeriesSignal <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(n)
|
||||
SqrSignal <span style="color: #666666">=</span> <span style="color: #666666">1.0+</span>signal<span style="color: #666666">.</span>square(<span style="color: #666666">2*</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*5*</span>t<span style="color: #666666">+</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>Width<span style="color: #666666">/</span>T)
|
||||
a0 <span style="color: #666666">=</span> Fmax<span style="color: #666666">*</span>Width<span style="color: #666666">/</span>T
|
||||
FourierSeriesSignal <span style="color: #666666">=</span> a0
|
||||
Factor <span style="color: #666666">=</span> <span style="color: #666666">2.0*</span>Fmax<span style="color: #666666">/</span>np<span style="color: #666666">.</span>pi
|
||||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">1</span>,<span style="color: #666666">500</span>):
|
||||
FourierSeriesSignal <span style="color: #666666">+=</span> Factor<span style="color: #666666">/</span>(i)<span style="color: #666666">*</span>np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>i<span style="color: #666666">*</span>Width<span style="color: #666666">/</span>T)<span style="color: #666666">*</span>np<span style="color: #666666">.</span>cos(i<span style="color: #666666">*</span>t<span style="color: #666666">*2*</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">/</span>T)
|
||||
plt<span style="color: #666666">.</span>plot(t, SqrSignal)
|
||||
plt<span style="color: #666666">.</span>plot(t, FourierSeriesSignal)
|
||||
plt<span style="color: #666666">.</span>ylim(<span style="color: #666666">-0.5</span>, <span style="color: #666666">2.5</span>)
|
||||
plt<span style="color: #666666">.</span>show()
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="output_wrapper">
|
||||
<div class="output">
|
||||
<div class="output_area">
|
||||
<div class="output_subarea output_stream output_stdout output_text">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
|
||||
<h2 id="two-dimensional-objects">Two-dimensional Objects </h2>
|
||||
|
||||
@@ -2489,7 +2197,7 @@ samples
|
||||
$$
|
||||
\begin{equation}
|
||||
x = g(z; \theta^{(g)})
|
||||
\label{_auto4}
|
||||
\label{_auto1}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2506,7 +2214,7 @@ value given by
|
||||
$$
|
||||
\begin{equation}
|
||||
d(x; \theta^{(d)})
|
||||
\label{_auto5}
|
||||
\label{_auto2}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2519,7 +2227,7 @@ which a function
|
||||
$$
|
||||
\begin{equation}
|
||||
v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto6}
|
||||
\label{_auto3}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2530,7 +2238,7 @@ conjugate reward
|
||||
$$
|
||||
\begin{equation}
|
||||
-v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto7}
|
||||
\label{_auto4}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2565,7 +2273,7 @@ $$
|
||||
\begin{equation}
|
||||
g^* = \underset{g}{\mathrm{argmin}}\hspace{2pt}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto8}
|
||||
\label{_auto5}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2575,7 +2283,7 @@ $$
|
||||
v(\theta^{(g)}, \theta^{(d)}) = \mathbb{E}_{x\sim p_\mathrm{data}}\log d(x)
|
||||
+ \mathbb{E}_{x\sim p_\mathrm{model}}
|
||||
\log (1 - d(x))
|
||||
\label{_auto9}
|
||||
\label{_auto6}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
@@ -2586,7 +2294,7 @@ approximation of a partition function. In the case where
|
||||
$$
|
||||
\begin{equation}
|
||||
\underset{d}{\mathrm{max}}v(\theta^{(g)}, \theta^{(d)})
|
||||
\label{_auto10}
|
||||
\label{_auto7}
|
||||
\end{equation}
|
||||
$$
|
||||
|
||||
|
||||
Binary file not shown.
+220
-659
File diff suppressed because it is too large
Load Diff
@@ -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