% Created 2024-03-15 Fri 16:58
% Intended LaTeX compiler: pdflatex
\documentclass[usenames,dvipsnames,colorlinks,aspectratio=169]{beamer}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{color}
\usepackage{listings}
\usepackage{pdfpages}
\usepackage{xcolor}
\usepackage{graphicx}
\usepackage{xspace}
\usepackage{libertine}
\usepackage{fontawesome}
\mode<beamer>{\usetheme{Boadilla}}
\setbeamertemplate{navigation symbols}{}
\setbeamerfont{alerted text}{series=\bfseries}
\setbeamercolor{alerted text}{fg=blue}
\usecolortheme{default}
\usefonttheme{serif}
\usefonttheme{professionalfonts}
\lstloadlanguages{[ISO]C++}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.50,0,0.82}
\definecolor{codeorange}{rgb}{0.95,0.3,0.1}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
commentstyle=\color{codegreen},
keywordstyle=\color{codeorange},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\usepackage{siunitx}
\usepackage{multirow}
\usetheme{default}
\author{Brett Viren with Lino Gerlach, Wenqiang Gu, Nitish Nayak, and Xin Qian}
\date{\today}
\title{LMN Resampling for DUNE TPC Raw Data}
\hypersetup{
 pdfauthor={Brett Viren with Lino Gerlach, Wenqiang Gu, Nitish Nayak, and Xin Qian},
 pdftitle={LMN Resampling for DUNE TPC Raw Data},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 28.2 (Org mode 9.7-pre)}, 
 pdflang={English}}
\begin{document}

\maketitle
\begin{frame}[label={sec:orge9fe2ef}]{Topics}
\begin{itemize}
\item DUNE FD TPC ADC sampling\textbf{\underline s} and problems they pose to offline software.
\item \alert{Proposal} for mitigation via \alert{resampling} of TPC ADC waveforms.
\item Resampling techniques and ``LMN'' optimization trick.
\item Understanding normalization when resampling.
\item Example of resampling applied to DUNE FD simulation.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org5ecc671}]{Some LArTPC ADC samplings}
\begin{center}
\begin{tabular}{|c|r|r|r|}
\hline
Detector & \(T\) (ns) & \(F\) (MHz) & ADC (bits)\\
\hline
\hline
past (PD-1,MB) & 500 & 2.000000 & 12\\
\hline
\hline
DUNE FD &  &  & \\
\hline
VD TDE & 500 & 2.000000 & 14\\
\hline
VD BDE & 512 & 1.953125 & 14\\
\hline
HD & 512 & 1.953125 & 14\\
\hline
\end{tabular}
\end{center}

\begin{center}
Sampling period \(T\) (``tick''), frequency \(F\) and ADC resolution.
\end{center}
\end{frame}
\begin{frame}[label={sec:org2f66950}]{A variety of sample periods leads to problems}
Some facts.

\begin{itemize}
\item DUNE official requirements state softly, ``\(T \approx\qty{500}{ns}\)''.
\item The mix of \qty{500}{ns} and \qty{512}{ns} was accepted by DUNE project management.

\vfill
\end{itemize}

Headaches for \alert{offline software}.

\begin{itemize}
\item VD BD/TD will need two field responses calculations, despite same CRP design.
\item Many, otherwise identical configurations require bifurcation, error prone.
\end{itemize}

\vfill

Not to be discounted: mental math in easier in \qty{2}{MHz} than \qty{1.953125}{MHz}!
\end{frame}
\begin{frame}[label={sec:org46a8d23}]{Proposal}
\begin{quote}
Inside the \alert{first processing stage of the Offline Software} (Wire-Cell noise-filter + signal
processing) we will \alert{upsample} from \(T_s=\qty{512}{ns}\) to \(T_r=\qty{500}{ns}\).
\end{quote}
\end{frame}
\begin{frame}[label={sec:org15cbd4f}]{Questions on the proposal}
Why standardize on \qty{500}{ns}?
\begin{itemize}
\item Upsampling is \alert{information-lossless} from a sampling-theory perspective.
\end{itemize}
But, then you must resample 3/4 of the channels!
\begin{itemize}
\item Resampling is \alert{low-cost} via \alert{FFT and the LMN trick}, \(\mathcal{O}(1\%)\) NF+SP cost.
\end{itemize}
Why do it first thing in the offline chain?
\begin{itemize}
\item Resample \alert{far-upstream} as possible to hide variance from so majority of software.
\item Need only single VD field-response calculation, no configuration bifurcation.
\item Caveat: mitigating ``non-spectral'' pathology (stuck-bits, etc) may require original waveforms.   Can place special NF component just prior to resampling.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org1e5c404}]{Conventional resampling techniques \(N_s \to N_r\)}
\ldots{}are typically performed in two integer-factor stages:

