% Created 2024-03-06 Wed 14:57
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\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}
\renewcommand{\vec}[1]{\mathbf{#1}}
\usepackage[margin=1.0in]{geometry}
\usepackage{amsmath,hyperref}
\usepackage{siunitx}
\author{Brett Viren}
\date{\today}
\title{LMN Method Section}
\hypersetup{
 pdfauthor={Brett Viren},
 pdftitle={LMN Method Section},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 28.2 (Org mode 9.7-pre)}, 
 pdflang={English}}
\begin{document}

\maketitle
\section{Description of the LMN Resampling Method}
\label{sec:orga3b0ef3}

The proposed resampling method is described.  First, established resampling methods on which the proposed is based are summarized.  Then, a special case optimization trick used in the proposed method is described along with some procedural details.  Finally, a number of normalization terms are defined to cover different interpretations of the resampling. 
\subsection{Resampling basics}
\label{sec:orgf8d9291}
\label{resbasics}

A continuous signal \(g(t)\) may be sampled at times \(t_i = i\cdot T_s, i\in [0,...,N_s-1]\) with period \(T_s\) to produce a time-domain sequence \(\vec{g}_s \equiv \{g_s[i]\},\ g_s[i] \equiv g_s(t_i)\).
From this sequence, another sequence
\(\vec{g}_r \equiv \{g_r[j]\}, j\in [0,...,N_r-1]\) may be constructed that corresponds to a \emph{resampling} of \(g(t)\) with a sampling period \(T_r \ne T_s\).
Depending on the resampling method, the bandwidth of the signal and whether the resampling results in an overall \emph{upsampling} (\(T_r < T_s\)) or \emph{downsampling} (\(T_r > T_s\)) this correspondence may be exact or approximate.

One general resampling method known as \emph{fractional resampling}\cite{fractionalresample} decomposes the resampling procedure into two stages.  First, the original sequence \(\vec{g}_s\) is upsampled by an integer factor \(L\) to produce an intermediate sequence \(\vec{g}_u\) with a larger number of samples \(N_u = LN_s\).
Second, this intermediate sequence is downsampled by an integer factor \(M\) to produce the final sequence \(\vec{g}_r\) with a number of samples \(N_r = \frac{N_u}{M}\).
The \emph{simple fraction} \(R\equiv\frac{L}{M} = \frac{N_r}{N_s}\) characterizes the fractional resampling.

When the duration of the original signal is held fixed in the resampling then \(N_s T_s = N_r T_r\) and thus \(R = \frac{T_s}{T_r}\).  Otherwise, \(\frac{T_s}{T_r}\) may be irrational and fractional resampling can not be applied exactly.  In such cases, \(R \approx \frac{T_s}{T_r}\) may be chosen to approximate the desired resampling to arbitrary precision though at the cost of potentially large values of \(L\) and \(M\).
\subsection{Discrete Fourier Transform}
\label{sec:orgf5dd105}
\label{dft}

The resampling used here is based on a subclass\cite{dftresampling} of fractional methods that operate on 
the Fourier representation of the sampled signal.
The discrete Fourier transform (DFT)
is applied to the time-domain sequence \(\vec{g}\) of size \(N\) to produce the frequency-domain sequence \(\vec{G} \equiv \{G[k]\} = DFT(\vec{g})\) with

\begin{equation}
\label{eq:fwddft}
G[k] = \sum_{n=0}^{N-1}g[n] \cdot e^{-i2\pi \frac{nk}{N}},\ k \in \mathbb{I}.
\end{equation}
This sequence is infinite and periodic \(G[k] = G[k+N]\) over size \(N\).
In a range of size \(N\) the sequence has two points of Hermitian symmetry which are important for the resampling.
The first is about the ``zero frequency'' sample \(G[0]\) so that \(G[k] = G^*[-k]\).
The second is about the Nyquist frequency and is expressed differently if the number of samples is even or odd as

\begin{equation}
\label{eq:nyqsym}
G[H-k] =
\begin{cases}
G^*[H+k+2], &  N \in \mathcal{N}_{even} \\
G^*[H+k+1], &  N \in \mathcal{N}_{odd}
\end{cases}
\end{equation}
where the size the ``half spectrum'' that consists of the sub-sequence of frequency-domain samples that are not Hermitian-symmetric with themselves is given by
\begin{equation}
\label{eq:aitch}
H =
\begin{cases}
\frac{N}{2}-1 ,& N \in \mathcal{N}_{even} \\
\frac{N-1}{2} ,& N \in \mathcal{N}_{odd}
\end{cases}
\end{equation}
For \(N \in \mathbb{N}_{even}\), the sample \(G[H+1]\) is real and called the ``Nyquist bin'' as the Nyquist frequency\cite{nyquist} lands at the center of its sample period.  For \(N\in \mathbb{N}_{odd}\), the Nyquist frequency is at the lower edge of the sample \(G[H+1]\).

There two common ways to define a finite subsequence of \(\vec{G}\) of size \(N\).
First is the ``Nyquist-centered'' range where the subset of samples \(\{G[1],...,G[H]\}\) are Hermitian-reflected about the Nyquist frequency starting with \(G[H+1] = G^*[H]\) for \(N \in \mathbb{N}_{odd}\) or with \(G[H+2] = G^*[H]\) for \(N\in \mathbb{N}_{even}\).
The second is the ``zero-centered'' range where
the same subsequence of size \(H\) is instead Hermitian-reflected about \(G[0]\).
Influenced by this second choice, the reflected subsequence is often said to consist of the ``negative frequency'' samples.

The inverse DFT may be applied to \(\vec{G}\) recover the original time-domain sequence \(\vec{g}\) as
\begin{equation}
\label{eq:invdft}
g[n] = \frac{1}{N}\sum_{k=0}^{N-1}G[k] \cdot e^{i2\pi \frac{nk}{N}},\ n \in \mathbb{I}
\end{equation}
The result of the inverse DFT is also an infinite, periodic sequence.  Note, the form of the normalization term \(\frac{1}{N}\) shown here is the convention followed by most software providing the DFT.  Additional discussion of normalization is in \autoref{sec:norm}.
\subsection{Resampling in the Fourier domain}
\label{sec:orgea53d0b}
\label{sec:dftres}

An upsampling from \(N_s\) to \(N_u = LN_s\) can be accomplished in the frequency-domain by 
inserting \((L-1)N\) samples in the middle of the Nyquist-centered range of \(\vec{G}_s\) to produce an intermediate spectrum sequence \(\vec{G}_u\) with samples

\begin{equation}
\label{eq:fdus}
G_u[k] =
\begin{cases}
G_s[k], & k \in [-H_s, ..., H_s] \\
0     , & \text{otherwise}
\end{cases}
\end{equation}
where \(H_s\) represents thevalue for the original sampling as defined in \autoref{eq:aitch} and it is assumed that \(N_s \in \mathbb{N}_{odd}\).
When \(N_s \in \mathbb{N}_{even}\) \autoref{eq:fdus} applies with the addition that the Nyquist bin at \(G_s[H+1]\) requires special treatment which is described in \autoref{sec:nyqbin}.

If \(\frac{N_u}{M} \not\in \mathbb{N}\) then the final \(M\)-wise downsampling 
must be performed in the time domain after applying the inverse DFT of size \(N_u = LN_s\) to \(\vec{G}_u\).
This allows the non-zero remainder of samples \((N_u\ \mathrm{mod}\ M)\) to be ignored and corresponds to an effective change in the duration of the resampled signal compared to the original.

In the special case that \(N_u/M \in \mathbb{N}\), the downsampling may be performed in the Fourier domain by removing  \(\frac{N_u}{M}(M-1)\) samples from the middle of the Nyquist-centered range to produce \(\vec{G}_r\) of size \(N_r\) with terms

\begin{equation}
\label{eq:fdds}
G_r[k] = G_u[k], k \in [-H_r, ..., H_r].
\end{equation}
Here, \(H_r\) is defined in \autoref{eq:aitch} for the resampled sequence and \autoref{eq:ffds} is strictly for \(N_r \in \mathbb{N}_{odd}\) while treatment of the Nyquist bin in the case \(N_r \in \mathbb{N}_{even}\) is put aside until \autoref{sec:nyqbin}.

Obviously, in this special case, the upsampling and downsampling stages may be combined so that the net number of frequency-domain samples is changed by a smaller net amount \(\Delta N = N_r - N_s\).  When \(\Delta N > 0\) a net upsampling is performed by inserting this number of zero-valued samples similar to \autoref{eq:fdus}.  
Conversely, \(\Delta N < 0\) indicates a net downsampling is performed with (the absolute value of) this number of samples removed as in \autoref{eq:fdds}.

In any case, the intermediate spectrum \(\vec{G}_r\) of size \(N_r\) is formed and the inverse DFT is applied to produce a resampled time-domain sequence \(\vec{g}_r\).
\subsection{Special case optimization}
\label{sec:orgc152c77}
\label{sec:specialcase}

The special case \(\frac{NL}{M}\in \mathbb{N}\)  can be met for any given \(T_s\) and \(T_r\) that meet a rationality condition described below and when there is freedom to choose \(N_s\).
It is possible to generate a series of values for \(N_s\) that satisfy \(N_sL/M \in \mathbb{N}\).  
The generation begins by considering that the resampling will shift the sampling frequency by an amount

\begin{equation}
    \label{eq:nfshift}
    \Delta F = \frac{1}{T_r} - \frac{1}{T_s} = \frac{T_s-T_r}{T_sT_r}.
\end{equation}
Next, this shift must span an integer number \(\delta N \in \mathbb{N}\) of original frequency-domain samples and thus must cover a frequency range

\begin{equation}
    \label{eq:ibshift}
    \delta F = \frac{\delta N}{N_sT_s}.
\end{equation}
Equating \(\delta F = \Delta F\) results in the relation

\begin{equation}
    \label{eq:nfibshift}
    N_s = \frac{\delta N \cdot T_r}{T_s - T_r} \in \mathbb{N}.
\end{equation}
The smallest value of \(|\delta N|\) that satisfies \autoref{eq:nfibshift} results in a minimal sequence count \(N_s = N_{min}\) for which the special case applies.  Any multiple of \(N_{min}\) will also satisfy the special case.
The value for this \(\delta N\) may be found as
\begin{equation}
    \label{eq:nsolve}
    \delta N = \frac{T_s - T_r}{\gcd(T_r,\ T_s - T_r)}.
\end{equation}
Here, \(\gcd(\cdot,\cdot)\) returns the greatest common divisor of its arguments.
As 
the argument are in general real valued, this function may apply the extended Euclidean algorithm\cite{eea}.
Computer floating-point round-off error will require the algorithm to test for convergence against a small, non-zero error parameter.
Note, a lack of convergence within this error indicates that the ratio of its arguments is not rational.  When this rationality condition is not met, this form of fractional resampling can not be applied exactly.
\subsection{Treatment of Nyquist bins}
\label{sec:orgb8bf4f7}
\label{sec:nyqbin}

In general, when \(N \in \mathbb{N}_{even}\) the sequence \(\vec{G}\) posses a Nyquist bin.  When resampling in the Fourier domain, this sample requires special treatment in two cases.

The first case is when a net upsampling from size \(N_s \in \mathbb{N}_{even}\) is performed.
Half of the Nyquist bin sample value is set to each of the two equivalent samples in the resampled spectrum,
\(G_r[H_s + 1] = \frac{1}{2}G_s[H_s+1]\)  and \(G_r[-H_s - 1] = \frac{1}{2}G_s[-H_s - 1]\), where this notation uses the zero-centered range.  Note, the sample \(G_r[H_s+1]\) in the upsampled spectrum is not itself a Nyquist bin.

The second and opposite case is when a net downsampling to size \(N_r \in \mathbb{N}_{even}\) is performed.
The Nyquist bin in the resampled spectrum must be set to the absolute value of either of the two corresponding samples from the original spectrum, for example as \(G_r[H_r + 1] = |G_s[H_r + 1]|\).
\subsection{Normalization}
\label{sec:org2277568}
\label{sec:norm}

A ``round trip'' of a signal sequence through both the forward and inverse DFT requires an overall normalization of \(\frac{1}{N}\) shown in \autoref{eq:invdft}.  It is a mere, if prevalent, convention to apply this normalization fully as part of the inverse DFT.  No ambiguity exists in this normalization convention 
when \(N\) is held fixed through both transforms.

However, resampling in the Fourier domain necessarily performs the forward DFT with size \(N_s\) and the inverse DFT with size \(N_r \ne N_s\).  A proper choice for the normalization depends on an interpretation of the quantity measured by a sample.  For each of three interpretations  considered a motivation for an addition normalization of the form \(g_r[i] \to g'_r[i] = Ag_r[i]\) is given.  In what follows, it is assumed that only zero-amplitude frequency-domain samples are inserted or removed in the resampling.  Subsequently, the contrary case is described.
\subsubsection{Interpolation}
\label{sec:org3b206c0}

For the first interpretation, consider the case where a time-domain sample represents an estimate of the instantaneous value of the underlying true continuous signal at a point in time.  That is, the resampling provides an interpolation of the originally sampled sequence.  The resampling leads to a change in the size of the sequence of \(\delta N = N_r - N_s\) while power is neither added to nor removed from the signal.

Taking the usual convention, it is the inverse DFT that applies a normalization of \(\frac{1}{N_r}\) and this will change the signal amplitude.  The signal amplitude will be reduced if upsampled and increased if downsampled when compared to a true resampling of the continuous signal.
Thus, an additional normalization of \(A_0 = \frac{N_r}{N_s}\) must be applied to the resampled sequence for correct interpolation.  This effectively applies the DFT normalization as part of the forward DFT instead of the inverse DFT.
\textcolor{red}{Include a figure with example?}
\subsubsection{Integral}
\label{sec:orga470a14}

For the next interpretation, consider the case where a sample represents the integral of the underlying continuous signal over the sample period.
This interpretation must preserve the sum of the time-domain sequence samples through the resampling process as expressed by
\begin{equation}
\label{sumcons}
\sum_{i}^{N_s} g_s[i] = A_1A_0\sum_{j}^{N_r} g_r[j].
\end{equation}
The notation indicates the summation is over one range of the periodicity of a sequence.
Applying the interpolation normalization \(A_0\) is equivalent to integrating each of \(N_r\) points over the original sample period \(T_s\) while integration over the resampled period \(T_r\) is proper to preserve the equality between sampled and resampled sums.  Thus an additional normalization of \(A_1 = \frac{T_r}{T_s} = \frac{N_s}{N_r}\) must be applied to the interpolation normalization interpretation.  These two additional normalization terms cancel \(A_1A_0 = 1\) and the choice to fully normalize as part of the inverse DFT is appropriate for this interpretation.
\textcolor{red}{Include a figure with example?}
\subsubsection{Energy}
\label{sec:orgc5a1c03}

For the final interpretation, consider the case that the signal represents a probability amplitude, field or other quantity where the L2-sum must be conserved through the resampling.  This sum is conserved through the forward DFT as 
expressed by Parseval's theorem which equates an energy measure in the time domain \(E_t\) to an energy measure in the frequency domain \(E_f\).  In terms of the original sampling, this may be written as
\begin{equation}
\label{parseval}
E_{t,s} \equiv \sum_{i}^{N_s} \left|g_s[i]\right|^2 = \frac{1}{N_s}\sum_{k}^{N_s} \left|G_s[k]\right|^2 \equiv E_{f,s}.
\end{equation}
The energy after resampling may be written as
\begin{equation}
\label{parsevalf}
E_{f,r} \equiv \frac{1}{N_r}\sum_{l}^{N_r} \left|G_r[l]\right|^2 = \frac{1}{N_r}\sum_{k}^{N_s} \left|G_s[k]\right|^2 = \frac{N_s}{N_r}E_{f,s}.
\end{equation}
The effective replacement \(r \to s\) in the sum of right hand term is allowed as we have assumed only zero-amplitude samples have been added or removed in the resampling.  Thus, in order for Parseval energy to be conserved throughout, an additional normalization \(A_2 = \sqrt\frac{N_r}{N_s}\) must be multiplied to the resampled time-domain sequence, \(g_r[i] \to g'_r[i] = A_2g_r[i]\).
\subsubsection{Loss}
\label{sec:org7f17757}

In the above it is assumed that only zero-amplitude frequency-domain samples are inserted or removed in the resampling.  In the case of upsampling, this is always assured.  In the case of downsampling it is only assured if the original signal is bandlimited to be below the new, smaller Nyquist frequency.

In such cases, non-zero amplitude samples will be removed.  In addition to resampling this effectively applies a perfect low-pass filter with a cut-off at the resampled Nyquist frequency \(\frac{1}{2T_r}\).  These removed samples represent actual loss of signal.  Regardless of the interpretation used for normalization, the Parseval Parseval energy in the resampled signal must be reduced exactly by the amount of energy in the removed samples

\begin{equation}
\label{loss}
E_{loss} = \sum_{|k| > H_r} \left| G[k] \right|^2.
\end{equation}
\end{document}
