diff --git a/README.md b/README.md new file mode 100644 index 0000000..c8f2cb3 --- /dev/null +++ b/README.md @@ -0,0 +1,163 @@ +# PicoVNA106 — MATLAB Instrument Driver + +A MATLAB class for controlling the **PicoVNA 106** vector network analyzer over a TCP/IP connection. Provides methods for triggering sweeps, acquiring S-parameters in polar form, querying frequency axes, and packaging results into an `SPARAMS` object. + +--- + +## Requirements + +- MATLAB with the **Instrument Control Toolbox** +- The **PicoVNA software** must be running on the host machine with its SCPI server active on `localhost:5025` +- The companion `SPARAMS` class (required by `readToSparamsObject`, available at https://github.com/njchorda/MATLAB-Touchstone-Reader) + +--- + +## Installation + +1. Clone or download this repository. +2. Add the folder to your MATLAB path: + ```matlab + addpath('/path/to/PicoVNA106'); + ``` +3. Ensure the PicoVNA application is open and its SCPI server is enabled before instantiating the class. + +--- + +## Quick Start + +```matlab +% Connect to the VNA +vna = PicoVNA106(); + +% Trigger a single sweep and wait for completion +vna.sweep(); + +% Read all four S-parameters as complex polar data +[S11, S12, S21, S22] = vna.getSParams(); + +% Get the corresponding frequency axis in Hz +f = vna.getFreqAxis(); + +% Or read everything into a single SPARAMS object +S = vna.readToSparamsObject(); + +% Clean up +vna.deInit(); +``` + +--- + +## API Reference + +### Constructor + +```matlab +obj = PicoVNA106() +``` + +Opens a TCP connection to `localhost:5025` with a default timeout of 10 seconds. The PicoVNA 5 software must already be running. + +--- + +### Sweep Control + +```matlab +vna.sweep() +``` +Triggers a single sweep (`INIT`) and waits for the instrument to acknowledge completion. + +```matlab +vna.setContinuousSweep() +``` +Puts the instrument into continuous sweep mode (`INIT:CONT:ALL`). + +--- + +### S-Parameter Acquisition + +```matlab +[S11, S12, S21, S22] = vna.getSParams() +``` +Reads all four S-parameters from the instrument buffer as **complex polar vectors**. Each value is returned as a column vector of complex doubles. **Does not trigger a new sweep** — call `sweep()` first if fresh data is needed. + +```matlab +S = vna.readToSparamsObject() +``` +Combines `getSParams()` and `getFreqAxis()` into a single `SPARAMS` object. Sets the reference impedance to 50 Ω and the port count to 2. The S-parameter and frequency vectors are column-oriented. + +--- + +### Frequency Axis + +```matlab +f = vna.getFreqAxis() +``` +Queries the start frequency, stop frequency, and number of sweep points from the instrument and returns a linearly spaced frequency vector in Hz. Handles `kHz`, `MHz`, and `GHz` unit strings automatically. + +--- + +### Power Level + +```matlab +p = vna.getPowerLevel() +``` +Returns the current stimulus power level in dBm. + +```matlab +vna.setPowerLevel(p) +``` +Sets the stimulus power level in dBm. + +--- + +### Instrument Utilities + +```matlab +id = vna.getID() +``` +Queries the instrument identification string (`*IDN?`). + +```matlab +vna.reset() +``` +Sends `*RST` to reset the instrument to its default state. + +```matlab +vna.selfTest() +``` +Runs the built-in self-test (`*TST?`) and prints the result to the console. + +```matlab +vna.setLocal() +``` +Returns front-panel control to the user (`SYST:LOC`). + +```matlab +vna.clearBuffer() +``` +Flushes any pending data in the TCP receive buffer by reading until empty. Temporarily reduces the timeout to 0.2 s during the flush. + +```matlab +retVal = vna.sendCommand(cmd) +``` +Sends an arbitrary SCPI command. If the command contains `?`, it reads and returns the response string; otherwise returns `0`. + +```matlab +vna.deInit() +``` +Releases the TCP connection. Returns `1` on success, `0` if the connection was already invalid. + +--- + +## Notes + +- S-parameters are returned in **polar (real/imaginary) format** — the instrument sends interleaved real and imaginary doubles which the driver recombines into complex MATLAB arrays. +- `getSParams()` does **not** trigger a sweep. Always call `sweep()` before reading data if you need up-to-date measurements. +- The frequency string parser handles `kHz`, `MHz`, and `GHz` unit suffixes from the instrument response. Responses in plain Hz are not currently handled — extend `freqStrConvert` if needed. +- The default TCP timeout is 10 seconds, which may need increasing for slow sweeps (e.g. high point counts or narrow IF bandwidths). + +--- + +## License + +MIT License — see [LICENSE](LICENSE) for details.