Digital display for half wave detector with cubic spline interpolation – part 1

Digital display for QRP labs 20W dummy load – part 1 and the following articles discussed an approach to compensating the non-linear response of the half wave detector by finding a polynomial curve fit over a desired range. Unfortunately, the range for a good fit can be smaller than one desires.

This article discussed an alternative using cubic spline interpolation and might be applicable to extend the range or for responses that aren’t well approximated by a simple curve fit.


Essentially, this technique applies a piecewise polynomial to fit the data points, and a relatively small number of data points may provide a very good approximation.

The graph above shows:

  • Basis: a carefully selected set of points from which to calculate the cubic spline coefficients;
  • Interpolated: the result of interpolation calculation of a range of points; and
  • LTSPICE: a set of model results from which the Basis points were selected.

It can be seen that the Interpolated curve is a very good fit to the underlying LTSPICE dataset, and we might expect that the interpolation will be a good estimator of points in this 54dB range.


The interpolation table is calculated separately in Excel (using a custom VBA function library), but could be done in any suitable tool.

Above is a screen shot  extract of the spreadsheet, the column on the right is C array initialisation code for pasting into the project source code.

float inttable[][3]={
int soi=sizeof(inttable)/sizeof(inttable[0]);

Whilst I have a preference for putting this stuff in EEPROM, in this case it  is inline in the source code… mainly because the target processor (Arduino Zero) does not have EEPROM and emulation using NVM does not have the convenience or endurance of the EEPROM found on most Arduino AVR chips.

Selection of the points is important to success, and experience informs the selection. In this case, I plotted the results of the simulation, and by hand digitised it using Engauge.

The above plot shows the digitised points and a smooth curve connecting them to give guidance on point selection. In this case there are eight points which are exported and pasted into the cubic spline interpolation worksheet above.

Prototype – initial

The code was developed on an initial prototype based on an Ardunio Nano (ATmega328P, 5V, 16MHz, 10bit ADC).

Above the initial prototype for code development, though the 10bit ADC is limiting.

In this implementation with Vref=1.1V and 10 bits each ADC step is 1.07mV so we cannot measure below about 10mV with moderate accuracy, which translates to about 6mW RF.

The intended target is an Arduino (mini) Zero which has a 12bit ADC so should give moderate accuracy down to about 2.5mV or 0.8mW RF.

The uncertainty here is that measurements of a couple of dev boards had very high internal ADC noise with input shorted, far worse than running the code on an Arduino Nano. This is not an uncommon problem with cheap dev boards, they rarely take the trouble (and expense) to implement low noise ADC.

The code does work, and works very well on an Arduino Nano.


Next step is to evaluation ADC noise on some more dev board candidates.

A work in progress..

Continued at Digital display for half wave detector with cubic spline interpolation – part 2.