\vfill

\begin{center}
\begin{tabular}{lrl}
 & integer upsample: & \(N_s \to N_u = LN_s\)\\
+ & integer downsample: & \(N_u \to N_r = N_u/M\)\\
\hline
= & rational\(^*\) resample: & \(N_s \to N_r = RN_s,\ R\equiv \frac{L}{M}\)\\
\end{tabular}
\end{center}

\begin{center}
\(L, M, N \in \mathbb{N}\)
\end{center}

\vfill

\scriptsize

\(^*\)An irrational \(R'\) must be approximated by some integer ratio \(R=\frac{L}{M}\).
\end{frame}
\begin{frame}[label={sec:org353c281}]{Summary of conventional resampling}
Next, we give a summary over a \(2 \times 2\) space of:
\begin{itemize}
\item The \alert{upsample} and \alert{downsample} steps.
\item Operate in \alert{interval} (time) \emph{vs} \alert{frequency} domains.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org28c7cb1}]{Conventional (time) \alert{interval-domain} resampling}
\begin{block}{Upsampling \(N \to N_u = LN\)}
\begin{enumerate}
\item \alert{Insert} \(L-1\) zero-value samples after each of the original \(N\) samples.
\item \alert{Convolve} with a smoothing filter, eg (truncated) \(sinc()\).
\end{enumerate}
\end{block}
\begin{block}{Downsampling \(N \to N_d = \lfloor N/M \rfloor\)}
\begin{enumerate}
\item \alert{Convolve} with anti-alias filter, eg (truncated) \(sinc()\).
\item \alert{Decimate} by retaining 1 out of very \(M\) consecutive samples.
\item Ignore any trailing remainder when \(N/M \not\in \mathbb{N}\).
\end{enumerate}
\end{block}
\end{frame}
\begin{frame}[label={sec:org4b0e461}]{Conventional \alert{frequency-domain} resampling}
\begin{block}{Upsampling \(N \to N_u = LN\)}
\begin{enumerate}
\item \alert{Transform} (DFT) to frequency-domain sequence.
\item \alert{Insert} \((L-1)N\) zero samples above the Nyquist frequency.
\begin{itemize}
\item Equivalent to a perfect smoothing filter.
\end{itemize}
\item \alert{Transform} (inverse DFT) to interval-domain sequence.
\end{enumerate}
\end{block}
\begin{block}{Downsampling \(N \to N_d = N/M\)}
\begin{enumerate}
\item \alert{Transform} (DFT) to frequency-domain sequence.
\item \alert{Remove} \((M-1)N\) samples above desired, resampled Nyquist frequency.
\begin{itemize}
\item Equivalent to a perfect anti-alias filter.
\end{itemize}
\item \alert{Transform} (inverse DFT) to interval-domain sequence.
\end{enumerate}

