On matched filtering in the presence of carrier frequency offset

If \(\{x_k\}_{k=0}^{N-1}\) is a complex waveform and this waveform is received in AWGN, that is, the sequence \(y_k = A x_k + n_k\) is received, where \(A\) is an unknown complex amplitude and \(n_k\) are independent circularly symmetric normal random variables with standard deviation one, it is well known that the linear filter \(\{a_k\}_{k=0}^{N-1}\) that maximizes the detection SNR of \(T = \sum_{k=0}^{N-1} a_k y_k\), which is defined as \(|\mathbb{E}[T]|^2/V(T)\), is given by the matched filter \(a_k = \overline{x_k}\).

A natural question is what happens if the waveform is received with an unknown carrier frequency offset \(f\). That is, if \(y_k = A e^{2\pi i f k} x_k + n_k\). The typical solution is to use a bank of matched filters which are spaced by \(\Delta\) in the frequency domain and cover the expected carrier frequency offset range. This means that we use filters \(a_{k,m} = e^{-2\pi i \Delta m k} \overline{x_k}\), where the integers \(m\) are such that the grid of frequencies \(\Delta m\) covers the required frequency range. Here the hope is that if \(\Delta\) is small enough, then choosing the integer \(m\) such that \(\Delta m\) is closest to \(f\), we have that\[T = \sum_{k=0}^{N-1} e^{-2\pi i \Delta m k} \overline{x_k}y_k = A \sum_{k=0}^{N-1} e^{2 \pi i (f-\Delta m) k} |x_k|^2 + \sum_{k=0}^{N-1} e^{-2 \pi i \Delta m k} \overline{x_k} n_k.\]If \(\Delta m-f\) is small, this expression will have an SNR similar to the SNR for \(f = 0\).

However it is possible to do better. We can modify the matched filter to improve the SNR when there is frequency error. Since we choose the filter \(m\) from the bank such that \(\Delta m\) is closest to \(f\), we can assume that \(|f| \leq \Delta / 2\) and that we choose bank \(m = 0\). Now we can pose an optimization problem that involves the frequency error \(f\). Different kinds of optimization problems will lead to different solutions. A natural quantity to maximize is the average SNR with respect to \(f\), assuming that \(f\) is uniformly distributed in \([-\frac{\Delta}{2},\frac{\Delta}{2}]\). This is\[\frac{1}{\Delta}\int_{-\frac{\Delta}{2}}^{\frac{\Delta}{2}} \frac{|\mathbb{E}[T]|^2}{V(T)}\, df.\]Let us solve the optimization problem.

Similarly to the case of the matched filter with no frequency error, we have\[\mathbb{E}[T] = A \sum_{k=0}^{N-1} e^{2 \pi i f k} a_k x_k,\]so\[V(T) = \mathbb{E}[|T-\mathbb{E}[T]|^2] = \mathbb{E}\left[\left|\sum_{k=0}^{N-1} a_k n_k\right|^2\right] = \sum_{k = 0}^{N-1} |a_k|^2.\]Therefore, the optimization problem is equivalent to finding a vector \(\{a_k\}_{k=0}^{N-1}\) with unit norm (\(\sum_{k=0}^{N-1} |a_k|^2 = 1\)) that maximizes the expression\[\frac{1}{\Delta}\int_{-\frac{\Delta}{2}}^{\frac{\Delta}{2}}\left|\sum_{k=0}^{N-1} e^{2\pi i f k} a_k x_k\right|^2\, df.\]This expression can be rewritten as\[\frac{1}{\Delta}\sum_{k=0}^{N-1}\sum_{l=0}^{N-1}\overline{a_l x_l}a_k x_k \int_{-\frac{\Delta}{2}}^{\frac{\Delta}{2}} e^{2\pi i f (k-l)}\, df = \sum_{k=0}^{N-1}\sum_{l=0}^{N-1}\overline{a_l x_l}a_k x_k \operatorname{sinc} (\Delta (k-l)),\]where \(\operatorname{sinc}(x) = \sin(\pi x)/(\pi x)\).

