entry / Mathematics / 2025-04-21

Understanding undersampling - 1

Using the Fourier transform and interactive graphics to intuitively understand undersampling transmitters

It’s possible to generate nearly arbitrarily high frequency signals using a relatively slow transmitter by exploiting undersampling. In this post I will try to give an intuitive explanation of the mechanism, and try to find the optimum sample frequency to emit a given signal.


I found this fascinating video, which showcases the emission of LORA signals using nothing more than a GPIO on a microcontroller. Of course, the microcontroller cannot directly synthesize the radio frequency signal (at around 900MHz), so instead high harmonics of the GPIO square wave output are used. The mechanism to actually synthesize the signal is remarkable: sample the signal you want to emit at your desired GPIO frequency, and use that sampled data to drive your pin.

As a prerequisite for this article, you will need to know to have some familiarity with the Fourier transform and convolutions. Nonetheless, I’ve tried to make the article as intuitive as possible, of course nearly fully disregarding mathematical rigor.

Sampling our signal

We will consider a really simple signal 𝑔(𝑑)=cos(2πœ‹π‘“0𝑑)=12𝑒2πœ‹π‘“0𝑑𝑖+12π‘’βˆ’2πœ‹π‘“0𝑑𝑖, which is the signal we want to emit from our device. An ideal sampling device would capture infinitely thin slices of the signal. Such slices have a vanishingly small quantity of energy, so the sampler needs greater and greater gain as we thin the slice. The mathematical symbol to represent such behavior is the Dirac delta 𝛿, which allows us to write the sampled signal as:

𝑔𝑠(𝑑)=𝑔(𝑑)βˆ‘π‘›=βˆ’βˆžβˆžπ›Ώ(π‘‘βˆ’π‘›π‘‡)

Where 𝑇 is the time between each sample being taken.

If we take the Fourier transform1 of 𝑔(𝑑) we find its spectrum 𝐺(πœ”), which also uses the Dirac delta:

𝐺(𝑓)=12𝛿(π‘“βˆ’π‘“0)+12𝛿(𝑓+𝑓0)

The spectrum of the sampled signal

To compute the spectrum of the sampled signal, we can apply the convolution theorem. It states that the Fourier transform of the product of two functions is the convolution of their respective Fourier transforms (the converse is also true). We can obtain the Fourier transform of the β€œsampling function” (Dirac comb) and find it to be:

1π‘‡βˆ‘π‘›=βˆ’βˆžβˆžπ›Ώ(π‘“βˆ’π‘›π‘‡)

Now, we need to convolve the previous expression with 𝐺(πœ”). The convolution of a Dirac delta with another obeys the following law:

𝛿(π‘‘βˆ’π‘Ž)βˆ—π›Ώ(π‘‘βˆ’π‘)=𝛿((π‘Ž+𝑏)βˆ’π‘‘)

Thus we may write the spectrum of the sampled signal by applying the previous β€œlaw” linearly:

𝐺𝑠(𝑓)=12βˆ‘π‘›=βˆ’βˆžβˆžπ›Ώ((𝑛𝑇±𝑓0)βˆ’π‘“)

The following graph allows you to play around with the values and get a feel for the results. Note that the vertical scale of the graph represents the intensity of each term of the Fourier series in a logarithmic scale2, and the horizontal scale is the frequency in Hz. The shaded area represents the Nyquist area, where the signal frequency is less than half the sampling frequency.

Consider 𝑓0 = Hz and 1𝑇=𝑓𝑠 = Hz. We obtain the spectrum:

(Enable zero-order hold in graph).

(Stick graph to screen).

Sure enough, our original frequency is one of the components of the sampled signal. Note that if you reduce the signal frequency to within the Nyquist zone (grey area), the signal is perfectly reproduced within that area, without any spurious signal appearing.

The zero-order hold

Our ideal sampling process can be easily achieved within a computer by sampling a mathematical representation of a signal. But, outputting such a signal from a microcontroller would prove impossible, as it would require generating infinitely fast pulses. A more realistic approximation is to state that we may generate a square-wave. For simplicity, we will assume that its edges are instantaneous. Mathematically, this is referred to as a zero-order hold. Feel free to play around with the button in the graph to get a feel for how it works.

We can represent such a device as a convolution in the time domain between our sampled signal and the β€œboxcar” function with the sample period as width:

Rectangle function

Applying the convolution theorem, we can obtain the spectrum of the resulting signal as the product of the spectrum of the original samples, and of the spectrum of the β€œboxcar” function, which is known as the β€œsinc” function:

1πœ‹π‘“sin(πœ‹π‘“π‘“π‘ )

Due to the denominator, the bigger 𝑓 is, the more attenuation we have. Furthermore, if 𝑓 is badly placed it may be completely attenuated. Note that, even with a properly sampled signal (i.e. sampling frequency more than twice the signal frequency), some attenuation will take place for signals relatively close to the Nyquist frequency (half the sampling frequency). This is commonly known as β€œsinc roll-off”.

You can use the following button to enable this attenuation in the interactive graph:

(Enable zero-order hold in graph). Go to graph

Each of the areas between two zeros is referred to as a β€œNyquist zone”. The zeroes can be found by solving πœ‹π‘“π‘“π‘ =π‘˜πœ‹, which gives 𝑓=π‘˜π‘“π‘ , for π‘˜β‰₯1.

A quick side-note: Extrema of the sinc function

If we compute the derivative of said function we can find the frequencies at which it’s of maximum amplitude, which requires solving (for non-zero 𝑓):

tan(πœ‹π‘“π‘“π‘ )=πœ‹π‘“π‘“π‘ 

