The nanoVNA and MATLAB

The nanoVNA is a cheap but usable vector network analyser. It is good value and very useful for all sorts of RF design and radio ham activities.   I suggest you buy a nanoVNA from a reputable dealer as there are plenty of clones which don’t work as well as the original. The model I have has a tiny screen which I can read adequately but it isn’t as comfortable as reading a computer screen. The NanoVNA is a touchscreen device so you need to tap on tiny text to do anything. Again, this is possible but far from comfortable for those of us with ageing eyes. There’s also a bit of screen reflection.

nanoVNA

The nanoVNA can be driven from a PC using a program called nanoVNA-saver which is pretty good. Unfortunately it runs on Microsoft Windows and as I don’t have a PC running Microsoft Windows I have to run it in a VirtualBox VM on my Mac Mini. This works but is a bit clunky and to be honest my Mac mini is a bit long in the tooth and struggles to run virtualised Windows 10 at a reasonable speed.

There is a cross-platform solution based on Python which looks promising. It uses Homebrew on MacOS which clashes with MacPorts which I use. I tried to make it work under MacPorts but fell into the usual maze of incompatible library versions causing the make to fail. So I gave up as I want to play with electronics and not software building. [Update: Rudi, DL5FA kindly helped with this and it looks like the Python Virtual Environment will help when I’ve got the time to try again.]

MATLAB to the rescue! — alex_m has created some MATLAB scripts which allow you to interrogate and control the nanoVNA from MATLAB. Thanks Alex! So if you have MATLAB this may be useful. If you don’t you may be able to convert much of this to Octave but it does use the MATLAB RF Toolbox so you may end up doing a lot of work.  Alex’s scripts produce LogMag, Smith Chart and TDR Step Response graphs. 

Here’s a graph showing my 40m LPF characteristics made using Alex’s scripts.

40m LPF LogMag

I’ve written a couple of scripts based on Alex’s work which I think makes using the nanoVNA easier. Both scripts need an edit to configure the serial link to the nanoVNA. You’ll need Alex’s code too.

The first script ajfCalibrate.m calibrates the nanoVNA for a particular sweep on the S11 port. You have to do this before every measurement that changes the sweep values, so you do it a lot. Here’s how it looks in the MATLAB console. The inputs are in italics.

>> ajfCalibrate
connect: Serial-/dev/tty.usbmodem4001
status: open
Sweep start (MHz)? 7
Sweep stop (MHz) ? 7.2
Calibrating...
press RETURN when S11 is open
press RETURN when S11 is shorted
press RETURN when S11 has 50 ohm load
Save [0-4]? 4
close
>>

The second script ajfVSWR.m produces a chart of VSWR against frequency. Most radio hams are happier with this than the LogMag chart preferred by RF designers. 

I used ajfVSWR to measure my small transmitting loop tuned to the 40m FT8 frequency. As expected it shows the narrow bandwidth in low VSWR that is the drawback of small transmitting loops. 

40m FT8 VSWR

The graph can be zoomed in MATLAB and have data cursors added to show more details.

40m FT8 VSWR 2

The VSWR could be lower. I think I left a metal step-ladder in the attic which is affecting the loop.

ajf? My initials.

UK Deaths per Country Comparison

I thought it might be educational to compare the different health services within the UK with regard to how many COVID-19 deaths there have been, adjusted for population. Here is the result. The figures are the numbers of deaths per million population. 

Of course, each country counts deaths in its own way, so beware of how you interpret this.

The English and Scottish figures cover deaths in hospitals only and do not count deaths in care homes or people dying at home. (As at Thursday, 16 April 2020 this means the used values are 25-30% low). I believe the same is true for NI and Wales. However, it doesn’t look like the differences between the various countries would be much affected by the uncounted deaths.

The MATLAB code is here.

Plotting Local Coronavirus Cases

Here in Scotland (and in England) the governments publish coronavirus data daily. But they do not show the data in a particularly useful way as it is simply a count of cases confirmed so far. These counts are useful as they can show whether the health service is likely to cope with the outbreak or not today, but they do not show the history of the pandemic.

Jason Leitch Flattening

I believe the important information is to see a graph of the confirmed cases to allow you to judge if the wanted flattening of the curve is happening or not. This curve is explained here by Scotland’s National Clinical Director, Jason Leitch. Also what matters to most people is what is happening locally to themselves and their loved ones.

So I’ve knocked together a MATLAB script to plot some graphs for the Lothian Health Board and the Greater Glasgow and Clyde Health Board in Scotland and the East Sussex Healthcare NHS Trust in England. The script gets its data from Tom White’s GitHub page. As Tom says, this data should be made available officially but does not appear to be published yet in a usable format. Thanks for the data, Tom!

I’m not a MATLAB guru and I’m sure my script could be written better and be more robust. But it works for me. Here is the code. MATLAB is quite expensive (I use it for playing about with radios and electronics) but the script could probably be rewritten in Octave with something replacing the TimeSeries variables. Spreadsheets would  work too but I’m even less a guru in them than MATLAB.

And the grim results, no doubt to become much grimmer due to the expected exponential growth of cases. Early days yet.

Lothian

Glasgow

Esussex

Remember to wash your hands!