Write \(x_k = e^{i\theta_k}|x_k|\) and denote by \(G\) the matrix with entries \(G_{kl} = |x_k||x_l|\operatorname{sinc} (\Delta (k-l))\). This matrix is the Gram matrix of the vectors \(\varphi_k(f) = e^{2 \pi i f k}|x_k|\) in \(L^2[-\frac{\Delta}{2}, \frac{\Delta}{2}]\) (with the Lebesgue measure multiplied by the normalization factor \(\frac{1}{\Delta}\)), so it is positive semidefinite (and it is positive definite if \(\Delta > 0\) and \(x_k \neq 0\) for all \(k = 0, \ldots, N-1\)). Let \(u = \{u_k\}_{k=0}^{N-1}\) be any unit norm eigenvector corresponding to the largest eigenvalue of \(G\). The solution to the optimization problem is then given by \(a_k = e^{-i\theta_k} u_k\).

The case in which \(|x_k| = 1\) for all \(k = 0, \ldots, N-1\) is particularly important, because it corresponds to constant-envelope modulations, and it is also easier to treat than the general case. This case includes the case of detecting a CW carrier, which corresponds to \(x_k = 1\) for all \(k\). In this case, the Gram matrix \(G\) is simply a matrix of sinc functions \(G_{kl} = \operatorname{sinc} (\Delta (k-l))\). This matrix has been studied by Slepian in 1978, because it appears in the spectral concentration problem, which is equivalent to the optimization problem I’m presenting here. In the spectral concentration problem we consider a unit norm sequence \(\{a_k\}_{k=0}^{N-1}\) and its Fourier transform\[U(f) = \sum_{k=0}^{N-1} e^{-2\pi i f k}a_k.\]The energy that \(\{a_k\}\) has in the frequency band \([-\frac{\Delta}{2}, \frac{\Delta}{2}]\) is\[\int_{-\frac{\Delta}{2}}^{\frac{\Delta}{2}} |U(f)|^2\,df.\]The problem asks which unit norm sequences \(\{a_k\}\) maximize the energy in this frequency band. It is clear that this is equivalent to a particular case of the optimization problem that we are considering (the case \(x_k = 1\) for all \(k\)).

The eigenvectors of the matrix \(G\) given by \(G_{kl} = \operatorname{sinc} (\Delta (k-l))\) can be computed numerically, but the problem is ill-conditioned for large \(N\), because many eigenvalues cluster around the largest eigenvalue. There is a trick to compute the eigenvectors without running into issues. In our case, we can use that trick to compute the eigenvector corresponding to the largest eigenvalue. The trick starts by noticing that the tridiagonal symmetric matrix \(R\) defined by\[\begin{split}R_{k,k} &= \cos(\pi\Delta) \left(k-\frac{N-1}{2}\right)^2,\ k = 0,\ldots, N-1\\R_{k,k+1} = R_{k+1,k} &= \frac{1}{2}(k+1)(N-1-k),\qquad k = 0,\ldots,N-2\end{split}\]commutes with \(G\) (this is shown by some straightforward calculations). This implies that the eigenspaces of \(G\) and \(R\) are the same. All the eigenvalues of a tridiagonal matrix with non-zero entries in its upper diagonal are simple. This is because the first component of an eigenvector for a given eigenvalue determines the remaining components (this is a very simple calculation). Moreover, it is also possible to prove that if \(v_0, v_1, \ldots, v_{N-1}\) are the eigenvectors of \(R\) with corresponding eigenvalues \(\lambda_0 > \lambda_1 > \cdots > \lambda_{N-1}\), then \(v_0, v_1, \ldots, v_{N-1}\) (which must be eigenvectors of \(G\)) have eigenvalues \(\mu_0 > \mu_1 > \cdots > \mu_{N-1}\) as eigenvectors of \(G\). However I haven’t been able to find a reference that proves this in a straightforward way, though presumably this follows from all the calculations in Slepian’s paper. This means that the eigenvector \(u\) that we need can be computed as \(v_0\), the eigenvector corresponding to the largest eigenvalue \(\lambda_0\) of \(R\).