Caveat: must have signal size \(N\) such that \(N/M \in \mathbb{N}\) (no remainder).
\end{block}
\begin{columns}
\begin{column}{1\columnwidth}
\small Foreshadow: note how up\#3 and down\#1 cancel!
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org282ee2b}]{Issues with conventional resampling}
\begin{block}{Desired \(R\) may lead to ruinously large \(L\) and \(M\)}
\(R = L/M = N_r/N_s = T_s/T_r = \qty{512}{ns}/\qty{500}{ns} \Rightarrow L = 128,\ M = 125\).
\end{block}
\begin{block}{Costly time-domain convolution of low-pass downsample filter}
It is \(\mathcal{O}(N_sN_r)\) while frequency domain operations cost \(\mathcal{O}(N_s \log N_s) + \mathcal{O}(N_s or N_r) + \mathcal{O}(N_r \log N_r)\).
\end{block}
\begin{block}{Frequency-domain downsampling requires \(N/M \in \mathbb{N}\)}
We must have a ``lucky size'' to do this, else use time-domain's freedom to have a ``remainder''.
\end{block}
\begin{columns}
\begin{column}{1.0\columnwidth}
Can we make our own luck?
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org40d4654}]{The LMN trick}
\begin{block}{Unified LMN resampling}
\begin{enumerate}
\item \alert{Calculate} ``lucky'' size \(N_s\) from original size \(N\) and desired ratio \(R \ni N_r = \frac{L}{M}N_s \in \mathbb{N}\).
\item \alert{Pad or truncate} interval-domain sequence to size \(N \to N_s\).
\begin{itemize}
\item May exploit padding to mitigate ringing artifacts.
\end{itemize}
\item \alert{Transform} (DFT) to frequency domain.
\item \alert{Apply resampling} in one step:
\begin{itemize}
\item Net-upsample: \alert{insert} \(N_r - N_s\) samples above \alert{original} Nyquist frequency.
\item Net-downsample: \alert{remove} \(N_s - N_r\) samples above \alert{resampled} Nyquist frequency.
\end{itemize}
\item \alert{Transform} (inverse DFT) to interval domain.
\end{enumerate}
\end{block}
\begin{columns}
\begin{column}{1.0\columnwidth}
There are some details to properly treat case where a ``Nyquist bin'' exists due to \(N_s,N_r \in \mathbb{N}_{even}\).
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org9bf763e}]{Finding LMN's ``lucky'' \(N_s\)}
The resampling will shift the sampling frequency by an amount:

\[ \Delta F = \frac{1}{T_r} - \frac{1}{T_s} = \frac{T_s-T_r}{T_sT_r} \]

That shift must cover an integer number \(\delta N\) of frequency samples of total bandwidth:

\[\delta F = \frac{\delta N}{N_sT_s}\]

Equating \(\delta F = \Delta F\) and solving for \(N_s\):

\[ N_s = \frac{\delta N \cdot T_r}{T_s-T_r} \in \mathbb{N}\]
\end{frame}
\begin{frame}[label={sec:org2e2733a}]{Finding LMN's minimal \(\delta N\)}
Continuing:

\[ N_s = \frac{\delta N \cdot T_r}{T_s-T_r} \in \mathbb{N}\]

A (minimum) value of \(\delta N\) that satisfies \(N_s \in \mathbb{N}\) is:

\[\delta N = \frac{T_s - T_r}{\mathrm{gcd}(T_r, T_s - T_r)}\]

Where \(\mathrm{gcd}(\cdot,\cdot)\) is the real-valued greatest-common-denominator function.
\begin{itemize}
\item The \alert{extended Euclidean algorithm} is recursive but fast to converge.
\item Any multiple of \(\delta N\) may be chosen, gives freedom to pick \(N_s\) closest
to a ``natural'' size.
\item LMN rationality: \(T_s\) and \(T_r\) must be such that \(\delta N \in \mathbb{N}\) can be found, ie \(\mathrm{gcd}()\) converges.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgcfdc92f}]{Example 1 - the finite cosine chirp \(T_s = 0.512 \to T_r = 0.500\)}
\begin{columns}
\begin{column}{0.5\columnwidth}
Original \(N=20,\ T_s = 0.512\) (arb units)
\begin{itemize}
\item Want to resample to \(T_r = 0.500\).
\item LMN says: \(\delta N = 39,\ N_s = 125\).
\end{itemize}

Note,
\begin{itemize}
\item \small High frequency \alert{ringing}.
\begin{itemize}
\item \scriptsize Tail extension may be truncated away.
\item A later low-pass filter can be used.
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth,page=1]{lmn-example.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org1f9d7b2}]{Example 2 - the finite cosine chirp \(T_s = 0.512 \to T_r = 0.200\)}
\begin{columns}
\begin{column}{0.5\columnwidth}
Original \(N=20,\ T_s = 0.512\) (arb time)
\begin{itemize}
\item Want to resample to \(T_r = 0.200\).
\item LMN says: \(\delta N = 3,\ N_s = 25\).
\end{itemize}