Remarkably, this equation has no closed form solution. Nonetheless, we can infer some properties about its solutions, and cook up a quick numerical method to find them3. First of all, note that it’s intuitive to see that infinite solutions exist, as surely the line in the right hand side intersects the tangent (whose image spans all reals over and over) infinitely many times.

Afterwards, note that taking the arc-tangent:

πœ‹π‘“π‘“π‘ =arctan(πœ‹π‘“π‘“π‘ )+2π‘˜πœ‹βŸΉπ‘“=π‘“π‘ πœ‹(arctan(πœ‹π‘“π‘“π‘ )+2π‘˜πœ‹)

Except for small π‘˜, the term in the parenthesis is dominated by 2π‘˜πœ‹. Furthermore, only one solution is located in each Nyquist zone, because the arc-tangent approaches πœ‹2 as its argument grows, and is positive. In fact, for big enough 𝑓 (and thus π‘˜ ), the solution is located extremely close to 4π‘˜+12𝑓𝑠, at the center of each Nyquist zone.

Thus, we propose a numerical method where start our iterative solution with 𝑓[0]=2π‘˜π‘“π‘ , i.e. one of the zeroes of the sinc function, and iterate by the following recurrence relation:

𝑓[𝑛]=π‘“π‘ πœ‹(arctan(πœ‹π‘“[π‘›βˆ’1]𝑓𝑠)+2π‘˜πœ‹)

Intuitively, this converges because 𝑓[π‘›βˆ’1] always underestimates the actual solution (as the arctangent is monotonic), and 𝑓[𝑛] is also monotonically increasing with 𝑛. A more detailed proof could be given, as this argument doesn’t really show that the converged value is the actual solution, but goes outside the intent of the blog post. 5 iterations of this method are good enough for pretty much all applications.

Assuming that the maxima are located at the center of the Nyquist zones supposes a maximum error of around 0.5%, and thus for our application we may as well just assume that they are coincident.

Optimum sampling frequency

We will consider the problem of finding the optimum sampling frequency to best represent 𝑔(𝑑) with our sample-zero-order-hold system, given an upper limit on 𝑓𝑠. This limit is usually imposed by the clock of the microcontroller’s GPIO (General Purpose Input Output). By β€œbest represent”, we mean:

  • Generating an output signal that contains as much power as possible in its spectrum at frequency 𝑓0
  • Having the least possible cluttering signals around 𝑓0 so we can use a wide band-pass filter to isolate our desired signal

Of course, if our 𝑓𝑠 is large enough that it satisfies the Nyquist criterion, we can just output the signal β€œas-is”, and apply a low-pass filter to eliminate higher order harmonics. We are instead interested in the case where 𝑓𝑠 is relatively small.

For emitting symmetric signals

If you play around with the graph, you will find that for signals β€œdancing” around a multiple of half 𝑓𝑠, we get a symmetric signal of near-maximum gain, and furthest away from the other undesired harmonics. The maximum gain can be explaind intuitively: at a signal of half the sample-frequency, the output signal switches the most, and thus reasonably it contains the most energy at high frequencies4.

Such signals are common in communications. For example, they could be used for carrier-supressed AM transmissions, as this type of signal is symmetric. Emitting a AM signal with carrier would be as simple as adding another signal at a multiple of half our sampling frequency.

Thus, if we want to emit a signal that’s symmetric around a given 𝑓𝑐, we need to set the sampling frequency to 22π‘šβˆ’1𝑓0 where π‘š is as big as needed.

Consider 𝑓𝑐 = Hz and π‘š = , the sample rate must be set to 𝑓𝑠 = Hz. Go to graph

For emitting non-symmetric signals

Non-symmetric signals are a bit more tricky to generate using this method. A good example of such signals are chirp-spread-spectrum methods, such as LORA, Frequency-Shift-Keying (FSK), and many other protocols used for digital data transfer.

By playing around with the graph for a bit, you may also find that signals at odd multiples of a quarter the sampling frequency are optimally far away from the other harmonics. For example, if you set 𝑓0=125 Hz and 𝑓𝑠=100 Hz, and move around 𝑓0, you will find this frequency maximizes the separation between signals, which are evenly spaced a distance of 𝑓𝑠2 Hz apart.

Thus, if we want to emit a signal that’s asymmetric but centered around a given 𝑓𝑐, we need to set the sampling frqeuency to 42π‘šβˆ’1𝑓0 where π‘š is as big as needed.

If you only care about having the highest bandwidth without interference from other harmonics, this is the ideal sampling frequency. You could theoretically increase gain by a bit by exploiting the off-center nature of sinc maxima, but this effect is fairly small and for practical applications may as well be ignored.

Consider 𝑓𝑐 = Hz and π‘š = , the sample rate must be set to 𝑓𝑠 = Hz. Go to graph

Further non-idealities

During the whole text, we have considered that we can output any power level, but in reality we will be limited to outputting either zero power or maximum power. In the next post I will try to derive the effect of such a β€œdistortion” on our signal. Indeed, this quantization will imply the appearance of a lot of distortion in the output signal, but our fundamental frequency will remain. Finally, I will present a real-life experiment where we put to test all of these mathematics in a device, and try to emit some meaningful radio waves.

  1. 1I’m using the unitary Fourier transform, which leads to neater expressions.
  2. 2Actually, the signals are divided by the would-be intensity of the β€œDC” signal of 𝑓=0 before taking logarithms, such that the graph scale remains consistent.
  3. 3Adapted from leonbloy’s post on Mathematics Stack Exchange.
  4. 4Switching the signal is where the β€œhigh-frequency” of our output comes to life, as such a fast transition can β€œexcite” arbitrarily high frequency resonant systems. This is precisely why a sampled 0 frequency signal (a constant), after applying the zero-order hold, has absolutely no high frequency content: it has no transitions.