% vim: fdm=marker fmr=<<<,>>>
\documentclass[../thesis.tex]{subfiles}

\graphicspath{
	{.}
	{../../figures/}
	{../../../figures/}
}

\begin{document}
\chapter[Single Sine Synchronisation]{Single Sine Beacon Synchronisation and Radio Interferometry}
\label{sec:single_sine_sync}

% <<<
As shown in Chapter~\ref{sec:disciplining}, both impulsive and sine beacon signals can synchronise air shower radio detectors to enable the interferometric reconstruction of extensive air showers.
% period multiplicity/degeneracy
Although a sine beacon is the least intrusive, due to its periodicity, it can only synchronise two detectors up to its period
 (expressed as the $\Delta k_{ij}$ term in \eqref{eq:synchro_mismatch_clocks_periodic}
  \footnote{%<<<
   Note that $\Delta k_{ij}$ will be referenced in this chapter as $k_j$ since we can take station $i$ as the reference ($k_i = 0$).
  }%>>>
 ).
As previously mentioned, by choosing a beacon period much longer than the estimated accuracy of another timing mechanism, the correct periods can be ascertained.
\\

In this chapter, a different method of resolving these period mismatches is investigated by recording an impulsive signal in combination with the sine beacon.
This extra signal declares a shared time $\tTrueEmit$ that is common to the stations, after which the periods can be counted (see Figure~\ref{fig:beacon_sync:sine}).

% Same transmitter / Static setup
When the beacon transmitter is also used to emit the signal defining $\tTrueEmit$, the number of periods $k$ can be obtained directly from the signal.
However, if this calibration signal is sent from a different location, its time delays differ from the beacon's time delays.
\\
% Dynamic setup
For static setups, these time delays can be resolved by measuring the involved distances or by taking measurements of the time delays over time.
In dynamic setups, such as for transient signals, the time delays change per event and the distances are not known a priori.
The time delays must therefore be resolved from the information of a single event.
\\

\Todo{text continuity}

% Beacon + Impulsive -> discrete
In a sine beacon synchronised array, finding this minimum deviation must control for the period defects.
In general, these can be constrained using estimates of the accuracy of other timing mechanisms (see below).
\\
With a restricted set of allowed period defects, we can alternate optimising the calibration signal's origin and optimising the set of period time delays of the array.

\begin{figure}%<<<
	\centering
	\begin{subfigure}{\textwidth}
		\centering
		\includegraphics[width=\textwidth]{beacon/08_beacon_sync_timing_outline.pdf}
		\caption{
			Measure two waveforms at different antennas at approximately the same local time (clocks are not synchronised).
		}
		\label{fig:beacon_sync:timing_outline}
	\end{subfigure}
	\begin{subfigure}{\textwidth}
		\centering
		\includegraphics[width=\textwidth]{beacon/08_beacon_sync_synchronised_outline.pdf}
		\caption{
			The beacon signal is used to remove time differences smaller than the beacon's period.
			The detector clocks are now an unknown amount of periods out of sync.
		}
		\label{fig:beacon_sync:syntonised}
	\end{subfigure}
	\begin{subfigure}{\textwidth}
		\centering
		\includegraphics[width=\textwidth]{beacon/08_beacon_sync_synchronised_period_alignment.pdf}
		\caption{
			Lifting period degeneracy ($k=n-m=7$ periods) using the optimal overlap between impulsive signals.
			\Todo{note misaligned overlap due to different locations}
		}
		\label{fig:beacon_sync:period_alignment}
	\end{subfigure}
	\caption{
		Synchronisation scheme for two antennas using a continuous beacon and an impulsive signal, each emitted from a separate transmitter.
		Vertical dashed lines indicate periods of the beacon (orange),
		solid lines indicate the time of the impulsive signal (blue).
		\\
		\textit{Middle panel}: The beacon allows to resolve a small timing delay ($\Delta \tClockPhase$).
		\\
		\textit{Lower panel}: Expecting the impulsive signals to come from the same source, the overlap between the two impulsive signals is used to lift the period degeneracy ($k=n-m$).
	}
	\label{fig:beacon_sync:sine}
	\Todo{
		Redo figure without xticks and spines,
		rename $\Delta \tClockPhase$
	}