There are efficient algorithms to compute eigenvalues and eigenvectors for tridiagonal symmetric matrices. For instance, SciPy has an eigh_tridiagonal function. Additionally it is possible to use these algorithms to compute only a selection of some of the eigenvalues and eigenvectors. This is precisely what we need, because in our case we only want the eigenvector \(v_0\) corresponding to the largest eigenvalue \(\lambda_0\) of \(R\).

The eigenvectors \(v_0, v_1, \ldots, v_{N-1}\) are called discrete prolate spheroidal sequences (DPSS) and they also play a role in other similar spectral concentration problems and in multitaper spectral analysis. They can be calculated with the dpss window function in SciPy. The first DPSS, also known as Slepian window, and \(v_0\) in our eigenvector notation, is the vector that solves our optimization problem in the constant-envelope case. That is, when \(|x_k| = 1\) for all \(k = 0, \ldots, N-1\). The takeaway of this post is:

For a constant-envelope waveform, average SNR performance in the presence of carrier frequency offset improves if the matched filter is multiplied by a DPSS window.

In the general case in which the waveform is not constant-envelope, the trick of using a tridiagonal matrix does not work, and we can also have ill-conditioning when trying to compute the eigenvectors numerically (for instance by using the eigh SciPy function).

It is convenient to put the above theoretical results in perspective and show what they really imply for the usual practical applications. In most applications \(\Delta \lesssim 1/N\). For instance, when an FFT is used to detect a CW carrier, we have \(\Delta = 1/N\), because in this case \(\Delta\) is equal to the FFT bin spacing. Other matched filter applications that use an FFT similarly set \(\Delta\) in relation to the FFT bin spacing.

The following plot shows, for a constant-envelope waveform of \(N\) samples, what is the average SNR loss when there is a carrier frequency offset \(f\) uniformly distributed on \([-\frac{\Delta}{2},\frac{\Delta}{2}]\), for both the matched filter (solid lines) and for a matched filter weighted with the DPSS window (dashed lines). The values of \(\Delta = 1/(4N)\), \(1/(2N)\), \(1/N\), \(2/N\), \(4/N\) are shown. We see that there is almost no dependence on \(N\), which is to be expected because this problem can be approximated well by an analogous continuous-time problem. We also see that for the smallest values of \(\Delta\) the loss of the matched filter is already quite small and the DPSS weighting gives almost no improvement.

Since the behaviour changes very little with \(N\), it is better to study what happens for a fixed \(N\) (here \(N = 8192\)), in terms of \(\Delta N\). This is what the plot below shows.

Another good takeaway from this plot is:

The average SNR loss of matched filtering with a frequency bin separation equal to the reciprocal of the filter length (for instance when using an FFT to detect a CW carrier) is around 1 dB, regardless of whether DPSS weighting is used.

The following figure shows the difference between the two traces in the figure above. This indicates how much improvement is obtained by applying DPSS weighting to the matched filter. For \(\Delta = 1/N\) the improvement is 0.05 dB, which explains why this is rarely done in practice. However for \(\Delta = 2/N\) the improvement is 0.36 dB, so DPSS weighting can be a useful technique if we need to implement a system that is in this situation for whatever reason. Note that interestingly the improvement decreases for \(\Delta > 2/N\).

Finally, the following plot shows the DPSS windows. As expected, when \(\Delta\) decreases they tend to a rectangular window, and as \(\Delta\) increases the window tapers off more.

These plots have been made in this Jupyter notebook.

