2020-03-06 02:24:32 +01:00
|
|
|
|
# Exercise 6
|
|
|
|
|
|
2020-05-01 00:43:50 +02:00
|
|
|
|
## Generating points according to Fraunhöfer diffraction
|
2020-03-06 02:24:32 +01:00
|
|
|
|
|
2020-05-20 16:28:19 +02:00
|
|
|
|
The diffraction of a plane wave through a round slit is to be simulated by
|
2020-03-06 02:24:32 +01:00
|
|
|
|
generating $N =$ 50'000 points according to the intensity distribution
|
2020-06-01 02:07:39 +02:00
|
|
|
|
$I(\theta)$ [@hecht02] on a screen at a great distance from the slit itself
|
2020-05-20 16:28:19 +02:00
|
|
|
|
(see @fig:slit):
|
2020-03-06 02:24:32 +01:00
|
|
|
|
$$
|
|
|
|
|
I(\theta) = \frac{E^2}{2} \left( \frac{2 \pi a^2 \cos{\theta}}{L}
|
|
|
|
|
\frac{J_1(x)}{x} \right)^2 \with x = k a \sin{\theta}
|
|
|
|
|
$$
|
|
|
|
|
where:
|
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
- $E$ is the electric field amplitude, default $E = \SI{1e4}{V/m}$;
|
|
|
|
|
- $a$ is the radius of the slit aperture, default $a = \SI{0.01}{m}$;
|
2020-06-03 21:56:05 +02:00
|
|
|
|
- $\theta$ is the diffraction angle shown in @fig:slit;
|
|
|
|
|
- $J_1$ is the Bessel function of first kind;
|
2020-06-01 02:07:39 +02:00
|
|
|
|
- $k$ is the wavenumber, default $k = \SI{1e-4}{m^{-1}}$;
|
2020-06-03 21:56:05 +02:00
|
|
|
|
- $L$ is the distance from the screen, default $L = \SI{1}{m}$.
|
2020-03-06 02:24:32 +01:00
|
|
|
|
|
|
|
|
|
\begin{figure}
|
2020-03-17 23:32:45 +01:00
|
|
|
|
\hypertarget{fig:slit}{%
|
2020-03-06 02:24:32 +01:00
|
|
|
|
\centering
|
|
|
|
|
\begin{tikzpicture}
|
|
|
|
|
% Walls
|
|
|
|
|
\draw [thick] (-1,3) -- (1,3) -- (1,0.3) -- (1.2,0.3) -- (1.2,3)
|
|
|
|
|
-- (9,3);
|
|
|
|
|
\draw [thick] (-1,-3) -- (1,-3) -- (1,-0.3) -- (1.2,-0.3) -- (1.2,-3)
|
|
|
|
|
-- (9,-3);
|
|
|
|
|
\draw [thick] (10,3) -- (9.8,3) -- (9.8,-3) -- (10,-3);
|
|
|
|
|
% Lines
|
|
|
|
|
\draw [thick, gray] (0.7,0.3) -- (0.5,0.3);
|
|
|
|
|
\draw [thick, gray] (0.7,-0.3) -- (0.5,-0.3);
|
|
|
|
|
\draw [thick, gray] (0.6,0.3) -- (0.6,-0.3);
|
|
|
|
|
\draw [thick, gray] (1.2,0) -- (9.8,0);
|
|
|
|
|
\draw [thick, gray] (1.2,-0.1) -- (1.2,0.1);
|
|
|
|
|
\draw [thick, gray] (9.8,-0.1) -- (9.8,0.1);
|
|
|
|
|
\draw [thick, cyclamen] (1.2,0) -- (9.8,-2);
|
|
|
|
|
\draw [thick, cyclamen] (7,0) to [out=-90, in=50] (6.6,-1.23);
|
|
|
|
|
% Nodes
|
|
|
|
|
\node at (0,0) {$2a$};
|
|
|
|
|
\node at (5.5,0.4) {$L$};
|
|
|
|
|
\node [cyclamen] at (5.5,-0.4) {$\theta$};
|
|
|
|
|
\node [rotate=-90] at (10.2,0) {screen};
|
|
|
|
|
\end{tikzpicture}
|
2020-05-01 00:43:50 +02:00
|
|
|
|
\caption{Fraunhöfer diffraction.}\label{fig:slit}
|
2020-03-06 02:24:32 +01:00
|
|
|
|
}
|
|
|
|
|
\end{figure}
|
|
|
|
|
|
2020-05-30 15:48:36 +02:00
|
|
|
|
Once again, the *hit-miss* method described in @sec:3 was implemented and
|
2020-05-20 16:28:19 +02:00
|
|
|
|
the same procedure about the generation of $\theta$ was applied. This time,
|
2020-06-01 02:07:39 +02:00
|
|
|
|
though, $\theta$ must be uniformly distributed on the half sphere, hence:
|
2020-03-06 02:24:32 +01:00
|
|
|
|
\begin{align*}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\frac{d^2 P}{d\omega^2} = \frac{1}{2 \pi}
|
2020-03-06 02:24:32 +01:00
|
|
|
|
&\thus d^2 P = \frac{1}{2 \pi} d\omega^2 =
|
|
|
|
|
\frac{1}{2 \pi} d\phi \sin{\theta} d\theta \\
|
2020-06-03 14:49:07 +02:00
|
|
|
|
&\thus \frac{dP}{d\theta} = \int_0^{2 \pi} \!\!\! d\phi \frac{1}{2 \pi} \sin{\theta}
|
2020-03-06 02:24:32 +01:00
|
|
|
|
= \frac{1}{2 \pi} \sin{\theta} \, 2 \pi = \sin{\theta}
|
|
|
|
|
\end{align*}
|
|
|
|
|
\begin{align*}
|
|
|
|
|
\theta = \theta (x) &\thus
|
|
|
|
|
\frac{dP}{d\theta} = \frac{dP}{dx} \cdot \left| \frac{dx}{d\theta} \right|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
= \left. \frac{dP}{dx} \middle/ \, \left| \frac{d\theta}{dx} \right| \right.
|
2020-03-06 02:24:32 +01:00
|
|
|
|
\\
|
|
|
|
|
&\thus \sin{\theta} = \left. 1 \middle/ \, \left|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\frac{d\theta}{dx} \right| \right.
|
2020-03-06 02:24:32 +01:00
|
|
|
|
\end{align*}
|
2020-06-03 21:56:05 +02:00
|
|
|
|
If $\theta$ is chosen to increase with $x$, then the absolute value can be
|
2020-03-17 19:42:28 +01:00
|
|
|
|
omitted:
|
2020-03-06 02:24:32 +01:00
|
|
|
|
\begin{align*}
|
|
|
|
|
\frac{d\theta}{dx} = \frac{1}{\sin{\theta}}
|
|
|
|
|
&\thus d\theta \sin(\theta) = dx
|
|
|
|
|
\\
|
|
|
|
|
&\thus - \cos (\theta') |_{0}^{\theta} = x(\theta) - x(0) = x - 0 = x
|
|
|
|
|
\\
|
|
|
|
|
&\thus - \cos(\theta) + 1 =x
|
|
|
|
|
\\
|
|
|
|
|
&\thus \theta = \text{acos} (1 -x)
|
|
|
|
|
\end{align*}
|
2020-05-20 16:28:19 +02:00
|
|
|
|
The so obtained sample was binned and stored in a histogram with a customizable
|
2020-06-01 02:07:39 +02:00
|
|
|
|
number $n$ of bins (default to $n = 150$) ranging from $\theta = 0$ to $\theta
|
2020-06-03 21:56:05 +02:00
|
|
|
|
= \pi/2$ because of the system symmetry. An example is shown in @fig:original.
|
2020-03-17 19:42:28 +01:00
|
|
|
|
|
2020-05-20 18:45:27 +02:00
|
|
|
|
![Example of intensity histogram.](images/6-original.pdf){#fig:original}
|
2020-03-17 19:42:28 +01:00
|
|
|
|
|
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
## Convolution {#sec:convolution}
|
2020-03-17 19:42:28 +01:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
In order to simulate the instrumentation response, the sample was then
|
2020-06-03 21:56:05 +02:00
|
|
|
|
convolved with a Gaussian kernel with the aim to recover the original sample
|
2020-06-01 02:07:39 +02:00
|
|
|
|
afterwards, implementing a deconvolution routine.
|
2020-05-20 16:28:19 +02:00
|
|
|
|
For this purpose, a 'kernel' histogram with an even number $m$ of bins and the
|
|
|
|
|
same bin width of the previous one, but a smaller number of them ($m \sim 6\%
|
2020-06-03 21:56:05 +02:00
|
|
|
|
\, n$), was generated according to a Gaussian distribution with mean $\mu = 0$
|
2020-05-20 16:28:19 +02:00
|
|
|
|
and variance $\sigma$. The reason why the kernel was set this way will be
|
2020-05-21 18:50:21 +02:00
|
|
|
|
discussed shortly.
|
2020-06-03 21:56:05 +02:00
|
|
|
|
The original histogram was then convolved with the kernel in order to obtain
|
2020-05-20 16:28:19 +02:00
|
|
|
|
the smeared signal. As an example, the result obtained for $\sigma = \Delta
|
|
|
|
|
\theta$, where $\Delta \theta$ is the bin width, is shown in @fig:convolved.
|
2020-05-20 18:45:27 +02:00
|
|
|
|
The smeared signal looks smoother with respect to the original one: the higher
|
2020-06-01 02:07:39 +02:00
|
|
|
|
$\sigma$, the greater the smoothness.
|
2020-05-20 16:28:19 +02:00
|
|
|
|
|
2020-05-20 18:45:27 +02:00
|
|
|
|
![Convolved signal.](images/6-smoothed.pdf){#fig:convolved}
|
2020-05-20 16:28:19 +02:00
|
|
|
|
|
2020-03-17 23:32:45 +01:00
|
|
|
|
The convolution was implemented as follow. Consider the definition of
|
2020-06-01 02:07:39 +02:00
|
|
|
|
convolution for two integrable functions $f(x)$ and $g(x)$:
|
2020-03-17 23:32:45 +01:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
(f * g)(x) = \int \limits_{- \infty}^{+ \infty} dy f(y) g(x - y)
|
2020-03-17 23:32:45 +01:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
This definition is easily recast into a form that lends itself to be
|
|
|
|
|
implemented for discrete arrays of numbers, such as histograms or vectors:
|
|
|
|
|
\begin{align*}
|
|
|
|
|
(f * g)(x)
|
|
|
|
|
&= \int \limits_{- \infty}^{+ \infty} dy f(y) (R \, g)(y-x) \\
|
|
|
|
|
&= \int \limits_{- \infty}^{+ \infty} dy f(y) (T_x \, R \, g)(y) \\
|
|
|
|
|
&= (f, T_x \, R \, g)(y)
|
|
|
|
|
\end{align*}
|
2020-03-17 23:32:45 +01:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
where:
|
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
- $R$ and $T_x$ are the reflection and translation by $x$ operators,
|
|
|
|
|
- $(\cdot, \cdot)$ is an inner product.
|
2020-06-01 02:07:39 +02:00
|
|
|
|
|
|
|
|
|
Given a signal $s$ of $n$ elements and a kernel $k$ of $m$ elements,
|
2020-07-05 17:53:52 +02:00
|
|
|
|
their convolution $c$ is a vector of $n + m + 1$ elements computed
|
2020-06-01 02:07:39 +02:00
|
|
|
|
by flipping $s$ ($R$ operator) and shifting its indices ($T_i$ operator):
|
2020-03-17 23:32:45 +01:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
c_i = (s, T_i \, R \, k)
|
2020-03-17 23:32:45 +01:00
|
|
|
|
$$
|
2020-06-03 21:56:05 +02:00
|
|
|
|
The shift is defined such that when a index overflows ($\ge m$ or $\le$ 0) the
|
2020-06-01 02:07:39 +02:00
|
|
|
|
element is zero. This convention specifies the behavior at the edges
|
|
|
|
|
and results in the $m + 1$ increase in size.
|
|
|
|
|
For a better understanding, see @fig:dot_conv.
|
2020-03-17 19:42:28 +01:00
|
|
|
|
|
|
|
|
|
\begin{figure}
|
|
|
|
|
\hypertarget{fig:dot_conv}{%
|
|
|
|
|
\centering
|
|
|
|
|
\begin{tikzpicture}
|
|
|
|
|
% original histogram
|
2020-03-17 23:32:45 +01:00
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (0.0,0) rectangle (0.5,2.5);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (0.5,0) rectangle (1.0,2.8);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.0,0) rectangle (1.5,2.3);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.5,0) rectangle (2.0,1.8);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (2.0,0) rectangle (2.5,1.4);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (2.5,0) rectangle (3.0,1.0);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (3.0,0) rectangle (3.5,1.0);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (3.5,0) rectangle (4.0,0.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (4.0,0) rectangle (4.5,0.4);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (4.5,0) rectangle (5.0,0.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (5.0,0) rectangle (5.5,0.2);
|
2020-03-17 19:42:28 +01:00
|
|
|
|
\draw [thick, cyclamen] (6.0,0) -- (6.0,0.2);
|
|
|
|
|
\draw [thick, cyclamen] (6.5,0) -- (6.5,0.2);
|
|
|
|
|
\draw [thick, <->] (0,3.3) -- (0,0) -- (7,0);
|
|
|
|
|
% kernel histogram
|
2020-03-17 23:32:45 +01:00
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.0,-1) rectangle (1.5,-1.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.5,-1) rectangle (2.0,-1.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (2.0,-1) rectangle (2.5,-1.8);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (2.5,-1) rectangle (3.0,-1.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (3.0,-1) rectangle (3.5,-1.2);
|
2020-03-17 19:42:28 +01:00
|
|
|
|
\draw [thick, <->] (1,-2) -- (1,-1) -- (4,-1);
|
|
|
|
|
% arrows
|
2020-03-17 23:32:45 +01:00
|
|
|
|
\draw [thick, cyclamen, <->] (1.25,-0.2) -- (1.25,-0.8);
|
|
|
|
|
\draw [thick, cyclamen, <->] (1.75,-0.2) -- (1.75,-0.8);
|
|
|
|
|
\draw [thick, cyclamen, <->] (2.25,-0.2) -- (2.25,-0.8);
|
|
|
|
|
\draw [thick, cyclamen, <->] (2.75,-0.2) -- (2.75,-0.8);
|
|
|
|
|
\draw [thick, cyclamen, <->] (3.25,-0.2) -- (3.25,-0.8);
|
|
|
|
|
\draw [thick, cyclamen, ->] (2.25,-2.0) -- (2.25,-4.2);
|
2020-03-17 19:42:28 +01:00
|
|
|
|
% smeared histogram
|
|
|
|
|
\begin{scope}[shift={(0,-1)}]
|
2020-03-17 23:32:45 +01:00
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (-1.0,-4.5) rectangle (-0.5,-4.3);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] (-0.5,-4.5) rectangle ( 0.0,-4.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] ( 0.0,-4.5) rectangle ( 0.5,-2.0);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] ( 0.5,-4.5) rectangle ( 1.0,-1.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] ( 1.0,-4.5) rectangle ( 1.5,-2.3);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!05!white] ( 1.5,-4.5) rectangle ( 2.0,-2.9);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] ( 2.0,-4.5) rectangle ( 2.5,-3.4);
|
2020-03-17 19:42:28 +01:00
|
|
|
|
\draw [thick, cyclamen] (3.0,-4.5) -- (3.0,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (3.5,-4.5) -- (3.5,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (4.0,-4.5) -- (4.0,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (4.5,-4.5) -- (4.5,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (5.0,-4.5) -- (5.0,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (5.5,-4.5) -- (5.5,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (6.0,-4.5) -- (6.0,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (6.5,-4.5) -- (6.5,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (7.0,-4.5) -- (7.0,-4.3);
|
|
|
|
|
\draw [thick, cyclamen] (7.5,-4.5) -- (7.5,-4.3);
|
|
|
|
|
\draw [thick, <->] (-1,-2.5) -- (-1,-4.5) -- (8,-4.5);
|
|
|
|
|
\end{scope}
|
2020-03-17 23:32:45 +01:00
|
|
|
|
% nodes
|
|
|
|
|
\node [above] at (2.25,-5.5) {$c_i$};
|
|
|
|
|
\node [above] at (3.25,0) {$s_i$};
|
2020-05-21 18:50:21 +02:00
|
|
|
|
\node [above] at (1.95,0) {$s_{i-j}$};
|
|
|
|
|
\node [below] at (1.75,-1) {$k_j$};
|
2020-03-17 19:42:28 +01:00
|
|
|
|
\end{tikzpicture}
|
2020-03-27 23:18:17 +01:00
|
|
|
|
\caption{Element wise product as a step of the convolution between the original signal
|
2020-03-17 23:32:45 +01:00
|
|
|
|
(above) and the kernel (center). The final result is the lower
|
2020-03-17 19:42:28 +01:00
|
|
|
|
fledging histogram.}\label{fig:dot_conv}
|
|
|
|
|
}
|
|
|
|
|
\end{figure}
|
2020-03-17 23:32:45 +01:00
|
|
|
|
|
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
## Deconvolution by Fourier transform
|
2020-03-21 23:16:12 +01:00
|
|
|
|
|
|
|
|
|
Two different unfolding routines were implemented, one of which exploiting the
|
2020-05-20 16:28:19 +02:00
|
|
|
|
Fast Fourier Transform (FFT).
|
2020-03-21 23:16:12 +01:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
This method is based on the convolution theorem, which states that given two
|
|
|
|
|
$L^1$ functions $f(x)$ and $g(x)$:
|
2020-03-21 23:16:12 +01:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\mathcal{F}[f * g] = \mathcal{F}[f] \cdot \mathcal{F}[g]
|
2020-03-21 23:16:12 +01:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
where $\mathcal{F}[\cdot]$ stands for the Fourier transform.
|
2020-05-20 16:28:19 +02:00
|
|
|
|
Being the histogram a discrete set of data, the Discrete Fourier Transform (DFT)
|
2020-05-21 18:50:21 +02:00
|
|
|
|
was applied. When dealing with arrays of discrete values, the theorem still
|
2020-06-01 02:07:39 +02:00
|
|
|
|
holds if the two arrays have the same length and $(*)$ is understood
|
|
|
|
|
as a cyclical convolution.
|
|
|
|
|
For this reason, the kernel was 0-padded to make it the same length of the
|
|
|
|
|
original signal and, at the same time, avoiding the cyclical convolution.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
In order to accomplish this procedure, both histograms were transformed into
|
|
|
|
|
vectors. The implementation lies in the computation of the Fourier transform of
|
2020-05-20 16:28:19 +02:00
|
|
|
|
the smeared signal and the kernel, the ratio between their transforms and the
|
|
|
|
|
anti-transformation of the result:
|
2020-03-23 22:49:47 +01:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\mathcal{F}[s * k] = \mathcal{F}[s] \cdot \mathcal{F}[k] \thus
|
|
|
|
|
\mathcal{F} [s] = \frac{\mathcal{F}[s * k]}{\mathcal{F}[k]}
|
2020-03-23 22:49:47 +01:00
|
|
|
|
$$
|
2020-05-20 16:28:19 +02:00
|
|
|
|
The FFT are efficient algorithms for calculating the DFT. Given a set of $n$
|
2020-05-21 18:50:21 +02:00
|
|
|
|
values {$z_j$}, each one is transformed into:
|
2020-03-21 23:16:12 +01:00
|
|
|
|
$$
|
|
|
|
|
x_j = \sum_{k=0}^{n-1} z_k \exp \left( - \frac{2 \pi i j k}{n} \right)
|
|
|
|
|
$$
|
2020-05-21 18:50:21 +02:00
|
|
|
|
where $i$ is the imaginary unit.
|
2020-03-21 23:16:12 +01:00
|
|
|
|
The evaluation of the DFT is a matrix-vector multiplication $W \vec{z}$. A
|
|
|
|
|
general matrix-vector multiplication takes $O(n^2)$ operations. FFT algorithms,
|
2020-06-01 02:07:39 +02:00
|
|
|
|
instead, use a *divide-and-conquer* strategy to factorise the matrix into
|
|
|
|
|
smaller sub-matrices. If $n$ can be factorised into a product of integers $n_1$,
|
2020-05-21 18:50:21 +02:00
|
|
|
|
$n_2 \ldots n_m$, then the DFT can be computed in $O(n \sum n_i) < O(n^2)$
|
2020-03-21 23:16:12 +01:00
|
|
|
|
operations, hence the name.
|
|
|
|
|
The inverse Fourier transform is thereby defined as:
|
|
|
|
|
$$
|
|
|
|
|
z_j = \frac{1}{n}
|
|
|
|
|
\sum_{k=0}^{n-1} x_k \exp \left( \frac{2 \pi i j k}{n} \right)
|
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
In GSL, `gsl_fft_complex_forward()` and `gsl_fft_complex_inverse()` are
|
2020-05-21 18:50:21 +02:00
|
|
|
|
functions which allow to compute the forward and inverse transform,
|
2020-05-20 16:28:19 +02:00
|
|
|
|
respectively.
|
2020-03-23 22:49:47 +01:00
|
|
|
|
The inputs and outputs for the complex FFT routines are packed arrays of
|
2020-05-21 18:50:21 +02:00
|
|
|
|
floating point numbers. In a packed array, the real and imaginary parts of each
|
|
|
|
|
complex number are placed in alternate neighboring elements. In this special
|
2020-06-03 21:56:05 +02:00
|
|
|
|
case, where the sequence of values to be transformed is made of real numbers,
|
|
|
|
|
the Fourier transform is a complex sequence which satisfies:
|
2020-03-21 23:16:12 +01:00
|
|
|
|
$$
|
|
|
|
|
z_k = z^*_{n-k}
|
|
|
|
|
$$
|
2020-03-23 22:49:47 +01:00
|
|
|
|
where $z^*$ is the conjugate of $z$. A sequence with this symmetry is called
|
|
|
|
|
'half-complex'. This structure requires particular storage layouts for the
|
2020-03-21 23:16:12 +01:00
|
|
|
|
forward transform (from real to half-complex) and inverse transform (from
|
|
|
|
|
half-complex to real). As a consequence, the routines are divided into two sets:
|
|
|
|
|
`gsl_fft_real` and `gsl_fft_halfcomplex`. The symmetry of the half-complex
|
2020-05-20 16:28:19 +02:00
|
|
|
|
sequence requires only half of the complex numbers in the output to be stored.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
This works for all lengths: when the length is odd, the middle value is real.
|
2020-05-20 16:28:19 +02:00
|
|
|
|
Thus, only $n$ real numbers are required to store the half-complex sequence
|
|
|
|
|
(half for the real part and half for the imaginary).
|
2020-03-23 22:49:47 +01:00
|
|
|
|
|
|
|
|
|
\begin{figure}
|
|
|
|
|
\hypertarget{fig:reorder}{%
|
|
|
|
|
\centering
|
|
|
|
|
\begin{tikzpicture}
|
|
|
|
|
% standard histogram
|
|
|
|
|
\draw [thick, cyclamen] (0.5,0) -- (0.5,0.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.0,0) rectangle (1.5,0.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.5,0) rectangle (2.0,1.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (2.0,0) rectangle (2.5,1.4);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (2.5,0) rectangle (3.0,1.4);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (3.0,0) rectangle (3.5,1.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (3.5,0) rectangle (4.0,0.6);
|
|
|
|
|
\draw [thick, cyclamen] (4.5,0) -- (4.5,0.2);
|
|
|
|
|
\draw [thick, ->] (0,0) -- (5,0);
|
|
|
|
|
\draw [thick, ->] (2.5,0) -- (2.5,2);
|
|
|
|
|
% shifted histogram
|
2020-05-20 16:28:19 +02:00
|
|
|
|
\begin{scope}[shift={(7,0)}]
|
2020-03-23 22:49:47 +01:00
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (0.5,0) rectangle (1.0,1.4);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.0,0) rectangle (1.5,1.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (1.5,0) rectangle (2.0,0.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (3.0,0) rectangle (3.5,0.6);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (3.5,0) rectangle (4.0,1.2);
|
|
|
|
|
\draw [thick, cyclamen, fill=cyclamen!25!white] (4.0,0) rectangle (4.5,1.4);
|
|
|
|
|
\draw [thick, ->] (0,0) -- (5,0);
|
|
|
|
|
\draw [thick, ->] (2.5,0) -- (2.5,2);
|
2020-05-20 16:28:19 +02:00
|
|
|
|
\end{scope}
|
2020-03-23 22:49:47 +01:00
|
|
|
|
\end{tikzpicture}
|
2020-05-20 16:28:19 +02:00
|
|
|
|
\caption{The histogram on the right shows how the real numbers histogram on the
|
2020-05-21 18:50:21 +02:00
|
|
|
|
left is handled by the dedicated GSL functions.}\label{fig:reorder}
|
2020-03-23 22:49:47 +01:00
|
|
|
|
}
|
|
|
|
|
\end{figure}
|
2020-03-21 23:16:12 +01:00
|
|
|
|
|
2020-05-20 16:28:19 +02:00
|
|
|
|
If the bin width is $\Delta \theta$, then the DFT domain ranges from $-1 / (2
|
|
|
|
|
\Delta \theta)$ to $+1 / (2 \Delta \theta$). As regards the real values, the
|
|
|
|
|
aforementioned GSL functions store the positive values from the beginning of
|
|
|
|
|
the array up to the middle and the negative backwards from the end of the array
|
|
|
|
|
(see @fig:reorder).
|
2020-06-01 02:07:39 +02:00
|
|
|
|
While the order of frequencies of the convolved histogram is immaterial,
|
|
|
|
|
the kernel must be centered at zero in order to compute a correct
|
2020-05-20 16:28:19 +02:00
|
|
|
|
convolution. This requires the kernel to be made of an ever number of bins
|
2020-06-01 02:07:39 +02:00
|
|
|
|
to be divided into two equal halves.
|
2020-05-20 16:28:19 +02:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
When $\mathcal{F}[s * k]$ and $\mathcal{F}[k]$ are computed, they are given in the
|
|
|
|
|
half-complex GSL packed format, so they must be unpacked to a complex
|
|
|
|
|
GSL vector before performing the element-wise division. Then,
|
|
|
|
|
the result is repacked to the half-complex format for the inverse DFT
|
2020-05-20 16:28:19 +02:00
|
|
|
|
computation. GSL provides the function `gsl_fft_halfcomplex_unpack()` which
|
|
|
|
|
convert the vectors from half-complex format to standard complex format but the
|
2020-06-01 02:07:39 +02:00
|
|
|
|
inverse procedure is not provided by GSL and had to be implemented.
|
2020-05-20 16:28:19 +02:00
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
At the end, the external bins which exceed the original signal size were cut
|
2020-05-20 16:28:19 +02:00
|
|
|
|
away in order to restore the original number of bins $n$. Results will be
|
2020-06-01 02:07:39 +02:00
|
|
|
|
discussed in @sec:conv-results.
|
2020-03-21 23:16:12 +01:00
|
|
|
|
|
2020-03-27 00:00:55 +01:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
## Richardson-Lucy deconvolution
|
2020-03-27 00:00:55 +01:00
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
The Richardson–Lucy (RL) deconvolution is an iterative procedure typically used
|
2020-05-20 16:28:19 +02:00
|
|
|
|
for recovering an image that has been blurred by a known 'point spread
|
2020-06-01 02:07:39 +02:00
|
|
|
|
function', or 'kernel'.
|
2020-03-27 00:00:55 +01:00
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
Consider the problem of estimating the frequency distribution $f(\xi)$ of a
|
2020-05-20 16:28:19 +02:00
|
|
|
|
variable $\xi$ when the available measure is a sample {$x_i$} of points
|
2020-05-21 18:50:21 +02:00
|
|
|
|
drown not by $f(x)$ but by another function $\phi(x)$ such that:
|
2020-03-27 00:00:55 +01:00
|
|
|
|
$$
|
2020-05-20 16:28:19 +02:00
|
|
|
|
\phi(x) = \int d\xi \, f(\xi) P(x | \xi)
|
2020-05-20 18:45:27 +02:00
|
|
|
|
$$ {#eq:conv}
|
2020-05-20 16:28:19 +02:00
|
|
|
|
where $P(x | \xi) \, d\xi$ is the probability (presumed known) that $x$ falls
|
2020-05-21 18:50:21 +02:00
|
|
|
|
in the interval $(x, x + dx)$ when $\xi = \xi$. If the so-called point spread
|
2020-06-01 02:07:39 +02:00
|
|
|
|
function $P(x | \xi)$ is a function of $x-\xi$ only, for example a normal
|
2020-06-03 21:56:05 +02:00
|
|
|
|
distribution with variance $\sigma$:
|
2020-05-20 18:45:27 +02:00
|
|
|
|
$$
|
|
|
|
|
P(x | \xi) = \frac{1}{\sqrt{2 \pi} \sigma}
|
|
|
|
|
\exp \left( - \frac{(x - \xi)^2}{2 \sigma^2} \right)
|
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
then, @eq:conv becomes a convolution and finding $f(\xi)$ amounts
|
|
|
|
|
to a deconvolution.
|
2020-05-20 18:45:27 +02:00
|
|
|
|
An example of this problem is precisely that of correcting an observed
|
|
|
|
|
distribution $\phi(x)$ for the effect of observational errors, which are
|
|
|
|
|
represented by the function $P (x | \xi)$.
|
2020-03-27 00:00:55 +01:00
|
|
|
|
|
2020-05-20 16:28:19 +02:00
|
|
|
|
Let $Q(\xi | x) d\xi$ be the probability that $\xi$ comes from the interval
|
|
|
|
|
$(\xi, \xi + d\xi)$ when the measured quantity is $x = x$. The probability that
|
|
|
|
|
both $x \in (x, x + dx)$ and $(\xi, \xi + d\xi)$ is therefore given by $\phi(x)
|
|
|
|
|
dx \cdot Q(\xi | x) d\xi$ which is identical to $f(\xi) d\xi \cdot P(x | \xi)
|
|
|
|
|
dx$, hence:
|
|
|
|
|
$$
|
|
|
|
|
\phi(x) dx \cdot Q(\xi | x) d\xi = f(\xi) d\xi \cdot P(x | \xi) dx
|
|
|
|
|
\thus Q(\xi | x) = \frac{f(\xi) \cdot P(x | \xi)}{\phi(x)}
|
2020-03-27 00:00:55 +01:00
|
|
|
|
$$
|
|
|
|
|
$$
|
2020-05-20 16:28:19 +02:00
|
|
|
|
\thus Q(\xi | x) = \frac{f(\xi) \cdot P(x | \xi)}
|
|
|
|
|
{\int d\xi \, f(\xi) P(x | \xi)}
|
|
|
|
|
$$ {#eq:first}
|
|
|
|
|
which is the Bayes theorem for conditional probability. From the normalization
|
|
|
|
|
of $P(x | \xi)$, it follows also that:
|
|
|
|
|
$$
|
|
|
|
|
f(\xi) = \int dx \, \phi(x) Q(\xi | x)
|
|
|
|
|
$$ {#eq:second}
|
2020-05-21 18:50:21 +02:00
|
|
|
|
Since $Q (\xi | x)$ depends on $f(\xi)$, @eq:second suggests an iterative
|
2020-05-20 16:28:19 +02:00
|
|
|
|
procedure for generating estimates of $f(\xi)$. With a guess for $f(\xi)$ and
|
2020-06-03 21:56:05 +02:00
|
|
|
|
a known $P(x | \xi)$, @eq:first can be used to calculate an estimate for
|
2020-05-20 16:28:19 +02:00
|
|
|
|
$Q (\xi | x)$. Then, taking the hint provided by @eq:second, an improved
|
2020-06-01 02:07:39 +02:00
|
|
|
|
estimate for $f(\xi)$ can be generated, using the observed sample {$x_i$} to
|
2020-05-21 18:50:21 +02:00
|
|
|
|
give an approximation for $\phi$.
|
2020-06-01 02:07:39 +02:00
|
|
|
|
Thus, if $f^t$ is the $t-th$ estimate, the next is given by:
|
2020-03-27 00:00:55 +01:00
|
|
|
|
$$
|
2020-05-20 16:28:19 +02:00
|
|
|
|
f^{t + 1}(\xi) = \int dx \, \phi(x) Q^t(\xi | x)
|
|
|
|
|
\with
|
|
|
|
|
Q^t(\xi | x) = \frac{f^t(\xi) \cdot P(x | \xi)}
|
|
|
|
|
{\int d\xi \, f^t(\xi) P(x | \xi)}
|
2020-03-27 00:00:55 +01:00
|
|
|
|
$$
|
2020-05-20 16:28:19 +02:00
|
|
|
|
from which:
|
|
|
|
|
$$
|
|
|
|
|
f^{t + 1}(\xi) = f^t(\xi)
|
|
|
|
|
\int dx \, \frac{\phi(x)}{\int d\xi \, f^t(\xi) P(x | \xi)}
|
|
|
|
|
P(x | \xi)
|
|
|
|
|
$$ {#eq:solution}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
When the spread function $P(x | \xi) = P(x-\xi)$, @eq:solution can be
|
2020-05-20 18:45:27 +02:00
|
|
|
|
rewritten in terms of convolutions:
|
2020-05-20 16:28:19 +02:00
|
|
|
|
$$
|
|
|
|
|
f^{t + 1} = f^{t}\left( \frac{\phi}{{f^{t}} * P} * P^{\star} \right)
|
|
|
|
|
$$
|
|
|
|
|
where $P^{\star}$ is the flipped point spread function [@lucy74].
|
2020-03-27 23:18:17 +01:00
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
In this particular instance, a Gaussian kernel was convolved with the original
|
2020-06-01 02:07:39 +02:00
|
|
|
|
histogram. Again, dealing with discrete arrays of numbers, the division and
|
|
|
|
|
multiplication are element wise and the convolution is to be carried out as
|
|
|
|
|
described in @sec:convolution.
|
2020-03-27 23:44:18 +01:00
|
|
|
|
When implemented, this method results in an easy step-wise routine:
|
|
|
|
|
|
2020-05-20 16:28:19 +02:00
|
|
|
|
- choose a zero-order estimate for {$f(\xi)$};
|
2020-05-21 18:50:21 +02:00
|
|
|
|
- create a flipped copy of the kernel;
|
2020-05-20 16:28:19 +02:00
|
|
|
|
- compute the convolutions, the product and the division at each step;
|
2020-05-21 18:50:21 +02:00
|
|
|
|
- proceed until a given number $r$ of iterations is reached.
|
2020-03-27 23:44:18 +01:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
In this case, the zero-order was set $f(\xi) = 0.5 \, \forall \, \xi$ and
|
|
|
|
|
different number of iterations where tested. Results are discussed in
|
|
|
|
|
@sec:conv-results.
|
2020-03-27 00:00:55 +01:00
|
|
|
|
|
2020-03-21 23:16:12 +01:00
|
|
|
|
|
2020-05-20 18:45:27 +02:00
|
|
|
|
## The earth mover's distance
|
2020-03-21 23:16:12 +01:00
|
|
|
|
|
2020-05-20 18:45:27 +02:00
|
|
|
|
With the aim of comparing the two deconvolution methods, the similarity of a
|
|
|
|
|
deconvolved outcome with the original signal was quantified using the earth
|
|
|
|
|
mover's distance.
|
2020-05-01 23:56:35 +02:00
|
|
|
|
|
|
|
|
|
In statistics, the earth mover's distance (EMD) is the measure of distance
|
2020-06-01 02:07:39 +02:00
|
|
|
|
between two distributions [@cock41]. Informally, if one imagines the
|
2020-05-21 09:51:36 +02:00
|
|
|
|
distributions as two piles of different amount of dirt in their respective
|
2020-06-01 02:07:39 +02:00
|
|
|
|
regions, the EMD is the minimum cost of turning one pile into the other, making
|
|
|
|
|
the first the most possible similar to the second, where the cost is the amount
|
|
|
|
|
of dirt moved times the distance by which it is moved.
|
2020-05-03 00:06:02 +02:00
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
Computing the EMD is based on the solution to a transportation problem which
|
2020-06-01 02:07:39 +02:00
|
|
|
|
can be formalized as follows. Consider two vectors $P$ and $Q$ which represent
|
|
|
|
|
the two distributions whose EMD has to be measured:
|
2020-05-03 00:06:02 +02:00
|
|
|
|
$$
|
2020-05-20 18:45:27 +02:00
|
|
|
|
P = \{ (p_1, w_{p1}) \dots (p_m, w_{pm}) \} \et
|
2020-05-03 00:06:02 +02:00
|
|
|
|
Q = \{ (q_1, w_{q1}) \dots (q_n, w_{qn}) \}
|
|
|
|
|
$$
|
2020-05-20 18:45:27 +02:00
|
|
|
|
where $p_i$ and $q_i$ are the 'values' (that is, the location of the dirt) and
|
|
|
|
|
$w_{pi}$ and $w_{qi}$ are the 'weights' (that is, the quantity of dirt). A
|
2020-06-01 02:07:39 +02:00
|
|
|
|
ground distance matrix $D$ is defined such as its entries $d_{ij}$ are the
|
|
|
|
|
distances between $p_i$ and $q_j$. The aim is to find the flow matrix $F$,
|
|
|
|
|
where each entry $f_{ij}$ is the flow from $p_i$ to $q_j$ (which would be the
|
|
|
|
|
quantity of moved dirt), which minimizes the cost $W$:
|
2020-05-03 00:06:02 +02:00
|
|
|
|
$$
|
|
|
|
|
W (P, Q, F) = \sum_{i = 1}^m \sum_{j = 1}^n f_{ij} d_{ij}
|
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
The $Q$ region is to be considered empty at the beginning: the 'dirt' present
|
|
|
|
|
in $P$ must be moved to $Q$ in order to reproduce the same distribution as
|
|
|
|
|
close as possible. Formally, the following constraints must be satisfied:
|
2020-05-03 00:06:02 +02:00
|
|
|
|
\begin{align*}
|
2020-05-21 09:51:36 +02:00
|
|
|
|
&\text{1.} \hspace{20pt} f_{ij} \ge 0 \hspace{15pt}
|
|
|
|
|
&1 \le i \le m \wedge 1 \le j \le n
|
|
|
|
|
\\
|
|
|
|
|
&\text{2.} \hspace{20pt} \sum_{j = 1}^n f_{ij} \le w_{pi}
|
|
|
|
|
&1 \le i \le m
|
|
|
|
|
\\
|
|
|
|
|
&\text{3.} \hspace{20pt} \sum_{i = 1}^m f_{ij} \le w_{qj}
|
|
|
|
|
&1 \le j \le n
|
|
|
|
|
\\
|
2020-07-05 17:53:52 +02:00
|
|
|
|
&\text{4.} \hspace{20pt} \sum_{j = 1}^n \sum_{j = 1}^m f_{ij} \le
|
|
|
|
|
\text{min} \left( \sum_{i = 1}^m w_{pi}, \sum_{j = 1}^n w_{qj} \right)
|
2020-05-21 09:51:36 +02:00
|
|
|
|
\end{align*}
|
|
|
|
|
The first constraint allows moving dirt from $P$ to $Q$ and not vice versa; the
|
|
|
|
|
second limits the amount of dirt moved by each position in $P$ in order to not
|
|
|
|
|
exceed the available quantity; the third sets a limit to the dirt moved to each
|
|
|
|
|
position in $Q$ in order to not exceed the required quantity and the last one
|
|
|
|
|
forces to move the maximum amount of supplies possible: either all the dirt
|
2020-05-21 18:50:21 +02:00
|
|
|
|
present in $P$ has been moved or the $Q$ distribution has been obtained.
|
2020-05-21 09:51:36 +02:00
|
|
|
|
The total moved amount is the total flow. If the two distributions have the
|
2020-06-03 21:56:05 +02:00
|
|
|
|
same amount of dirt, all the dirt present in $P$ is necessarily moved to $Q$ and
|
|
|
|
|
the total flow equals the amount of available dirt.
|
2020-05-03 00:06:02 +02:00
|
|
|
|
|
2020-05-21 09:51:36 +02:00
|
|
|
|
Once the transportation problem is solved and the optimal flow is found, the
|
2020-06-01 02:07:39 +02:00
|
|
|
|
EMD is defined as the work normalized by the total flow:
|
2020-05-03 00:06:02 +02:00
|
|
|
|
$$
|
2020-05-21 09:51:36 +02:00
|
|
|
|
\text{EMD} (P, Q) = \frac{\sum_{i = 1}^m \sum_{j = 1}^n f_{ij} d_{ij}}
|
2020-05-03 00:06:02 +02:00
|
|
|
|
{\sum_{i = 1}^m \sum_{j=1}^n f_{ij}}
|
|
|
|
|
$$
|
2020-05-21 18:50:21 +02:00
|
|
|
|
In this case, where the EMD is to be measured between two same-length
|
|
|
|
|
histograms, the procedure simplifies a lot. By representing both histograms
|
|
|
|
|
with two vectors $u$ and $v$, the equation above boils down to [@ramdas17]:
|
2020-05-03 00:06:02 +02:00
|
|
|
|
$$
|
2020-05-21 09:51:36 +02:00
|
|
|
|
\text{EMD} (u, v) = \sum_i |U_i - V_i|
|
2020-05-03 00:06:02 +02:00
|
|
|
|
$$
|
|
|
|
|
where the sum runs over the entries of the vectors $U$ and $V$, which are the
|
2020-06-01 02:07:39 +02:00
|
|
|
|
cumulative sums of the histograms. In the code, the following equivalent
|
2020-05-21 18:50:21 +02:00
|
|
|
|
iterative routine was implemented.
|
2020-05-03 00:06:02 +02:00
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\text{EMD} (u, v) = \sum_i |\text{d}_i| \with
|
2020-05-03 00:06:02 +02:00
|
|
|
|
\begin{cases}
|
2020-06-03 21:56:05 +02:00
|
|
|
|
\text{d}_i = v_i - u_i + \text{d}_{i-1} \\
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\text{d}_0 = 0
|
2020-05-03 00:06:02 +02:00
|
|
|
|
\end{cases}
|
|
|
|
|
$$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
The equivalence is apparent once the definition is expanded:
|
2020-05-03 00:06:02 +02:00
|
|
|
|
\begin{align*}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
\text{EMD} (u, v)
|
|
|
|
|
&= \sum_i |\text{d}_i| = |\text{d}_0| + |\text{d}_1|
|
|
|
|
|
+ |\text{d}_2| + |\text{d}_3| + \dots \\
|
|
|
|
|
&= 0 + |v_1 - u_1 + \text{d}_0| +
|
|
|
|
|
|v_2 - u_2 + \text{d}_1| +
|
|
|
|
|
|v_3 - u_3 + \text{d}_2| + \dots \\
|
|
|
|
|
&= |v_1 - u_1| +
|
|
|
|
|
|v_1 - u_1 + v_2 - u_2| +
|
|
|
|
|
|v_1 - u_1 + v_2 - u_2 + v_3 - u_3| + \dots \\
|
|
|
|
|
&= |v_1 - u_1| +
|
|
|
|
|
|v_1 + v_2 - (u_1 + u_2)| +
|
|
|
|
|
|v_1 + v_2 + v_3 - (u_1 + u_2 + u_3))| + \dots \\
|
|
|
|
|
&= |V_1 - U_1| + |V_2 - U_2| + |V_3 - U_3| + \dots \\
|
|
|
|
|
&= \sum_i |U_i - V_i|
|
2020-05-03 00:06:02 +02:00
|
|
|
|
\end{align*}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
This simple algorithm enabled the comparisons between a great number of
|
2020-06-03 21:56:05 +02:00
|
|
|
|
histograms to be computed efficiently.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
In order to make the code more flexible, the data were normalized before
|
|
|
|
|
computing the EMD: in doing so, it is possible to compare even samples with a
|
|
|
|
|
different number of points.
|
|
|
|
|
|
2020-05-20 18:45:27 +02:00
|
|
|
|
|
2020-06-01 02:07:39 +02:00
|
|
|
|
## Results comparison {#sec:conv-results}
|
2020-05-20 18:45:27 +02:00
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
|
|
|
|
### Noiseless results {#sec:noiseless}
|
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
In addition to the convolution with a Gaussian kernel of width $\sigma$, the
|
|
|
|
|
possibility to add a Gaussian noise to the convolved histogram counts was also
|
2020-06-01 02:07:39 +02:00
|
|
|
|
implemented to check weather the deconvolution is affected or not by this kind
|
|
|
|
|
of interference. This approach is described in the next subsection, while the
|
|
|
|
|
noiseless results are given in this one.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
|
|
|
|
The two methods were compared for three different values of $\sigma$:
|
|
|
|
|
$$
|
|
|
|
|
\sigma = 0.1 \, \Delta \theta \et
|
|
|
|
|
\sigma = 0.5 \, \Delta \theta \et
|
|
|
|
|
\sigma = \Delta \theta
|
|
|
|
|
$$
|
|
|
|
|
Since the RL method depends on the number $r$ of performed rounds, in order to
|
2020-06-01 02:07:39 +02:00
|
|
|
|
find out how many are sufficient or necessary to compute, the earth mover's
|
|
|
|
|
distance between the deconvolved signal and the original one was measured for
|
|
|
|
|
different $r$s for each of the three tested values of the kernel $\sigma$.
|
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
To achieve this goal, a number of 1000 experiments was simulated. Each one
|
|
|
|
|
consists in generating the diffraction signal, convolving it with a kernel
|
2020-06-01 02:07:39 +02:00
|
|
|
|
of width $\sigma$, deconvolving with the RL algorithm with a given number of
|
|
|
|
|
rounds $r$ and measuring the EMD.
|
|
|
|
|
The distances are used to build an histogram of EMD distribution, from which
|
|
|
|
|
mean and standard deviation are computed.
|
|
|
|
|
This procedure was repeated for a few tens of different $r$s till a flattening
|
|
|
|
|
or a minimum of the curve became evident. All the results are shown in
|
|
|
|
|
@fig:rounds-noiseless.
|
|
|
|
|
|
|
|
|
|
The plots in @fig:rless-0.1 show the average (red) and standard deviation
|
|
|
|
|
(grey) of the measured EMD for $\sigma = 0.1 \, \Delta \theta$. The number of
|
2020-05-21 18:50:21 +02:00
|
|
|
|
iterations does not affect the quality of the outcome (those fluctuations are
|
2020-06-01 02:07:39 +02:00
|
|
|
|
merely a fact of floating-points precision) and the best result is obtained for
|
|
|
|
|
$r = 2$, meaning that the convergence of the RL algorithm is really fast and
|
2020-06-03 21:56:05 +02:00
|
|
|
|
this is due to the fact that the histogram was only slightly modified.
|
2020-06-01 02:07:39 +02:00
|
|
|
|
In @fig:rless-0.5, the curve starts to flatten at about 10 rounds, whereas in
|
|
|
|
|
@fig:rless-1 a minimum occurs around \num{5e3} rounds, meaning that, whit such
|
|
|
|
|
a large kernel, the convergence is very slow, even if the best results are
|
|
|
|
|
close to the one found for $\sigma = 0.5$.
|
|
|
|
|
The following $r$s were chosen as the most fitting:
|
2020-05-21 18:50:21 +02:00
|
|
|
|
\begin{align*}
|
2020-07-05 17:53:52 +02:00
|
|
|
|
\sigma = 0.1 \, \Delta \theta &\thus r^{\text{best}} = 2 \\
|
|
|
|
|
\sigma = 0.5 \, \Delta \theta &\thus r^{\text{best}} = 10 \\
|
|
|
|
|
\sigma = 1 \, \Delta \theta &\thus r^{\text{best}} = \num{5e3}
|
2020-05-21 18:50:21 +02:00
|
|
|
|
\end{align*}
|
|
|
|
|
|
|
|
|
|
Note the difference between @fig:rless-0.1 and the plots resulting from $\sigma =
|
|
|
|
|
0.5 \, \Delta \theta$ and $\sigma = \, \Delta \theta$ as regards the order of
|
|
|
|
|
magnitude: the RL deconvolution is heavily influenced by the variance magnitude:
|
2020-06-03 21:56:05 +02:00
|
|
|
|
the greater $\sigma$, the worse the deconvolved result.
|
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
On the other hand, the FFT deconvolution procedure is not affected by $\sigma$
|
|
|
|
|
amplitude changes: it always gives the same outcome, which would be exactly the
|
2020-06-03 21:56:05 +02:00
|
|
|
|
original signal, if the floating point precision would not affect the result,
|
|
|
|
|
being the FFT the analytical result of the deconvolution.
|
|
|
|
|
For this reason, the EMD obtained with the FFT can be used as a reference point
|
|
|
|
|
against which to compare the EMDs measured with RL.
|
|
|
|
|
As described above, for a given $r$, a thousands of experiments were simulated:
|
|
|
|
|
for each of this simulations, an EMD was computed. Besides computing their
|
|
|
|
|
average and standard deviations, those values were used to build histograms
|
|
|
|
|
showing the EMD distribution.
|
|
|
|
|
Once the best numbers of rounds $r^{\text{best}}$ were found, their histograms
|
|
|
|
|
were compared to the histograms of the FFT results, started from the same
|
|
|
|
|
convolved signals, and the EMD of the convolved signals themselves, in order to
|
|
|
|
|
check if an improvement was truly achieved. Results are shown in
|
|
|
|
|
@fig:emd-noiseless.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
2020-06-02 00:22:27 +02:00
|
|
|
|
::: {id=fig:rounds-noiseless}
|
2020-05-21 18:50:21 +02:00
|
|
|
|
![](images/6-nonoise-rounds-0.1.pdf){#fig:rless-0.1}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
![](images/6-nonoise-rounds-0.5.pdf){#fig:rless-0.5}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
![](images/6-nonoise-rounds-1.pdf){#fig:rless-1}
|
|
|
|
|
|
|
|
|
|
EMD as a function of RL rounds for different kernel $\sigma$ values. The
|
2020-06-03 21:56:05 +02:00
|
|
|
|
average is shown in red and the standard deviation in grey. Noiseless results.
|
2020-06-02 00:22:27 +02:00
|
|
|
|
:::
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
2020-06-02 00:22:27 +02:00
|
|
|
|
::: {id="fig:emd-noiseless"}
|
2020-05-21 18:50:21 +02:00
|
|
|
|
![$\sigma = 0.1 \, \Delta \theta$](images/6-nonoise-emd-0.1.pdf){#fig:eless-0.1}
|
|
|
|
|
|
|
|
|
|
![$\sigma = 0.5 \, \Delta \theta$](images/6-nonoise-emd-0.5.pdf){#fig:eless-0.5}
|
|
|
|
|
|
|
|
|
|
![$\sigma = \Delta \theta$](images/6-nonoise-emd-1.pdf){#fig:eless-1}
|
|
|
|
|
|
|
|
|
|
EMD distributions for different kernel $\sigma$ values. The plots on the left
|
|
|
|
|
show the results for the FFT deconvolution, the central column the results for
|
|
|
|
|
the RL deconvolution and the third one shows the EMD for the convolved signal.
|
|
|
|
|
Noiseless results.
|
2020-06-02 00:22:27 +02:00
|
|
|
|
:::
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
|
|
|
|
As expected, the FFT results are always of the same order of magnitude,
|
2020-05-26 10:07:30 +02:00
|
|
|
|
\num{1e-15}, independently from the kernel width, whereas the RL deconvolution
|
2020-06-01 02:07:39 +02:00
|
|
|
|
is greatly affected by it, ranging from \num{1e-16} for $\sigma = 0.1 \, \Delta
|
|
|
|
|
\theta$ to \num{1e-4} for $\sigma = \Delta \theta$.
|
|
|
|
|
On the other hand, the first result came off as a surprise: for very low values
|
|
|
|
|
of $\sigma$, the RL routine gives better results. Apparently the RL algorithm
|
|
|
|
|
is more numerically stable than a FFT, which is more affected by floating
|
|
|
|
|
points round-off errors.
|
|
|
|
|
|
|
|
|
|
Regarding the comparison with the convolved signal, which shows always
|
2020-05-26 10:07:30 +02:00
|
|
|
|
an EMD of \num{1e-2}, both RL and FFT always return results closer to the
|
2020-06-01 02:07:39 +02:00
|
|
|
|
original signal, meaning that the deconvolution is indeed working.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### Noisy results
|
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
In order to observe the effect of the Gaussian noise on the two deconvolution
|
2020-06-01 02:07:39 +02:00
|
|
|
|
methods, a value of $\sigma = 0.8 \, \Delta \theta$ for the kernel width was
|
|
|
|
|
arbitrary chosen. The noise was then applied to the convolved histogram as
|
|
|
|
|
follows.
|
2020-05-21 18:50:21 +02:00
|
|
|
|
|
2020-06-03 21:56:05 +02:00
|
|
|
|
![Example of noisy histogram,
|
2020-05-21 18:50:21 +02:00
|
|
|
|
$\sigma_N = 0.05$.](images/6-noisy.pdf){#fig:noisy}
|
|
|
|
|
|
|
|
|
|
For each bin, once the convolved histogram was computed, a value $v_N$ was
|
2020-06-03 21:56:05 +02:00
|
|
|
|
randomly sampled from a Gaussian distribution with standard deviation
|
2020-05-21 18:50:21 +02:00
|
|
|
|
$\sigma_N$, and the value $v_n \cdot b$ was added to the bin itself, where $b$
|
2020-06-01 02:07:39 +02:00
|
|
|
|
is the count of the bin. An example with $\sigma_N = 0.05$ of the new
|
2020-05-21 18:50:21 +02:00
|
|
|
|
histogram is shown in @fig:noisy.
|
|
|
|
|
The following three values of $\sigma_N$ were tested:
|
|
|
|
|
$$
|
|
|
|
|
\sigma_N = 0.005 \et
|
|
|
|
|
\sigma_N = 0.01 \et
|
2020-06-03 21:56:05 +02:00
|
|
|
|
\sigma_N = 0.05
|
2020-05-21 18:50:21 +02:00
|
|
|
|
$$
|
|
|
|
|
The same procedure followed in @sec:noiseless was then repeated for noisy
|
|
|
|
|
signals. Hence, in @fig:rounds-noise the EMD as a function of the RL rounds is
|
|
|
|
|
shown, this time varying $\sigma_N$ and keeping $\sigma = 0.8 \, \Delta \theta$
|
2020-06-03 21:56:05 +02:00
|
|
|
|
constant.
|
|
|
|
|
|
|
|
|
|
::: {id=fig:rounds-noise}
|
|
|
|
|
![](images/6-noise-rounds-0.005.pdf){#fig:rnoise-0.005}
|
|
|
|
|
|
|
|
|
|
![](images/6-noise-rounds-0.01.pdf){#fig:rnoise-0.01}
|
|
|
|
|
|
|
|
|
|
![](images/6-noise-rounds-0.05.pdf){#fig:rnoise-0.05}
|
|
|
|
|
|
|
|
|
|
EMD as a function of RL rounds for different noise $\sigma_N$ values with the
|
|
|
|
|
kernel $\sigma = 0.8 \Delta \theta$. The average is shown in red and the
|
|
|
|
|
standard deviation in grey. Noisy results.
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
|
|
::: {id=fig:emd-noisy}
|
|
|
|
|
![$\sigma_N = 0.005$](images/6-noise-emd-0.005.pdf){#fig:enoise-0.005}
|
|
|
|
|
|
|
|
|
|
![$\sigma_N = 0.01$](images/6-noise-emd-0.01.pdf){#fig:enoise-0.01}
|
|
|
|
|
|
|
|
|
|
![$\sigma_N = 0.05$](images/6-noise-emd-0.05.pdf){#fig:enoise-0.05}
|
|
|
|
|
|
|
|
|
|
EMD distributions for different noise $\sigma_N$ values. The plots on the left
|
|
|
|
|
show the results for the FFT deconvolution, the central column the results for
|
|
|
|
|
the RL deconvolution and the third one shows the EMD for the convolved signal.
|
|
|
|
|
Noisy results.
|
|
|
|
|
:::
|
|
|
|
|
|
2020-05-21 18:50:21 +02:00
|
|
|
|
In @fig:rnoise-0.005, the flattening is achieved around $r = 20$ and in
|
|
|
|
|
@fig:rnoise-0.01 it is sufficient $\sim r = 15$. When the noise becomes too
|
2020-06-01 02:07:39 +02:00
|
|
|
|
high, on the other hand, as $r$ grows, the algorithm becomes
|
|
|
|
|
largely ineffective, so only a few iterations are actually needed.
|
|
|
|
|
The most fitting values were chosen as:
|
2020-05-21 18:50:21 +02:00
|
|
|
|
\begin{align*}
|
|
|
|
|
\sigma_N = 0.005 &\thus r^{\text{best}} = 20 \\
|
|
|
|
|
\sigma_N = 0.01 &\thus r^{\text{best}} = 15 \\
|
|
|
|
|
\sigma_N = 0.05 &\thus r^{\text{best}} = 1
|
|
|
|
|
\end{align*}
|
2020-06-01 02:07:39 +02:00
|
|
|
|
About the distance, as $\sigma_n$ increases, unsurprisingly the EMD grows
|
|
|
|
|
larger, ranging from $\sim$ \num{2e-4} in @fig:rnoise-0.005 to $\sim$
|
|
|
|
|
\num{1.5e-3} in @fig:rnoise-0.05.
|
|
|
|
|
Since the FFT is no more able to give the original signal as close as before,
|
2020-05-21 18:50:21 +02:00
|
|
|
|
it is no more assumed to be a reference point. In fact, as shown in @fig:noisy,
|
|
|
|
|
the FFT algorithm, when dealing with noisy signals whose noise shape is
|
|
|
|
|
unknown, is as efficient as the RL, since they share the same order of magnitude
|
|
|
|
|
regarding the EMD.
|
|
|
|
|
An increasing noise entails the shift of the convolved histogram to slightly
|
|
|
|
|
greater values, still remaining in the same order of magnitude of the noiseless
|
|
|
|
|
signals. However, the deconvolution still works, being the EMD of the convolved
|
|
|
|
|
histogram an order of magnitude greater than the worst obtained with both
|
|
|
|
|
methods.
|
|
|
|
|
|
|
|
|
|
In conclusion, when dealing with smeared signals with a known point spread
|
|
|
|
|
function, the FFT proved to be the best deconvolution method, restoring
|
|
|
|
|
perfectly the original signal to the extent permitted by the floating point
|
|
|
|
|
precision. When the point spread function is particularly small, this precision
|
|
|
|
|
problem is partially solved by the RL deconvolution process, which employs a
|
2020-06-01 02:07:39 +02:00
|
|
|
|
more stable computations.
|
|
|
|
|
However, in real world applications the measures are affected by (possibly
|
|
|
|
|
unknown) noise and the signal can only be partially reconstructed by either
|
|
|
|
|
method.
|