\end{figure}%>>>
% >>>

\section{Lifting the Period Degeneracy with an Air Shower}% <<<
% <<<<
% Airshower gives t0
In the case of radio detection of air showers, the very signal of the air shower itself can be used as the calibration signal.
This falls into the dynamic setup previously mentioned.
The best period defects must thus be recovered from a single event.
\\
When doing the interferometric analysis for a sine beacon synchronised array, waveforms can only be delayed by an integer amount of periods, thereby giving discrete solutions to maximizing the interferometric signal.
\Todo{add size of shower at plane vs period defects in meters}

\subsection{Air Shower simulation}
% simulation of proton E15 on 10x10 antenna
To test the idea of combining a single sine beacon with an air shower, we simulated a set of recordings of a single air shower that also contains a beacon signal.
\footnote{\Todo{Url to repository}}
\\
The air shower signal (here a $10^{16}\eV$ proton) is simulated by \acrlong{ZHAires} on a grid of 10x10 antennas with a spacing of $50$\,meters.\Todo{cite ZHAires?}
Each antenna recorded a waveform of $500$ samples with a sample rate of $1\GHz$.
Figure~\ref{fig:single:proton_waveform} shows the earliest and latest waveforms recorded by the array with their true time.
\Todo{verify numbers in paragraph}
\\
%% add beacon
A sine beacon ($\fbeacon = 51.53\MHz$) is introduced at a distance of approximately $75\mathrm{\,km}$ northwest of the array.
The distance between the antenna and the transmitter results in a phase offset with which the beacon is received at each antenna.%
\footnote{%<<<
	The beacon's amplitude is also dependent on the distance. Although simulated, this effect has not been incorporated in the analysis as it is neglible for the considered grid and distance to the transmitter.
} %>>>
The beacon signal is recorded over a longer time, to be able to distinguish the beacon and air shower later in the analysis.
\\
The final waveform of an antenna (see Figure~\ref{fig:single:annotated_full_waveform}) is then constructed by adding its beacon and air shower waveforms and bandpassing with relevant frequencies (here $30$ and $80\MHz$ are taken by default).
Of course, a gaussian white noise component can be introduced to the waveform as a simple noise model (see Figure~\ref{fig:sine:time_accuracy} for a treatise on the timing accuracy of a sine beacon).
\\

\begin{figure}%<<<
	\centering
	%\begin{subfigure}{0.47\textwidth}
	%	\includegraphics[width=\textwidth]{ZH_simulation/array_geometry_shower_amplitude.pdf}
	%	\caption{}
	%	\label{fig:single:proton_grid}
	%\end{subfigure}
	%\hfill
	\begin{subfigure}[t]{0.47\textwidth}
		\includegraphics[width=\textwidth]{ZH_simulation/first_and_last_simulated_traces.pdf}
		\caption{}
		\label{fig:single:proton_waveform}
	\end{subfigure}
	\hfill
	\begin{subfigure}[t]{0.47\textwidth}
		\includegraphics[width=\textwidth]{ZH_simulation/ba_measure_beacon_phase.py.A74.no_mask.zoomed.pdf}
		\caption{}
		\label{fig:single:annotated_full_waveform}
	\end{subfigure}
	\caption{
		\textit{Left:}
		%The 10x10 antenna grid used for recording the air shower.
		%Colours indicate the maximum electric field recorded at the antenna.
		%\textit{Right:}
		Example of the earliest and latest recorded air shower waveforms in the array as simulated by ZHAires.
		\textit{Right:}
		Excerpt of a fully simulated waveform (blue) containing the air shower (a $10^{16}\eV$~proton), the beacon (orange, $\fbeacon = 51.53\MHz$) and noise.
		\Todo{indicate cuts?}
	}
	\label{fig:single:proton}
\end{figure}%>>>