Here I have treated the optimization of the average SNR assuming a uniform distribution of \(f \in [-\frac{\Delta}{2},\frac{\Delta}{2}]\). An equally interesting and useful optimization criterion is to maximize the worst-case SNR. That is, find the sequence \(\{a_k\}\) with unit norm that maximizes\[\min_{|f| \leq \frac{\Delta}{2}}\frac{|\mathbb{E}[T]|^2}{V(T)} = \min_{|f| \leq \frac{\Delta}{2}} \left|\sum_{k=0}^{N-1} e^{2\pi i f k} a_k x_k\right|^2.\]The techniques that are applicable in this problem are related to the Remez exchange used for optimal FIR design, but since the solution is quite involved, this might be a topic for another time.

X-engine correlator on a Ryzen NPU

Back in May I wrote a post explaining the architecture of AMD NPUs and demonstrating a simple kernel that reaches close to the peak TOPS allowed by the hardware resources. That program was very simple and there was no data movement between the NPU compute tiles and the rest of the system. After writing that post, I wanted to write a more complex program to understand better the NPU architecture and the software stack, and what the challenges are when working on real-world projects.

I decided to implement an X-engine correlator, such as the ones commonly used in radio astronomy. This is a problem that I’m personally interested in, and it is basically a big matrix multiplication, with some small caveats that I will explain below. As the main goal of NPUs is to be used for matrix multiplication in machine learning inference, I thought “how hard can this be?”. After a few months of working on and off on this project, I now have something ready to show.

The design has actually been quite challenging. There are many nuances I will get into below, and many dead-end paths I have taken until I discovered that when using some particular approaches performance would be killed for one reason or another, so I had to backtrack multiple times. I should also mention that while it is usually very clear what is happening at low level (which was one of the main messages of my previous post), the lack of flexibility of the hardware is often quite limiting, in particular regarding the programmability of the DMA engines, so it is quite challenging to design approaches that actually work well in the hardware.

This post is a full presentation of my X-engine implementation.

ORI’s lunar descent CTF

Open Research Institute has recently published the solutions for a Lunar Descent CTF that they ran at BSides San Diego 2026. The CTF revolves around the Ka-band radio altimeter used by the Chandrayaan-3 lunar lander. The CTF includes a simulation of the radio altimeter and the goal is to discover why the lander is crashing in this simulation and fix the problem. The CTF is in the Github repository OpenResearchInstitute/lunar-descent-ctf, which includes both the CTF and the solutions (in a spoilers directory). This seemed like an interesting topic, and in the past I have enjoyed a lot other CTFs that were organized by Michelle Thompson, so I decided to clone the repo, delete the spoilers directory, and start playing. In this post I comment on the CTF and my solution, so read no further if you don’t want to see spoilers.

PLL coefficients for rate-only feedback

A couple years ago I wrote a post about the paper Controlled-Root Formulation for Digital Phase-Locked Loops, by Stephens and Thomas. In this paper, the authors study digital PLLs by studying the transfer function in discrete time, rather than doing any continuous-time approximations or equivalences. They give values for the loop coefficients that are needed to achieve a certain noise bandwidth for some standard loop root placements (the supercritical damped response and the standard underdamped response). In general, the loop coefficients are obtained numerically. In my post, I show that in the case of a loop of order 2 with supercritical response the loop coefficients can be calculated explicitly in terms of the loop bandwidth by using the solution of a cubic equation. However, in that post, I treated only the phase/phase-rate feedback case. In this post I cover the rate-only feedback case.

Decoding the NB-IoT downlink

Recently I have been posting about V16 beacons, which are car emergency warning beacons that have been introduced this year in Spain, and which use the LTE NB-IoT cellular network to transmit their geolocation data to the traffic authority network when they are switched on. As part of experimenting with these beacons, I made recording of the downlink and uplink NB-IoT signals while the beacon was sending data to the network. My hope was to be able to decode these signals and extract the two-way traffic that shows how the beacon attaches to the LTE network and sends its data. I already decoded all the uplink transmission in a previous post. In this post I will decode the corresponding recording of the downlink channel.

