Resampling¶
Context¶
Let the discrete time signal \(x_1[n]\) be the samples of a continuous time signal \(x(t)\) sampled at some interval \(T_1\):
We want to convert \(x_1[n]\) to \(x_2[n]\), where \(x_2[n]\) is the samples of \(x(t)\), but sampled at a different interval \(T_2\).
Here we assume \(\frac{T_1}{T_2}\) is rational, in other words, there exists some integer \(L\) and \(M\) that
For example, we may want to convert a WAV data of 44100Hz sampling rate to 48000Hz sampling rate.
Problem¶
How do we convert \(x_1[n]\) to \(x_2[n]\)?
Solution¶
This resampling problem can be solved by two steps
- Upsample \(x_1[n]\) by the integer factor \(L\)
- Downsample the outcome of the previous step by the integer factor \(M\)
Upsampling¶
Upsampling is typically done by two steps
- Create a zero-inserted sequence from the original signal
- Smooth out the discontinuities with a lowpass filter. This filter is sometimes referred to as the interpolation filter
Let the zero-inserted sequence be \(x_{1,L}[n]\), where
$$
x_{1,L}[n] = \left{ \begin{array}{cc} x_1[m] & m = \frac{n}{L} \ 0 & otherwise \end{array} \right. $$
Let \(X(f)\) be the Fourier transform of \(x(t)\). The discrete-time Fourier transform of \(x_{1,L}[n]\) and \(x_1[n]\) are basically identical, for both of them are essentially
However, the true "upsampled by factor \(L\)" signal should be of DTFT
If \(x(t)\) is band-limited, of bandwidth \(W < \frac{0.5}{T_1}\), then we can design an ideal low-pass filter (LPF) of cut-off frequency \(\frac{0.5}{T_1}\), and filter \(x_{1,L}[n]\) with this LPF. The DTFT of the filtered \(x_{1,L}[n]\) will be \(\frac{L}{T_1} \sum_k{ X(f - \frac{kL}{T_1} })\) as desired.
Downsampling¶
Downsampling is typically done by two steps
- Apply an anti-aliasing low-pass filter to the original signal
- Decimate the filtered signal by a integer factor M.
Combining Upsampling and Downsampling¶
The overall data flow can be described as follows
x1[n] ---> zero-insertion ---> interpolation filter h[n] ---> anti-aliasing filter f[n] ---> decimation ---> x2[n]
x1,L[n] \ / y[n]
-----------------------v----------------------
g[n]
The interpolation filter \(h[n]\) and the anti-aliasing filter \(f[n]\) can be combined into one filter \(g[n]\) to reduce the computation.
First, zero-pad \(g[n]\) so that its length becomes a multiple of \(L\). Here we assume the length of the zero-padded \(g[n]\) is \(qL\), where \(q\) is an positive integer.
Let \(y[n]\) be the output of \(g[n]\), then
Because \(x_{1,L}[n-k]=0\) when \((n-k)\) is not multiple of \(L\), we can rewrite \(y[n]\) as
Following table illustrates the computation of \(y[n]\):
g[0] | g[1] | g[2] | ... | g[L] | g[L+1] | g[L+2] | ... | g[2L] | g[2L+1] | g[2L+2] | ... | g[qL-1] | |
x1[q] | 0 | 0 | ... | x1[q-1] | 0 | 0 | ... | x1[q-2] | 0 | 0 | ... | 0 | y[qL] = x1[q]g[0] + x1[q-1]g[L] + ... |
0 | x1[q] | 0 | ... | 0 | x1[q-1] | 0 | ... | 0 | x1[q-2] | 0 | ... | 0 | y[qL+1] = x1[q]g[1] + x1[q-1]g[L+1] + ... |
0 | 0 | x1[q] | ... | 0 | 0 | x1[q-1] | ... | 0 | 0 | x1[q-2] | ... | 0 | y[qL+2] = x1[q]g[2] + x1[q-1]g[L+2] + ... |
Note that the computation of \(y[n]\) above can be viewed as \(x_1[n]\) filtered by a filter bank \(\{g_0[n], g_1[n], g_2[n], ... , g_{L-1}[n] \}\) where
This filter bank is called the polyphase filter.
With the "polyphase filter" approach, computing one sample of \(y[n]\) requires only \(q\) multiplications and \(q-1\) additions (instead of \(qL\) multiplications and \(qL-1\) additions as the typical convolution requires). Also, only 1 out of \(M\) samples of \(y[n]\) needs to be computed because the rest will be decimated anyway.