% randomise clocks
After the creation of the antenna waveforms, the clocks are randomised by sampling a gaussian distribution with a standard deviation of $30\ns$ (see Figure~\ref{fig:simu:sine:periods:repair_none}).
At a beacon period of $\sim 20\ns$, this ensures that multiple antennas have clock defects of at least one beacon period.
This in turn allows for synchronisation mismatches of more than one beacon period.
Moreover, it falls in the order of magnitude of clock defects that were found in \gls{AERA}\cite{PierreAuger:2015aqe}.
\\

% separate air shower from beacon
To correctly recover the beacon from the waveform, it must be separated from the air shower.
In Figure~\ref{fig:single:annotated_full_waveform} it is readily identified at $t=500\ns$.
Since the beacon can be recorded for much longer than the air shower signal, we mask a window of $500$ samples around the maximum of the trace as the air shower's signal.
% measure beacon phase, remove distance phase
The remaining waveform is fed into a \gls{DTFT} \eqref{eq:fourier:dtft} to measure the beacon's phase $\pMeas$ and amplitude.
\\
With the obtained beacon parameters, the air shower signal is in turn reconstructed by subtracting the beacon from the full waveform in the time domain.
\\
The small clock defect $\tSmallClock$ is then finally calculated from the beacon's phase $\pMeas$ by subtracting the phase $\pProp$ introduced by the propagation from the beacon transmitter.
\\

% introduce air shower
From the above, we now have a set of reconstructed air shower waveforms with corresponding clock defects smaller than one beacon period $T$.
Shifting the waveforms to remove these small clocks defects, we are left with resolving the correct number of periods $k$ per waveform (see Figure~\ref{fig:simu:sine:periods:repair_phases}).
\\

\begin{figure}%<<<
	\centering
	\includegraphics[width=0.8\textwidth]{ZH_simulation/findks/ca_period_from_shower.py.run0.i1.kfind.zoomed.peak.pdf}
	\caption{
		Finding the maximum correlation for integer period shifts (up to $k=3$) between two waveforms recording the same (simulated) air shower.
		Randomising the antenna clocks up to $30\ns$ and $\fbeacon = 51.53\MHz$ corresponds to at most $3$ periods of time difference between two waveforms.
		\Todo{location origin}
	}
	\label{fig:single:k-correlation}
\end{figure}%>>>

% >>>>
\subsection{\textit{k}-finding} % <<<

% unknown origin of air shower signal
Up until now, the shower axis and thus the origin of the air shower signal here have not been resolved.
This means that the unknown propagation time delays for the air shower ($\tProp$) affect the alignment of the signals in Figure~\ref{fig:beacon_sync:period_alignment} in addition to the unknown clock period defects ($k_j T$).
As such, both this origin and the clock defects have to be determined simultaneously.
\\
% radio interferometry
If the antennas had been fully synchronised, radio interferometry as introduced in Section~\ref{sec:interferometry} can be applied to find the origin of the air shower signal, thus resolving the shower axis.
Still, a rough first estimate of the shower axis might be made using this or other techniques (see Figure~\ref{fig:dynamic-resolve}).
\\

Starting with an initial grid around this estimated axis, a two-step process zooms in on the shower axis while optimising the interferometric signal.
In this process each waveform of the array is allowed to shift by a restricted amount of periods with respect to a reference waveform (taken to be the waveform with the highest maximum).
\\
Note that the grids in Figure~\ref{fig:findks} are defined in shower plane coordinates with $\vec{v}$ the shower axis and \vec{B} the local magnetic field.
\\

The first step consists of finding the set of period shifts $k_j$ that maximizes the overall maximum amplitude on the grid.
At each location, after removing propagation delays, each waveform and the reference waveform are summed while varying the time delay $kT$ ($\left| k \right| \leq 3$ in Figure~\ref{fig:single:k-correlation}) to find the maximum attainable amplitude of this combined trace.
\footnote{%<<<
	Note that one could use a correlation method instead of a maximum to select the best time delay.
	However, for simplicity and ease of computation, this has not been implemented.
%\Todo{incomplete p}
%As shown in Figure~\ref{fig:single:annotated_full_waveform}, the air shower signal has a length in the order of a few nanoseconds.
%Since it is this peak that is of interest, it would have been possible to cut the waveforms such to only correlate the peaks.
}%>>>
\\
%
This amplitude optimisation is iterated over the grid (see Figure~\ref{fig:findks:maxima}) resulting in a grid measurement of the maximum attainable amplitude and the corresponding set of period defects $k$.
\\