Note,
\begin{itemize}
\item \small \alert{Periodicity} is violated
\begin{itemize}
\item \scriptsize Tail extension may be truncated away.
\item \scriptsize But still large errors at signal beginning.
\end{itemize}
\item Can be corrected with smarter padding fill.
\begin{itemize}
\item \scriptsize Eg, linear or half-cosine interpolation.
\item Examples in backup slides.
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth,page=2]{lmn-example.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org77b5b48}]{Normalizing when resampling \(N_s \to N_r\)}
\small LMN uses a DFT round trip which gains overall normalization of \(\frac{1}{N}\).
\begin{itemize}
\item \small Dominant software convention: apply \(\frac{1}{N}\) to inverse DFT.
\item When resampling, normalization is \(\frac{1}{N_r}\) (not \(\frac{1}{N_s}\)).
\end{itemize}

Must also respect a \alert{physical normalization} that depends on the \alert{signal interpretation}.
\begin{block}{\small \alert{Interpolation}: interval-domain signal \alert{magnitude} is conserved.}
Must \alert{replace} conventional \(\frac{1}{N_r}\) normalization with \(\frac{1}{N_s}\), multiply resampled signal by \(\frac{N_r}{N_s}\).
\end{block}
\begin{block}{\small \alert{Integral}: interval-domain signal \alert{integral} is conserved.}
The conventional \(\frac{1}{N_r}\) is correct.
\end{block}
\begin{block}{\small \alert{Energy}: samples represent field/probability ``amplitude'', conserve \alert{Parseval energy}}
Must multiply resampled sequence by \(\sqrt{\frac{N_r}{N_s}}\).
\end{block}
\end{frame}
\begin{frame}[label={sec:org56b3d58}]{Example 3 - LArTPC simulation}
Strategy for this illustration:

\begin{itemize}
\item Apply LMN to resample field response: \(T_s = \qty{100}{ns} \to T_r = \qty{64}{ns}\).
\begin{itemize}
\item Saves us from having to rerun GARFIELD.
\item Itself, provides illustration of LMN.
\end{itemize}
\item Run Wire-Cell sim at \(\qty{500}{ns} = 5 \times \qty{100}{ns}\) and  \(\qty{512}{ns} = 8 \times \qty{64}{ns}\).
\item Resample ADC ticks: \(T_s = \qty{512}{ns} \to T_r = \qty{500}{ns}\)
\item Compare resampled \qty{500}{ns} to native \qty{500}{ns}.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org7e86b1c}]{LMN-upsampling of charge field response \(\qty{100}{ns} \to \qty{64}{ns}\)}
\begin{columns}
\begin{column}{0.6\columnwidth}
\includegraphics[width=\textwidth, page=8]{lmn-fr-pdsp-0.pdf}
\end{column}
\begin{column}{0.4\columnwidth}
This is \alert{charge} (not current):
\begin{itemize}
\item must \alert{interpret as integral samples}: conserve signal sum.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org0d9f771}]{Electronics response at  \qty{100}{ns} and \qty{64}{ns}}
\begin{columns}
\begin{column}{0.6\columnwidth}
\includegraphics[width=\textwidth, page=5]{lmn-fr-pdsp-0.pdf}
\end{column}
\begin{column}{0.4\columnwidth}
\(ER\) interpretation: interpolation
\begin{itemize}
\item Actually, not a \alert{resampling} but simply a sampling of an analytic function at \qty{100}{ns} and \qty{64}{ns}.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org81a72e7}]{Detector voltage response (\(Q \otimes ER\)) at \qty{100}{ns} and \qty{64}{ns}}
\begin{columns}
\begin{column}{0.6\columnwidth}
\includegraphics[width=\textwidth, page=9]{lmn-fr-pdsp-0.pdf}
\end{column}
\begin{column}{0.4\columnwidth}
Convolution \(T \cdot FR \otimes ER\) at the two samplings.
\begin{itemize}
\item \small Expect and get \alert{perfect} effective interpolation of voltage sampling.
\end{itemize}

