Some practical signal processing facts
Signal processing is the art of analyzing, and interpreting signals.
Broadly speaking, any sequence can be a signal as long as it has a useful meaning (sequence of primes, stock prices, wind variation at a place). In practice, signals usually refer to a class of ordered list of snapshots of values captured by a recording device (microphone, camera, sensor, etc.).
Here I present a few tricks I discovered or found to be useful.
Optimal sampling
The Shanon-Nyquist theorem states that if a source emits a signal whose largest frequency is $f_{max}$ then the recording device should sample such signal to at least that frequency $2 f_{max}$.
If you really think about it, even without any knowledge of the theorem, you’d discover it yourself.
Fundamentally, what are the potential issues?
- You got a syncrhonization problem: peak-to-peak, valley-to-valley
- You want maximally preserve the original shape given your device constraints
- Undersampling is easy to rule out, so less than the dominant frequency is already a big no as you lose information.
- Some sampling frequencies are such that you’d fall more often into the valleys or the peaks everytime you take a snapshot (e.g. around $f_s = f_{max}/2 \pm \epsilon$). Unless you are looking for some fancy stroboscopic effects.
- An even more interesting case is that, a bad sampling frequency will bias what you are seeing in your experiment.
Why twice?
First let’s model a way to do snapshots of a function, for that matter we can just use the Dirac comb function. To convince you that this is illustrative enough to even cover the general case, in our sampling problem, only the spacing at which we take snapshots matters i.e. the period $T=1/f$ and the height on these points.
Suppose we have a signal $s(t)$ being emitted by a source, and our device is capturing at a frequency $f_s$.
$$ \eta (t) = Snaphot_{f_s} \{s (t)\} = s (t) \times \sum_{n=- \infty}^{\infty} \delta (t - n/f_s) $$
The Dirac comb function is such that it encodes sampling of a signal as it annihilates values at which it doesn’t match a multiple of the sampling period since the expression $\sum_{n=- \infty}^{\infty} \delta (t - n/f_s)$ constructs a bunch of peaks with a spacing of exactly $T_s=1/f_s$ units. And as scary as it looks, $\eta(t)$ is quite easy to manipulate.
Now, let’s take the Fourier transform:
$$ F\{\eta (t)\} = F \{ s(t) \times \sum_{n=- \infty}^{\infty} \delta (t - n/f_s) \} = F \{ s(t) \} * F \{ \sum_{n=- \infty}^{\infty} \delta (t - nf_s) \} $$
Dirac comb has the property that it transforms to another comb.
$$ \Eta (f) := F\{\eta (t)\} = S(f) * {f_s} \sum_{n=- \infty}^{\infty} \delta (f - nf_s) $$
We don’t have to compute $S(f)$ at all, we will only assume that it is bandlimited, also just know that it contains the frequency domain of $s(t)$. And if you follow closely, the whole convolution operation says that the Dirac comb makes multiple copies of $F \{ s(t) \}$ scaled by $f_s$.
Here is the keypart, if the sampling frequency $f_s$ is less that twice the dominant frequency $f_{max}$ contained within $s(t)$ then the shifted copies of the graph of $S(f)$ will overlap, resulting in aliasing.
This is easy to see as the copies of $S(f)$ must all be centered at $f = nf_s$, and to have no overlap we set $f_{max} \le f_s - f \implies 2 f_{max} \le f_s$.
While the Dirac comb might seem like a technical trick, it is really just a precise way of describing the process of sampling (at least on paper!). The important takeaway is the mechanism, not the formalism: sampling creates repeated copies of the spectrum, and if those copies are too close, they overlap and cause aliasing.