The second step then uses the period defects belonging to the highest maximum amplitude to measure the interferometric power on the same grid (see Figure~\ref{fig:findks:reconstruction}).
Afterwards, a new grid zooms in on the power maximum and the process is repeated (Figures~\ref{fig:findks:maxima:zoomed} and \ref{fig:findks:reconstruction:zoomed}) until the set of period defects does not change between grids.
\\

\begin{figure}%<<< findks
	\begin{subfigure}[t]{0.45\textwidth}
		\includegraphics[width=\textwidth]{ZH_simulation/findks/ca_period_from_shower.py.maxima.run0.pdf}
		\caption{
			Maximum amplitudes obtainable by shifting the waveforms.
		}
		\label{fig:findks:maxima}
	\end{subfigure}
	\hfill
	\begin{subfigure}[t]{0.45\textwidth}
		\includegraphics[width=\textwidth]{ZH_simulation/findks/ca_period_from_shower.py.reconstruction.run0.power.pdf}
		\caption{
			Power measurement with the $k$s belonging to the overall maximum of the amplitude maxima.
		}
		\label{fig:findks:reconstruction}
	\end{subfigure}
	\\
	\begin{subfigure}[t]{0.45\textwidth}
		\includegraphics[width=\textwidth]{ZH_simulation/findks/ca_period_from_shower.py.maxima.run1.pdf}
		\caption{
			Maximum amplitudes, zoomed to the location in \ref{fig:findks:reconstruction} with the highest amplitude.
		}
		\label{fig:findks:maxima:zoomed}
	\end{subfigure}
	\hfill
	\begin{subfigure}[t]{0.45\textwidth}
		\includegraphics[width=\textwidth]{ZH_simulation/findks/ca_period_from_shower.py.reconstruction.run1.power.pdf}
		\caption{
			Power measurement of the new grid.
		}
		\label{fig:findks:reconstruction:zoomed}
	\end{subfigure}
	\caption{
		Iterative $k$-finding algorithm:
		First (\textit{upper left}), find the set of period shifts $k$ per point on a grid that returns the highest maximum amplitude (blue cross).
		The grid starts as a $8^\circ$ wide shower plane slice at $X=400\mathrm{\,g/cm}$, centered at the true shower axis (red cross).
		Second (\textit{upper right}), perform the interferometric reconstruction with this set of period shifts.
		Finally (\textit{lower panes}), zooming in on the maximum power of the reconstruction, repeat the steps until the set of period shifts does not change.
	}
	\label{fig:findks}
\end{figure}%>>>
% >>>

%\phantomsection
\subsection{Strategy / Result} %<<<

The initial grid plays an important role in finding the correct axis.
Due to selecting the highest maximum amplitude, and the process above zooming in aggressively, wrong candidate axes are selected when there is no grid-location sufficiently close to the true axis.
\\
% premature optimisation / degeneracy
Such locations are subject to differences in propagation delays that are in the order of a few beacon periods.
The restriction of the possible delays is therefore important to limit the number of potential axes.
\\

% fall in local extremum, maximum
As the number of computations scales linearly with the number of grid points ($N = N_x N_y$), it is favourable to minimise the number of grid locations.
Unfortunately, the above process has been observed to fall into local maxima when a too coarse initial grid ($N_x < 13$ points over $8^\circ$ around the true axis\Todo{words}) was used while restricting the time delays to $\left| k \right| \leq 3$.
\\

In this analysis, the initial grid is defined as $8^\circ$ wide around the true axis.\Todo{why?}
Figure~\ref{fig:findks:reconstruction} shows such a potential point near $(-1, 0.5)$ with a maximum that is comparable to the selected maximum near the true axis.

\bigskip


Figures~\ref{fig:simu:sine:periods, fig:grid_power_time_fixes} show the effect of the various synchronisation stages on both the alignment of the air shower waveforms, and the interferometric power measurement near the true shower axis.
\\