\vfill

Foreshadow: plot is from an external calculation, not from WCT sim.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:orgab59245}]{WCT sim resampling - voltage (signal only)}
\begin{columns}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=1]{voltage_signal_near_begin_512ns_500ns.pdf}
\end{column}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=2]{voltage_signal_near_begin_512ns_500ns.pdf}
\end{column}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=3]{voltage_signal_near_begin_512ns_500ns.pdf}
\end{column}
\end{columns}
\begin{columns}
\begin{column}{1\columnwidth}
\vfill

One select channel from each view recording an ideal track going diagonal across detector.
\begin{itemize}
\item Some apparent distortion between native and resampled.
\item This is \alert{not expected} and if found to be caused by a ``feature'' of WCT \(FR \otimes ER\).
\begin{itemize}
\item Slides in backups that explains the details.
\end{itemize}
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org48c48a8}]{WCT sim resampling - ADC (signal+noise)}
\begin{columns}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=1]{adc_near_512ns_500ns.pdf}
\end{column}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=2]{adc_near_512ns_500ns.pdf}
\end{column}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=3]{adc_near_512ns_500ns.pdf}
\end{column}
\end{columns}
\begin{columns}
\begin{column}{1\columnwidth}
\vfill

Same track and channels in ADC with resampling at voltage level or at ADC level.
\begin{itemize}
\item \small Noise is common between blue (native) and green (resample at voltage).
\item Orange (resample at ADC) is representative of real-world.
\item With noise and digitization, the distortion due to bad \(FR \otimes ER\) is not significant.
\begin{itemize}
\item Still, we will fix it.
\end{itemize}
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org061c568}]{Paper}
\begin{block}{``Data Waveform Re-sampling with LMN Method''}
\small
L. Gerlach, B. Viren, W. Gu, N. Nayak, and X. Qian
\end{block}
\begin{block}{Sections}
\begin{itemize}
\item \small LArTPC signal processing,
\item LMN resampling method,
\item Performance comparison with other methods,
\item Application to LArTPC.
\end{itemize}
\end{block}
\begin{block}{Status - all but done\ldots{}}
\small Will first fix the WCT \(FR \otimes ER\) issue in order to make the story simpler.
\end{block}
\end{frame}
\begin{frame}[label={sec:org7765aa8}]{Summary}
Proposed: Wire-Cell will resample DUNE FD TPC to uniform samplings.

\begin{itemize}
\item \(\qty{512}{ns} \to \qty{500}{ns}\) for HD and VD-BD (VD-TD already at \qty{500}{ns})
\item Apply just prior to WCT NF+SP, or in NF if non-spectral mitigation needed.
\end{itemize}

Sparked development of the ``LMN trick''.

\begin{itemize}
\item Faster than conventional resampling (use FFT, no large intermediate signals).
\item Allows for perfect, low-pass filter (important for downsampling).
\item Very simple / obvious, but so far we have not found it in literature searches.
\end{itemize}

Some general ``resampling gotchyas'' explored.
\begin{itemize}
\item Avoid artifacts induced by periodicity violation, ``kinks'' in padding.
\item Proper normalization given a physical interpretation of the signal.
\end{itemize}

Paper writing close to done.
\begin{itemize}
\item Must first fix WCT sim \(FR \otimes ER\) for nicest plots.
\end{itemize}
\end{frame}
\begin{frame}[label={sec:orgbc29ca9}]{}
\begin{center}
\Huge \(\mathcal{FIN}\)
\end{center}
\end{frame}
\begin{frame}[label={sec:orgbbadebd}]{}
\end{frame}

\begin{frame}[label={sec:org1dcd0b2},fragile]{Some links}
 \begin{itemize}
\item Working repo area
\end{itemize}