However, as I already suspected when I was decoding the uplink recording, due to how I physically set up the experiment to avoid saturating the SDR receiver with the beacon transmissions, it turns out that the beacon was talking to an NB-IoT cell that is relatively weak in the downlink recording. More specifically, the antenna for the SDR receiver was set up near a window in the north side of the house, while the beacon was placed on the window sill on the south side of the house. The SDR receiver sees strong downlink signals from cell 145, which is located northeast of the house and is the cell to which the beacon connected in a previous experiment I did with the beacon placed in the north window. However, in this experiment with the beacon on the south window, the beacon connected to cell 261, which is southwest of the house. The signal from this cell is weaker in the downlink recording and is frequently overwhelmed by the signals from cell 145 and other strong cells. So I have had partial success decoding the transmissions that the network sent to the beacon.

This post is mainly about the NB-IoT downlink in general. At the end I focus on the downlink transmissions to the V16 beacon that I have been able to decode. It is a rather long post, because I cover all the main physical channels and signals of the NB-IoT downlink. I show how the NPSS and NSSS primary and secondary synchronization signals and the NRS reference signals work, how to decode the MIB-NB in the NPBCH, how to decode the SIB1-NB and SI messages carrying other SIB-NBs, how to decode NPDCCH transmissions in the Type1 common search space, which corresponds to paging, as well as decoding the corresponding NPDSCH transmissions carrying paging messages, how to do blind decoding of NPDCCH transmissions in the Type2 common search space and UE-specific search space, which correspond to uplink grants and downlink scheduling, and decode the corresponding NPDSCH transmissions that send data to the V16 beacon.

The recording used in this post is published in the dataset Recording of the NB-IoT downlink of a V16 beacon in Zenodo.

V16 beacon full uplink conversation

In my previous post I decoded a transmission from a V16 beacon. The V16 beacon has mandatorily replaced warning triangles in Spain in 2026. It is a device that contains a strobe light and an NB-IoT modem that sends its GNSS geolocation using the cellular network. It is said that the beacon first transmits is geolocation 100 seconds after it has been powered on, and then it transmits it again every 100 seconds. In that post I recorded one of those transmissions done after the beacon had been powered on for a few minutes and I decoded it by hand. I showed that the transmission contains a control plane service request NAS message that embeds a 158 byte encrypted message, which is what presumably contains the geolocation and other beacon data.

In that post I couldn’t show how the beacon connects to the cellular network and sets up the EPS security context used to encrypt the message, since that would have happened some minutes before I made the recording. I have now made a recording that contains both the NB-IoT uplink and the corresponding NB-IoT downlink and starts before the V16 beacon is switched on. In this post I show the contents of the uplink recording.

Decoding a V16 beacon

The V16 beacon is a car warning beacon that will mandatorily replace the warning triangles in Spain starting in 2026. In the event of an emergency, this beacon can be magnetically attached to the roof of the car and switched on. It has a bright LED strobe light and a connection to the cellular network, which it uses to send its GNSS position to the DGT 3.0 cloud network (for readers outside of Spain, the Spanish DGT is roughly the equivalent of the US DMV). The main point of these beacons is that placing warning triangles far enough from a vehicle can be dangerous, while this beacon can be placed without leaving the car.

There has been some criticism surrounding the V16 beacons and their mandatory usage that will start in January 2026, both for economical and implantation roadmap reasons, and also for purely technical reasons. The strobe light is so bright that you shouldn’t look at it directly while standing next to the beacon (which makes it tricky to pick it up and switch it off), but I have heard that it is not so easy to see in daylight from several hundreds of meters away.

