|
| 1 | +%% PicoVNA S-Parameter Multi Device Example |
| 2 | +% |
| 3 | +% This is an example of setting up the connection with three Pico Technology |
| 4 | +% PicoVNA Vector Newtwork Analyzers, loading calibration data, making measurements and collecting |
| 5 | +% the log magnitude data for S11, S12, S21 and S22 parameters on all devices. |
| 6 | +% |
| 7 | +% To run this example session, type the name of the file, |
| 8 | +% |PicoVNA_S_Parameter_Multi_Device_Example|, in the MATLAB Command Window. |
| 9 | +% |
| 10 | +% The file, |PicoVNA_S_Parameter_Multi_Device_Example.m| must be on your MATLAB Path. For |
| 11 | +% additional information on setting your MATLAB path, see |
| 12 | +% <matlab:doc('addpath') addpath>. |
| 13 | +% |
| 14 | + |
| 15 | +% Additionally you must have the |.cal| file for your device in the current |
| 16 | +% folder. |
| 17 | +% |
| 18 | +% *Example:* |
| 19 | +% PicoVNA_S-Parameter_Multi_Device_Example; |
| 20 | +% |
| 21 | +% *Description:* |
| 22 | +% Demonstrates how to connect to three VNAs, load in a calibration, make |
| 23 | +% measurements and collect data for S11, S12, S21 and S22 parameters on all devices. |
| 24 | +% The S-parameters are plotted onto auto-scaled plots. The measurement and |
| 25 | +% data collection is looped until the user stops the process. |
| 26 | +% |
| 27 | +% *Copyright:* © 2017-2018 Pico Technology Ltd. See LICENSE file for terms. |
| 28 | + |
| 29 | +%% Clear workspace, command window and close figures |
| 30 | + |
| 31 | +clear; |
| 32 | +clc; |
| 33 | +close all; |
| 34 | + |
| 35 | +%% Connect to VNA |
| 36 | + |
| 37 | +picoVNACOMObj = connectVNA_SN('DC2LZ9IY'); |
| 38 | +picoVNACOMObj_1 = connectVNA_SN_1('DC2L240G'); |
| 39 | +%% |
| 40 | +picoVNACOMObj_2 = connectVNA_SN_2('DC2NXKID'); |
| 41 | + |
| 42 | +%% Load Calibration |
| 43 | +% Load a calibration and settings file. |
| 44 | +% This needs to be generated and saved using the PicoVNA 2 software. |
| 45 | +% |
| 46 | +% Replace |DefCal.cal| with the correct calibration for your device, |Pico TD |
| 47 | +% demo with limits [Serial#].cal|. |
| 48 | +ans=picoVNACOMObj.LoadCal('?'); |
| 49 | +ans_1=picoVNACOMObj_1.LoadCal('?'); |
| 50 | +ans_2=picoVNACOMObj_2.LoadCal('?'); |
| 51 | + |
| 52 | +%% Stop button for exiting loop |
| 53 | +% Create a stop button for exiting rapid block capture and for displaying |
| 54 | +% the data in. |
| 55 | +[stopFig.f, stopFig.h] = stopButtonVNA(0, 50, 1350,1000); |
| 56 | + |
| 57 | +flag = 1; % Use flag variable to indicate if stop button has been clicked (0) |
| 58 | +setappdata(gcf, 'run', flag); |
| 59 | + |
| 60 | +%% Capture and plot data |
| 61 | + |
| 62 | +n = 0; % Number of Loops |
| 63 | +go = 1; % While loop condition (1 = run, 0 = stop) |
| 64 | + |
| 65 | +while go == 1 |
| 66 | + |
| 67 | + n |
| 68 | + tic |
| 69 | + % Instruct VNA do make a sweep measurement |
| 70 | + picoVNACOMObj.Measure('ALL'); |
| 71 | + toc |
| 72 | + picoVNACOMObj_1.Measure('ALL'); |
| 73 | + toc |
| 74 | + picoVNACOMObj_2.Measure('ALL'); |
| 75 | + |
| 76 | + toc |
| 77 | + |
| 78 | + % Get Log magnitude data for all S-Parameters |
| 79 | + [s11.freq, s11.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S11','logmag'); |
| 80 | + [s11_1.freq, s11_1.logmagDataPoints] = getBlockDataVNA_1(picoVNACOMObj_1,'S11','logmag'); |
| 81 | + [s11_2.freq, s11_2.logmagDataPoints] = getBlockDataVNA_2(picoVNACOMObj_2,'S11','logmag'); |
| 82 | + |
| 83 | + [s22.freq, s22.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S22','logmag'); |
| 84 | + [s22_1.freq, s22_1.logmagDataPoints] = getBlockDataVNA_1(picoVNACOMObj_1,'S22','logmag'); |
| 85 | + [s22_2.freq, s22_2.logmagDataPoints] = getBlockDataVNA_2(picoVNACOMObj_1,'S22','logmag'); |
| 86 | + |
| 87 | + [s12.freq, s12.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S12','logmag'); |
| 88 | + [s12_1.freq, s12_1.logmagDataPoints] = getBlockDataVNA_1(picoVNACOMObj_1,'S12','logmag'); |
| 89 | + [s12_2.freq, s12_2.logmagDataPoints] = getBlockDataVNA_2(picoVNACOMObj_2,'S12','logmag'); |
| 90 | + |
| 91 | + [s21.freq, s21.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S21','logmag'); |
| 92 | + [s21_1.freq, s21_1.logmagDataPoints] = getBlockDataVNA_1(picoVNACOMObj_1,'S21','logmag'); |
| 93 | + [s21_2.freq, s21_2.logmagDataPoints] = getBlockDataVNA_2(picoVNACOMObj_2,'S21','logmag'); |
| 94 | + |
| 95 | + toc |
| 96 | + |
| 97 | + % Get values for y-axes limits |
| 98 | + maxS11c = max(s11.logmagDataPoints); |
| 99 | + maxS11c_1 = max(s11_1.logmagDataPoints); |
| 100 | + maxS11c_2 = max(s11_2.logmagDataPoints); |
| 101 | + |
| 102 | + if n == 0 |
| 103 | + maxS11 = maxS11c; |
| 104 | + elseif maxS11c > maxS11 |
| 105 | + maxS11 = maxS11c; |
| 106 | + elseif maxS11c_1 > maxS11 |
| 107 | + maxS11 = maxS11c_1; |
| 108 | + elseif maxS11c_2 > maxS11 |
| 109 | + maxS11 = maxS11c_2; |
| 110 | + end |
| 111 | + |
| 112 | + minS11c = min(s11.logmagDataPoints); |
| 113 | + minS11c_1 = min(s11_1.logmagDataPoints); |
| 114 | + minS11c_2 = min(s11_2.logmagDataPoints); |
| 115 | + |
| 116 | + if n == 0 |
| 117 | + minS11 = minS11c; |
| 118 | + elseif minS11c < minS11 |
| 119 | + minS11 = minS11c; |
| 120 | + elseif minS11c_1 < minS11 |
| 121 | + minS11 = minS11c_1; |
| 122 | + elseif minS11c_2 <minS11 |
| 123 | + minS11 = minS11c_2; |
| 124 | + end |
| 125 | + |
| 126 | + maxS22c = max(s22.logmagDataPoints); |
| 127 | + maxS22c_1 = max(s22_1.logmagDataPoints); |
| 128 | + maxS22c_2 = max(s22_2.logmagDataPoints); |
| 129 | + |
| 130 | + if n == 0 |
| 131 | + maxS22 = maxS22c; |
| 132 | + elseif maxS22c > maxS22 |
| 133 | + maxS22 = maxS22c; |
| 134 | + elseif maxS22c_1 > maxS22 |
| 135 | + maxS22 = maxS22c_1; |
| 136 | + elseif maxS22c_2 > maxS22 |
| 137 | + maxS22 = maxS22c_2; |
| 138 | + end |
| 139 | + |
| 140 | + minS22c = min(s22.logmagDataPoints); |
| 141 | + minS22c_1 = min(s22_1.logmagDataPoints); |
| 142 | + minS22c_2 = min(s22_2.logmagDataPoints); |
| 143 | + |
| 144 | + if n == 0 |
| 145 | + minS22 = minS22c; |
| 146 | + elseif minS22c < minS22 |
| 147 | + minS22 = minS22c; |
| 148 | + elseif minS22c_1 < minS22 |
| 149 | + minS22 = minS22c_1; |
| 150 | + elseif minS22c_2 < minS22 |
| 151 | + minS22 = minS22c_2; |
| 152 | + end |
| 153 | + |
| 154 | + maxS12c = max(s12.logmagDataPoints); |
| 155 | + maxS12c_1 = max(s12_1.logmagDataPoints); |
| 156 | + maxS12c_2 = max(s12_2.logmagDataPoints); |
| 157 | + |
| 158 | + if n == 0 |
| 159 | + maxS12 = maxS12c; |
| 160 | + elseif maxS12c > maxS12 |
| 161 | + maxS12 = maxS12c; |
| 162 | + elseif maxS12c_1 > maxS12 |
| 163 | + maxS12 = maxS12c_1; |
| 164 | + elseif maxS12c_2 > maxS12 |
| 165 | + maxS12 = maxS12c_2; |
| 166 | + end |
| 167 | + |
| 168 | + minS12c = min(s12.logmagDataPoints); |
| 169 | + minS12c_1 = min(s12_1.logmagDataPoints); |
| 170 | + minS12c_2 = min(s12_2.logmagDataPoints); |
| 171 | + |
| 172 | + if n == 0 |
| 173 | + minS12 = minS12c; |
| 174 | + elseif minS12c < minS12 |
| 175 | + minS12 = minS12c; |
| 176 | + elseif minS12c_1 < minS12 |
| 177 | + minS12 = minS12c_1; |
| 178 | + elseif minS12c_2 < minS12 |
| 179 | + minS12 = minS12c_2; |
| 180 | + end |
| 181 | + |
| 182 | + maxS21c = max(s21.logmagDataPoints); |
| 183 | + maxS21c_1 = max(s21_1.logmagDataPoints); |
| 184 | + maxS21c_2 = max(s21_2.logmagDataPoints); |
| 185 | + |
| 186 | + if n == 0 |
| 187 | + maxS21 = maxS21c; |
| 188 | + elseif maxS21c > maxS21 |
| 189 | + maxS21 = maxS21c; |
| 190 | + elseif maxS21c_1 > maxS21 |
| 191 | + maxS21 = maxS21c_1; |
| 192 | + elseif maxS21c_2 > maxS21 |
| 193 | + maxS21 = maxS21c_2; |
| 194 | + end |
| 195 | + |
| 196 | + minS21c = min(s21.logmagDataPoints); |
| 197 | + minS21c_1 = min(s21_1.logmagDataPoints); |
| 198 | + minS21c_2 = min(s21_2.logmagDataPoints); |
| 199 | + |
| 200 | + if n == 0 |
| 201 | + minS21 = minS21c; |
| 202 | + elseif minS21c < minS21 |
| 203 | + minS21 = minS21c; |
| 204 | + elseif minS21c_1 < minS21 |
| 205 | + minS21 = minS21c_1; |
| 206 | + elseif minS21c_2 < minS21 |
| 207 | + minS21 = minS21c_2; |
| 208 | + end |
| 209 | + |
| 210 | + toc |
| 211 | + |
| 212 | + % Plot Data for all S-parameters |
| 213 | + subplot(2,2,1); |
| 214 | + plot(s11.freq, s11.logmagDataPoints, 'b'); |
| 215 | + hold on |
| 216 | + plot(s11_1.freq, s11_1.logmagDataPoints, 'r'); |
| 217 | + plot(s11_2.freq, s11_2.logmagDataPoints, 'g'); |
| 218 | + hold off |
| 219 | + xlabel('Frequency (Hz)'); |
| 220 | + ylabel('Magnitude (dB)'); |
| 221 | + ylim([minS11-5 maxS11+5]); |
| 222 | + title('S11') |
| 223 | + |
| 224 | + subplot(2,2,2); |
| 225 | + plot(s12.freq, s12.logmagDataPoints,'b'); |
| 226 | + hold on |
| 227 | + plot(s12_1.freq, s12_1.logmagDataPoints, 'r'); |
| 228 | + plot(s12_2.freq, s12_2.logmagDataPoints, 'g'); |
| 229 | + hold off |
| 230 | + xlabel('Frequency (Hz)'); |
| 231 | + ylabel('Magnitude (dB)'); |
| 232 | + ylim([minS12-5 maxS12+5]); |
| 233 | + title('S12'); |
| 234 | + |
| 235 | + subplot(2,2,3); |
| 236 | + plot(s21.freq, s21.logmagDataPoints,'b'); |
| 237 | + hold on |
| 238 | + plot(s21_1.freq, s21_1.logmagDataPoints, 'r'); |
| 239 | + plot(s21_2.freq, s21_2.logmagDataPoints, 'g'); |
| 240 | + hold off |
| 241 | + xlabel('Frequency (Hz)'); |
| 242 | + ylabel('Magnitude (dB)'); |
| 243 | + ylim([minS21-5 maxS21+5]); |
| 244 | + title('S21'); |
| 245 | + |
| 246 | + subplot(2,2,4); |
| 247 | + plot(s22.freq, s22.logmagDataPoints,'b'); |
| 248 | + hold on |
| 249 | + plot(s22_1.freq, s22_1.logmagDataPoints, 'r'); |
| 250 | + plot(s22_2.freq, s22_2.logmagDataPoints, 'g'); |
| 251 | + hold off |
| 252 | + xlabel('Frequency (Hz)'); |
| 253 | + ylabel('Magnitude (dB)'); |
| 254 | + ylim([minS22-5 maxS22+5]); |
| 255 | + title('S22'); |
| 256 | + |
| 257 | + drawnow |
| 258 | + |
| 259 | + toc |
| 260 | + |
| 261 | + |
| 262 | + |
| 263 | + % Check if stop button has been pressed |
| 264 | + flag = getappdata(gcf, 'run'); |
| 265 | + if flag == 0 |
| 266 | + go = 0; |
| 267 | + end |
| 268 | + clear maxS11c minS11c maxS12c minS12c maxS21c minS21c maxS22c minS22c |
| 269 | + clear maxS11c_1 minS11c_1 maxS12c_1 minS12c_1 maxS21c_1 minS21c_1 maxS22c_1 minS22c_1 |
| 270 | + clear maxS11c_2 minS11c_2 maxS12c_2 minS12c_2 maxS21c_2 minS21c_2 maxS22c_2 minS22c_2 |
| 271 | + |
| 272 | + toc |
| 273 | + n = n+1; % Current Loop Number |
| 274 | +end |
| 275 | +%% Disconnect VNA |
| 276 | + |
| 277 | +disconnectVNA(picoVNACOMObj) |
| 278 | +disconnectVNA_1(picoVNACOMObj_1) |
| 279 | +disconnectVNA_2(picoVNACOMObj_2) |
| 280 | + |
| 281 | + |
| 282 | +% Tidy workspace |
| 283 | +clear ans flag go maxS11 minS11 maxS12 minS12 maxS21 minS21 maxS22 minS22 picoVNACOMObj picoVNACOMObj_1 picoVNACOMObj_2 n s11 ans_1 ans_2 |
0 commit comments