\url{https://github.com/BNLIF/lmn/} 

\begin{itemize}
\item LMN functionality migrating to \texttt{wirecell.util.lmn}.
\end{itemize}

\url{https://github.com/wirecell/wire-cell-python}

\begin{itemize}
\item Paper in overleaf
\end{itemize}

\url{https://www.overleaf.com/project/65525feda20cdec448ee4390} 
\end{frame}
\begin{frame}[label={sec:orge2a5d5c}]{Non-periodic ringing example}
\begin{columns}
\begin{column}{0.5\columnwidth}
Lack of \alert{smooth wrap-around connection} leads to ``wiggles'' near endpoints.
\begin{itemize}
\item \(R=5\) net-upsample from black to red.
\item \textcolor{red}{Red upsample} has oscillatory artifacts.
\item \textcolor{ForestGreen}{Green dot} marks initial value at end.
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth,page=1]{ringing.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org32d9d25}]{Constructing periodicity with true function}
\begin{columns}
\begin{column}{0.5\columnwidth}
Simply continue to sample original function.
\begin{itemize}
\item Extrapolation is perfect as we know the underlying function.
\item But, not perfectly smooth so some artifacts remain.
\item Of course, function is unknown in measured waveforms.
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth,page=2]{ringing.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org59aee45}]{Constructing periodicity with linear extension}
\begin{columns}
\begin{column}{0.5\columnwidth}
Linearly extend original waveform.
\begin{itemize}
\item Kinks can induce high-frequency power.
\begin{itemize}
\item This power may become lost in net-downsampling or induce high-frequency ringing in net-upsampling.
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth,page=3]{ringing.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:orge3155b6}]{Constructing periodicity with half-cosine}
\begin{columns}
\begin{column}{0.5\columnwidth}
Extend original waveform with half-cosine.
\begin{itemize}
\item Care is needed to keep cosine frequency inside original signal bandwidth.
\begin{itemize}
\item O.w. same high-frequency loss/ringing as with linear kink.
\end{itemize}
\item Note, this example is identical to linear as we extend by a single \color{ForestGreen}{green} point.
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth,page=3]{ringing.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:orgc381d47}]{Response - (downsample, decimate) \(\leftrightarrow\) convolve}
\begin{columns}
\begin{column}{0.5\columnwidth}
\begin{itemize}
\item \small FR at \qty{100}{ns} has power above the Nyquist frequency for \qty{500}{ns} sampling (\qty{1}{MHz}).
\item Decimation will \alert{alias} this high-frequency power down to lower frequencies.
\item Downsampling will \alert{filter} it away.
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth, page=13]{lmn-fr-pdsp-0.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:orgf8adb4e}]{But, what is that distortion?!}
\begin{columns}
\begin{column}{0.6\columnwidth}
\includegraphics[width=\textwidth,page=1]{voltage_signal_near_begin_512ns_500ns.pdf}
\end{column}
\begin{column}{0.4\columnwidth}
\small Unexpected differences in native \qty{512}{ns} (using resampled FR), native \qty{500}{ns} and resampled \(\qty{512}{ns} \to \qty{500}{ns}\).

\begin{itemize}
\item \small Not due to HF ringing from undersampled FRs.
\item \small Not due to periodicity violation.
\item \small Not seen in external \(T \cdot FR \otimes ER\) plot just shown.
\end{itemize}

\small Likely arising in WCT's \(FR \otimes ER\) calculation.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:orgc8759cc}]{WCT's \(FR \otimes ER\)}
\begin{itemize}
\item \(FR\) is a ``fast'' signal, nominally sampled at \qty{100}{ns} (eg by GARFIELD).

\item ADC is a ``slow'' signal at \qty{500}{ns}

\item WCT sim must, at some point, downsample \(\qty{100}{ns} \to \qty{500}{ns}\).
\end{itemize}

\(2 \times 2\) set of choices in how to do that as part of \(FR \otimes ER\):
\begin{itemize}
\item \alert{convolution-then-downsample} \emph{vs} \alert{downsample-then-convolution}.
\item downsample with \alert{simple decimation} or \alert{downsample with filter}.
\end{itemize}