%\begin{figure}%<<< fig:simu:sine:periods
%	\centering
%	\begin{subfigure}[t]{0.45\textwidth}
%		\includegraphics[width=\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.repair_none.axis.trace_overlap.repair_none.pdf}
%		\caption{
%			Randomised clocks
%		}
%		\label{fig:simu:sine:periods:repair_none}
%	\end{subfigure}
%	\hfill
%	\begin{subfigure}[t]{0.45\textwidth}
%		\includegraphics[width=\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.repair_phases.axis.trace_overlap.repair_phases.pdf}
%		\caption{
%			Clock syntonisation
%		}
%		\label{fig:simu:sine:periods:repair_phases}
%	\end{subfigure}
%	\\
%	\begin{subfigure}[t]{0.45\textwidth}
%		\includegraphics[width=\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.no_offset.axis.trace_overlap.no_offset.pdf}
%		\caption{
%			True clocks
%		}
%		\label{fig:simu:sine:periods:no_offset}
%	\end{subfigure}
%	\hfill
%	\begin{subfigure}[t]{0.45\textwidth}
%		\includegraphics[width=\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.repair_full.axis.trace_overlap.repair_full.pdf}
%		\caption{
%			Fully resolved clocks
%		}
%		\label{fig:simu:sine:periods:repair_full}
%	\end{subfigure}
%	\caption{
%		Trace overlap for a position on the true shower axis for different stages of array synchronisation.
%		\Todo{x-axis relative to reference waveform, remove titles, no SNR}
%	}
%	\label{fig:simu:sine:periods}
%\end{figure}%>>>

\begin{figure}%<<< grid power time fixes
	%\vspace{-2cm}
	\centering
	\begin{subfigure}[t]{0.9\textwidth}
		\includegraphics[width=0.45\textwidth]{radio_interferometry/dc_grid_power_time_fixes.py.X400.repair_none.scale4d.pdf}
		\hfill
		\includegraphics[width=0.46\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.repair_none.axis.trace_overlap.repair_none.pdf}
		\caption{
			Randomised clocks
		}
		\label{fig:grid_power:repair_none}
	\end{subfigure}
	%\hfill
	\\
	\begin{subfigure}[t]{0.9\textwidth}
		\includegraphics[width=0.45\textwidth]{radio_interferometry/dc_grid_power_time_fixes.py.X400.repair_phases.scale4d.pdf}
		\hfill
		\includegraphics[width=0.46\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.repair_phases.axis.trace_overlap.repair_phases.pdf}
		\caption{
			Clock syntonisation
		}
		\label{fig:grid_power:repair_phases}
	\end{subfigure}
	\\
	\begin{subfigure}[t]{0.9\textwidth}
		\includegraphics[width=0.45\textwidth]{radio_interferometry/dc_grid_power_time_fixes.py.X400.repair_all.scale4d.pdf}
		\hfill
		\includegraphics[width=0.46\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.repair_full.axis.trace_overlap.repair_full.pdf}
		\caption{
			Fully resolved clocks
		}
		\label{fig:grid_power:repair_full}
	\end{subfigure}
	\\
	\begin{subfigure}[t]{0.9\textwidth}
		\includegraphics[width=0.45\textwidth]{radio_interferometry/dc_grid_power_time_fixes.py.X400.no_offset.scale4d.pdf}
		\hfill
		\includegraphics[width=0.46\textwidth]{radio_interferometry/trace_overlap/on-axis/dc_grid_power_time_fixes.py.no_offset.axis.trace_overlap.no_offset.pdf}
		\caption{
			True clocks
		}
		\label{fig:grid_power:no_offset}
	\end{subfigure}
	\caption{
		Different stages of array synchronisation (unsynchronised, beacon synchronised, $k$-resolved and true clocks).
		\allowbreak
		\textit{Right:} The overlap between the array's waveforms at the true axis.
		\allowbreak
		\textit{Left:} Power measurements near the simulation axis (red plus).
		The maximum power is indicated by the blue cross.
%		\Todo{x-axis relative to reference waveform, remove titles, no SNR}
	}
	\label{fig:grid_power_time_fixes}
\end{figure}%>>>
% >>>
\end{document}
