# 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.

## Introduction

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.

## Interpolation

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]={
1.581130E-04,9.957000E-05,0.000000E+00,
6.322400E-04,2.463000E-04,-5.925326E+01,
1.916700E-03,6.219500E-04,8.276237E+01,
1.056660E-02,6.237500E-03,6.615165E+01,
8.246800E-02,2.489700E-01,6.936073E+01,
2.136000E-01,1.576600E+00,5.772305E+01,
5.436400E-01,9.969000E+00,8.934798E+01,
8.621200E-01,2.523000E+01,0.000000E+00
};
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

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

A work in progress..