Turns out, three of these are equivalent while WCT implements the one deviant.
\begin{itemize}
\item \alert{decimate-then-convolve}
\end{itemize}
\end{frame}
\begin{frame}[label={sec:org3d7ed0c}]{Check \(2 \times 2\) choices - (downsample, decimate) \(\leftrightarrow\) convolve}
\begin{columns}
\begin{column}{0.5\columnwidth}
Look at all \(2 \times 2\) choices \((ds,dm) \leftrightarrow c\) .
\begin{itemize}
\item decimate-then-convolve (\(dmc\)) is deviant, the other three are coincident.
\item decimate-then-convolve worse representation of original \qty{100}{ns}.
\end{itemize}

Lack of anti-alias, low-pass filter in \alert{decimation} leads to HF aliasing (feed down).
\begin{itemize}
\item This is a \alert{classic sampling mistake!}  Doh!
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth, page=14]{lmn-fr-pdsp-0.pdf}
\end{column}
\end{columns}
\begin{columns}
\begin{column}{1\columnwidth}
Again, not significant once noise is added but we will fix this.
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org056a871}]{Why 3 of the \(2 \times 2\) are equivalent?}
\begin{block}{Why \(dsc \approx cds\)?}
The \alert{downsample} and \alert{convolve} operations are order independent.
\begin{itemize}
\item Ignoring whatever is happening in the low power, high frequency tail\ldots{}
\end{itemize}

But, why?
\begin{itemize}
\item Interval domain convolution \(a \otimes b\) is frequency domain multiplication \(A \times B\).
\item Resampling \(x_s \to x_r\) in LMN style is padding/truncation in frequency domain \(X_s \to X_r\).
\begin{itemize}
\item This is effectively applying a ``step'' aka ``box'' filter \(\to\) frequency domain multiplication!
\end{itemize}
\item Multiplication is commutative.
\end{itemize}
\end{block}
\begin{block}{Why \(cdm \approx cds\)?}
Similar reason to ``Why \(dsc \approx cds\)?'' after recognizing that the \(ER\) in
the \alert{convolution} is a good \alert{low-pass anti-alias filter} so the \alert{decimation} does not
cause aliasing.
\end{block}
\end{frame}
\begin{frame}[label={sec:org25269fa}]{DFT time-shift theorem}
A \alert{constant shift in interval domain}  is a \alert{linear phase shift in frequency domain}.

\[x_n \leftrightarrow X_k,\ \Rightarrow\  x_{n-l} \leftrightarrow X_ke^{-i2\pi k l / N}\]

To search for shifts between signals \(a_n\) and \(b_n\), may plot:
\begin{description}
\item[{relative magnitude}] \(|A_k|/|B_k|\)
\item[{relative phase}] \(phase(A_k) - phase(B_k)\).
\end{description}
\end{frame}
\begin{frame}[label={sec:org3ab2df2}]{Shift check for \(T \cdot FR \otimes EF\)}
\begin{columns}
\begin{column}{0.5\columnwidth}
No over-all time shift is seen, but:
\begin{itemize}
\item \small All choices produce deviations in power and time shift at high-frequency, where there happens to be little to no power.
\item Decimate-then-convolve (dmc) results in ``frequency-local'' time shifts where there is actually some signal power.
\begin{itemize}
\item This is likely aliasing in action.
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\columnwidth}
\includegraphics[width=\textwidth, page=15]{lmn-fr-pdsp-0.pdf}
\end{column}
\end{columns}
\end{frame}
\begin{frame}[label={sec:org742c579}]{Shift check for WCT voltage}
\begin{columns}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=1]{wct-sim-volt-diff.pdf}
\end{column}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=2]{wct-sim-volt-diff.pdf}
\end{column}
\begin{column}{0.3\columnwidth}
\includegraphics[width=\textwidth,page=3]{wct-sim-volt-diff.pdf}
\end{column}
\end{columns}
\begin{columns}
\begin{column}{1\columnwidth}
This shows same ``shift check'' plot for full WCT voltage convolution, not just single FR path.
\begin{itemize}
\item To complex to get much insight other than it being the superposition of many paths.
\item When fix \(FR \otimes ER\) to be \alert{convolve-then-downsample} expect these plots to be flat.
\end{itemize}
\end{column}
\end{columns}
\end{frame}
\end{document}
