{"id":105,"date":"2020-06-27T16:41:25","date_gmt":"2020-06-27T15:41:25","guid":{"rendered":"https:\/\/fletch.scot\/wp\/?p=105"},"modified":"2022-06-13T13:08:14","modified_gmt":"2022-06-13T12:08:14","slug":"the-nanovna-and-matlab","status":"publish","type":"post","link":"https:\/\/fletch.scot\/wp\/?p=105","title":{"rendered":"The nanoVNA and MATLAB"},"content":{"rendered":"<p>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. \u00a0 I suggest you buy a nanoVNA from a reputable dealer as there are plenty of clones which don\u2019t work as well as the original.\u00a0The model I have has a tiny screen which I can read adequately but it isn\u2019t 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\u2019s also a bit of screen reflection.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"IMG_1105.jpg\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2020\/09\/IMG_1105.jpg\" alt=\"nanoVNA\" width=\"600\" height=\"450\" border=\"0\" \/><\/p>\n<p>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\u2019t have a PC running Microsoft Windows I have to run it in a <a href=\"https:\/\/www.virtualbox.org\">VirtualBox<\/a> 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.<\/p>\n<p>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\u2019ve got the time to try again.]<\/p>\n<p><a href=\"https:\/\/uk.mathworks.com\">MATLAB<\/a> to the rescue! \u2014 alex_m has created some <a href=\"https:\/\/github.com\/qrp73\/NanoVNA-MATLAB\">MATLAB scripts<\/a> 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\u2019t you may be able to convert much of this to <a href=\"https:\/\/www.gnu.org\/software\/octave\/\">Octave<\/a> but it does use the MATLAB RF Toolbox so you may end up doing a lot of work. \u00a0Alex\u2019s scripts produce LogMag, Smith Chart and TDR Step Response graphs.\u00a0<\/p>\n<p>Here\u2019s a graph showing my 40m LPF characteristics made using Alex\u2019s scripts.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"40m-LPF-LogMag.png\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2020\/09\/40m-LPF-LogMag.png\" alt=\"40m LPF LogMag\" width=\"560\" height=\"420\" border=\"0\" \/><\/p>\n<p>I\u2019ve written a couple of scripts based on Alex\u2019s work which I think makes using the nanoVNA easier. Both scripts need an edit to configure the serial link to the nanoVNA. You\u2019ll need Alex\u2019s code too.<\/p>\n<p>The first script <a href=\"..\/code\/nanoVNA\/ajfCalibrate.m\">ajfCalibrate.m<\/a>\u00a0calibrates 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\u2019s how it looks in the MATLAB console. The inputs are in italics.<\/p>\n<pre>&gt;&gt; <em>ajfCalibrate<\/em><br \/>connect: Serial-\/dev\/tty.usbmodem4001<br \/>status: open<br \/>Sweep start (MHz)? <em>7<\/em><br \/>Sweep stop (MHz) ? <em>7.2<\/em><br \/>Calibrating...<br \/>press RETURN when S11 is open<br \/>press RETURN when S11 is shorted<br \/>press RETURN when S11 has 50 ohm load<br \/>Save [0-4]? <em>4<\/em><br \/>close<br \/>&gt;&gt;<\/pre>\n<p>The second script <a href=\"..\/code\/nanoVNA\/ajfVSWR.m\">ajfVSWR.m<\/a>\u00a0produces a chart of VSWR against frequency. Most radio hams are happier with this than the LogMag chart preferred by RF designers.\u00a0<\/p>\n<p>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\u00a0small transmitting loops.\u00a0<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"40m-FT8-VSWR.png\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2020\/09\/40m-FT8-VSWR.png\" alt=\"40m FT8 VSWR\" width=\"560\" height=\"420\" border=\"0\" \/><\/p>\n<p>The graph can be zoomed in MATLAB and have data cursors added to show more details.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" title=\"40m-FT8-VSWR-2.png\" src=\"https:\/\/fletch.scot\/wp\/wp-content\/uploads\/2020\/09\/40m-FT8-VSWR-2.png\" alt=\"40m FT8 VSWR 2\" width=\"560\" height=\"420\" border=\"0\" \/><\/p>\n<p>The VSWR could be lower. I think I left a metal step-ladder in the attic which is affecting the loop.<\/p>\n<p>ajf? My initials.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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. \u00a0 I suggest you buy a nanoVNA from a reputable dealer as there are plenty of clones which don\u2019t work as well as the original.\u00a0The model I have &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/fletch.scot\/wp\/?p=105\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;The nanoVNA and MATLAB&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,12],"tags":[3,45,34,50],"class_list":["post-105","post","type-post","status-publish","format-standard","hentry","category-aerial","category-radio","tag-electronics","tag-matlab","tag-radio","tag-vna"],"_links":{"self":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/105","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=105"}],"version-history":[{"count":5,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/105\/revisions"}],"predecessor-version":[{"id":343,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=\/wp\/v2\/posts\/105\/revisions\/343"}],"wp:attachment":[{"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=105"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=105"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fletch.scot\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=105"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}