The GNSS geolocation and cellular network service is also somewhat questionable. I purchased a V16 beacon from the brand NK connected (certificate number LCOE 2024070678G1), for no reason other than the fact that it was sold in a common supermarket chain. The instructions in the box directed me to the website validatuv16.com for testing it. In this website you can register the serial number or IMEI of your beacon and your email. Then you switch on the beacon. After 100 seconds the beacon should send a message to the DGT network, and then periodically every 100 seconds. This test service is somehow subscribed to the DGT network, and it sends you an email that contains the message data (GNSS position and battery status) when the DGT network receives it. This is great, but there is no test mode or anything that declares that you are using the beacon just for testing purposes. They only say that you should not leave the beacon on for much longer than what it takes you to receive the email, to avoid the test being mistaken for a real emergency. The fact that the test procedure for this system is literally the same as the emergency procedure is a red flag for me. Additionally, this beacon only includes cellular data service for 12 years, and it is not clear what happens after that.

Technical shortcomings aside, my main interest is how the RF connection to the DGT network works. The beacon I bought has a logo in the box saying that it uses the Orange cellular network. When I tested it, after receiving the confirmation email from the test service, I used a Pluto SDR running Maia SDR and quickly found that the beacon was transmitting NB-IoT on 832.3 MHz. I made a recording of one of the periodic transmissions. In this post I analyse and decode the recording.

First analysis of the Lunar GNSS Receiver Experiment data

The Lunar GNSS Receiver Experiment (LuGRE) is a NASA and Italian Space Agency payload that flew in the Firefly Blue Ghost Mission 1 lunar lander. An overview of this experiment can be found in this presentation. The payload contains a Qascom GPS/Galileo L1 + L5 receiver capable of both real time positioning and raw IQ recording, and a 16 dBi high-gain antenna that was pointed towards Earth. For decades the GNSS community has been talking about using GNSS in the lunar environment, and LuGRE has been the first payload to actually demonstrate this concept.

The LuGRE payload ran a total of 25 times over the Blue Ghost mission duration, starting with a commissioning run on 2025-01-15 a few hours after launch and ending with a series of 9 runs on the lunar surface between 2025-01-03 (the day after the lunar landing) and 2025-01-16 (end of mission after lunar sunset). Back in October 15, the experiment data was published in Zenodo in the dataset Lunar GNSS Receiver Experiment (LuGRE) Mission Data. This dataset includes some short raw IQ recordings, as well as output from the real time GNSS receiver (raw observables, PVT, ephemeris and acquisition data). Since I have some professional background implementing high-sensitivity GNSS acquisition algorithms and I find this experiment quite interesting, I decided to do some data analysis, mainly of the raw IQ data.

The initial results of the experiment were presented on September 11 in the ION GNSS+ 2025 conference in a talk titled Initial Results of the Lunar GNSS Receiver Experiment (LuGRE). This talk is only available to registered ION attendees. As I don’t want to resort to my network to scrounge some ION paper credits (which is how proceedings are usually downloaded from the ION website), I haven’t seen anything about this talk besides the abstract. It is quite possible that something of what I will mention here was already presented in this talk. This is what we get as a society for not doing science in a completely public and open way. However, it’s interesting that this also makes my analysis less likely to be biased. I’ve just downloaded some raw IQ data and started looking at it with only basic context about the instrument that produced it and how it was run.

For a first analysis, I have implemented a high-sensitivity acquisition algorithm for the GPS L1 C/A signal in CUDA. I have run this on all the 20 L1 IQ recordings that are available. In this post I present the algorithm and the results.

Non-coherent m-FSK BER

Yesterday I posted about how to compute the well known formula for the bit error rate of FSK with non-coherent demodulation. Later I realized that the same kind of argument can be extended to cover the case of \(m\)-FSK in which the \(m\) tones are orthogonal. The formula for this is not so well known, and I don’t recall having seen it before, although surely it is somewhere in the literature. Here I show the calculations and the closed-form expression that is obtained.

Published
Categorised as Maths Tagged ,