Skip to content

Commit 62095a5

Browse files
committed
Add PicoVNA108_S_Parameter_Example.m to show how to use PicoVNA 108 in MATLAB
1 parent b1ca514 commit 62095a5

File tree

1 file changed

+204
-0
lines changed

1 file changed

+204
-0
lines changed
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
%% PicoVNA108 S-Parameter Example
2+
%
3+
% This is an example of setting up the connection with the Pico Technology
4+
% PicoVNA Vector Network Analyzer, loading calibration data, making measurements and collecting
5+
% the log magnitude data for S11, S12, S21 and S22 parameters.
6+
%
7+
% To run this example session, type the name of the file,
8+
% |PicoVNA_S_Parameter_Example|, in the MATLAB Command Window.
9+
%
10+
% The file, |PicoVNA108_S_Parameter_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+
% Additionally you must have the |.cal| file for your device in the current
15+
% folder.
16+
%
17+
% *Example:*
18+
% PicoVNA108_S-Parameter_Example;
19+
%
20+
% *Description:*
21+
% Demonstrates how to connect to the VNA108, load in a calibration, make
22+
% measurements and collect data for S11, S12, S21 and S22 parameters. The
23+
% S-parameters are plotted onto auto-scaled plots. The measurement and
24+
% data collection is looped until the user stops the process.
25+
%
26+
% *Copyright:* © 2017-2020 Pico Technology Ltd. See LICENSE file for terms.
27+
28+
%% Clear workspace, command window and close figures
29+
30+
clear;
31+
clc;
32+
close all;
33+
34+
%% Connect to VNA
35+
36+
picoVNACOMObj = connectVNA108;
37+
38+
%% Load Calibration
39+
% Load a calibration and settings file.
40+
% This needs to be generated and saved using the PicoVNA2 software.
41+
42+
% Replace DefCal.cal with the correct calibration for your device, 'Pico TD
43+
% demo with limits [Serial#].cal'.
44+
picoVNACOMObj.LoadCal('?');
45+
46+
%%
47+
% This needs to be generated and saved using the PicoVNA 2 software.
48+
%
49+
% Replace |DefCal.cal| with the correct calibration for your device, |Pico TD
50+
% demo with limits [Serial#].cal|.
51+
picoVNACOMObj.LoadCal('DefCal.cal');
52+
53+
%% Stop button for exiting loop
54+
% Create a stop button for exiting rapid block capture and for displaying
55+
% the data in.
56+
[stopFig.f, stopFig.h] = stopButtonVNA(0, 50, 1350,1000);
57+
58+
flag = 1; % Use flag variable to indicate if stop button has been clicked (0)
59+
setappdata(gcf, 'run', flag);
60+
61+
%% Capture and plot data
62+
63+
n = 0; % Number of Loops
64+
go = 1; % While loop condition (1 = run, 0 = stop)
65+
66+
while go == 1
67+
68+
% Instruct VNA do make a sweep measurement
69+
picoVNACOMObj.Measure('Raw');
70+
71+
% Get Log magnitude data for all S-Parameters
72+
[s11.freq, s11.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S11','logmag');
73+
[s22.freq, s22.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S22','logmag');
74+
[s12.freq, s12.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S12','logmag');
75+
[s21.freq, s21.logmagDataPoints] = getBlockDataVNA(picoVNACOMObj,'S21','logmag');
76+
77+
% Get values for y-axes limits
78+
maxS11c = max(s11.logmagDataPoints);
79+
80+
if n == 0
81+
maxS11 = maxS11c;
82+
end
83+
84+
if maxS11c > maxS11
85+
maxS11 = maxS11c;
86+
end
87+
88+
minS11c = min(s11.logmagDataPoints);
89+
90+
if n == 0
91+
minS11 = minS11c;
92+
end
93+
94+
if minS11c < minS11
95+
minS11 = minS11c;
96+
end
97+
98+
maxS22c = max(s22.logmagDataPoints);
99+
100+
if n == 0
101+
maxS22 = maxS22c;
102+
end
103+
104+
if maxS22c > maxS22
105+
maxS22 = maxS22c;
106+
end
107+
108+
minS22c = min(s22.logmagDataPoints);
109+
110+
if n == 0
111+
minS22 = minS22c;
112+
end
113+
114+
if minS22c < minS22
115+
minS22 = minS22c;
116+
end
117+
118+
maxS12c = max(s12.logmagDataPoints);
119+
120+
if n == 0
121+
maxS12 = maxS12c;
122+
end
123+
124+
if maxS12c > maxS12
125+
maxS12 = maxS12c;
126+
end
127+
128+
minS12c = min(s12.logmagDataPoints);
129+
130+
if n == 0
131+
minS12 = minS12c;
132+
end
133+
134+
if minS12c < minS12
135+
minS12 = minS12c;
136+
end
137+
138+
maxS21c = max(s21.logmagDataPoints);
139+
140+
if n == 0
141+
maxS21 = maxS21c;
142+
end
143+
144+
if maxS21c > maxS21
145+
maxS21 = maxS21c;
146+
end
147+
148+
minS21c = min(s21.logmagDataPoints);
149+
150+
if n == 0
151+
minS21 = minS21c;
152+
end
153+
154+
if minS21c < minS21
155+
minS21 = minS21c;
156+
end
157+
158+
159+
% Plot Data for all S-parameters
160+
subplot(2,2,1);
161+
plot(s11.freq, s11.logmagDataPoints);
162+
xlabel('Frequency (Hz)');
163+
ylabel('Magnitude (dB)');
164+
ylim([minS11 maxS11]);
165+
title('S11')
166+
167+
subplot(2,2,2);
168+
plot(s12.freq, s12.logmagDataPoints);
169+
xlabel('Frequency (Hz)');
170+
ylabel('Magnitude (dB)');
171+
ylim([minS12 maxS12]);
172+
title('S12');
173+
174+
subplot(2,2,3);
175+
plot(s21.freq, s21.logmagDataPoints);
176+
xlabel('Frequency (Hz)');
177+
ylabel('Magnitude (dB)');
178+
ylim([minS21 maxS21]);
179+
title('S21');
180+
181+
subplot(2,2,4);
182+
plot(s22.freq, s22.logmagDataPoints);
183+
xlabel('Frequency (Hz)');
184+
ylabel('Magnitude (dB)');
185+
ylim([minS22 maxS22]);
186+
title('S22');
187+
188+
drawnow
189+
190+
n = n+1 % Current Loop Number
191+
192+
% Check if stop button has been pressed
193+
flag = getappdata(gcf, 'run');
194+
if flag == 0
195+
go = 0;
196+
end
197+
clear maxS11c minS11c maxS12c minS12c maxS21c minS21c maxS22c minS22c
198+
end
199+
%% Disconnect VNA
200+
201+
disconnectVNA(picoVNACOMObj)
202+
203+
% Tidy workspace
204+
clear ans flag go maxS11 minS11 maxS12 minS12 maxS21 minS21 maxS22 minS22 picoVNACOMObj

0 commit comments

Comments
 (0)