Skip to content

Commit 3c2317d

Browse files
committed
Restore example files
1 parent d21b193 commit 3c2317d

File tree

4 files changed

+513
-0
lines changed

4 files changed

+513
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
%% PicoVNA Pass-Fail Testing Example
2+
%
3+
% This is an example of a Pass/Fail test using the PicoVNA. This compares a
4+
% S21 log magnitude sweep from a device to the same measurement of a
5+
% previously measured Golden DUT using the |PicoVNA_GoldenDUT_Example.m| file.
6+
%
7+
% To run this example session, type the name of the file,
8+
% |PicoVNA_DUT_PassFail_Testing_Example|, in the MATLAB Command Window.
9+
%
10+
% The file, |PicoVNA_DUT_PassFail_Testing_Example.m| must be on your MATLAB
11+
% Path. For 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 and the
15+
% |GoldenDUT.mat| file in the current folder.
16+
%
17+
% *Example:*
18+
% PicoVNA_DUT_PassFail_Testing_Example;
19+
%
20+
% *Description:*
21+
% Demonstrates how to use the VNA to compare DUTs to a saved Golden DUT
22+
% and evaluate if the DUT is within tolerance of the Golden DUT
23+
% measurement.
24+
%
25+
% *Copyright:* © 2017-2018 Pico Technology Ltd. See LICENSE file for terms.
26+
27+
%% Clear workspace, command window and close figures
28+
29+
clear;
30+
clc;
31+
close all;
32+
33+
%% Connect to VNA
34+
35+
picoVNACOMObj = connectVNA;
36+
37+
%% Load calibration
38+
% Load a calibration and settings file.
39+
% This needs to be generated and saved using the PicoVNA2 software.
40+
%
41+
% Replace |DefCal.cal| with the correct calibration for your device, |Pico TD
42+
% demo with limits [Serial#].cal|.
43+
44+
picoVNACOMObj.LoadCal('DefCal.cal');
45+
46+
%% Load Golden DUT log magnitude
47+
% Load in the reference data from the Golden Dut captured using
48+
% <PicoVNA_GoldenDUT_Example.html |PicoVNA_GoldenDUT_Example|>
49+
50+
load('GoldenDUT.mat');
51+
52+
%% Create pass band
53+
% Create a pass band using the Golden DUT data and the tolererance in dB of
54+
% the testing for comparison with the DUTs later.
55+
56+
tolerance = 0.2; % Tolerance of the cable in dB
57+
58+
% Create the upper and lower bounds of the pass band.
59+
Error.Upper = Golden.S12LogMag + tolerance;
60+
Error.Lower = Golden.S12LogMag - tolerance;
61+
62+
%% Testing
63+
% Create a stop button for ending testing.
64+
[stopFig.f, stopFig.h] = stopButtonVNA(50, 200, 1000, 500);
65+
66+
flag = 1; % Use flag variable to indicate if stop button has been clicked (0)
67+
setappdata(gcf, 'run', flag);
68+
stopbutton = gcf;
69+
70+
% Create the axes for plotting the test measurements on with the pass band
71+
% displayed.
72+
ax1 = subplot(1,1,1);
73+
plot(ax1,Golden.Frequency,Error.Upper,'k');
74+
hold on
75+
plot(ax1,Golden.Frequency,Error.Lower,'k');
76+
hold off
77+
xlabel('Frequency (Hz)');
78+
ylabel('Magnitude');
79+
title('Test Limits');
80+
81+
%%
82+
n = 0; % Number of Loops
83+
go = 1; % While loop condition (1 = run, 0 = stop)
84+
85+
while go == 1
86+
87+
% Run test on mouse click on the figure
88+
k = waitforbuttonpress;
89+
% Check if stop button has been pressed
90+
flag = getappdata(stopbutton, 'run');
91+
92+
if flag == 0
93+
go = 0;
94+
end
95+
96+
if k == 0
97+
98+
n = n+1
99+
100+
% Make measurement of the DUT
101+
picoVNACOMObj.Measure('ALL');
102+
103+
% Collect the S21 Log Magnitude data from the VNA
104+
[test.frequency, test.logmag] = getBlockDataVNA(picoVNACOMObj,'S21','logmag');
105+
106+
% Compare the test data with the pass band limits at every point
107+
for i = 1:length(test.logmag)
108+
109+
if (test.logmag(1,i) >= Error.Upper(1,i)) || (test.logmag(1,i) <= Error.Lower(1,i))
110+
test.Check = 1; % Set Check to 1 if the point is outside of the pass band
111+
else
112+
test.Check = 0; % Set Check to 0 if the point is inside of the pass band
113+
end
114+
115+
end
116+
117+
% Inspect Check to see if any point failed the tolerance testing and
118+
% record whether the test was a pass or a fail.
119+
% If the DUT passed the test it is assigned a 1, if it failed it is
120+
% assigned a 0.
121+
if sum(test.Check) == 0
122+
pass(n,1) = 1;
123+
else
124+
pass(n,1) = 0;
125+
end
126+
127+
% Plot the Test Results
128+
plot(ax1,Golden.Frequency,Error.Upper,'k');
129+
hold on
130+
plot(ax1,Golden.Frequency,Error.Lower,'k');
131+
132+
% The test data is plotted in green with "Test Passed" title if
133+
% pass = 1 for the DUT
134+
if pass(n,1) == 1
135+
136+
plot(ax1,test.frequency,test.logmag,'g');
137+
title('Test Passed');
138+
139+
% The test data is plotted in red with "Test Failed" title if pass = 0
140+
% for the DUT
141+
else
142+
143+
plot(ax1,test.frequency,test.logmag,'r');
144+
title(['Test Failed']);
145+
146+
end
147+
148+
xlabel('Frequency (Hz)');
149+
ylabel('Magnitude');
150+
drawnow
151+
hold off
152+
disp('Test Complete')
153+
154+
end
155+
156+
end
157+
158+
%% Disconnect VNA
159+
160+
disconnectVNA(picoVNACOMObj)
161+
close PicoVNA
162+
clear ans ax1 flag go i k n picoVNACOMObj
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
%% Pico VNA Golden DUT Data Collection Example
2+
%
3+
% This is an example of Golden DUT data aquisition using the PicoVNA. This
4+
% makes a measurement of the Golden DUT and retrieves the S21 log magnitude
5+
% data from the VNA ready for use in the
6+
% <PicoVNA_DUT_PassFail_testing_Example.html |PicoVNA_DUT_PassFail_Testing_Example|>.
7+
%
8+
% To run this example session, type the name of the file,
9+
% |PicoVNA_GoldenDUT_Example|, in the MATLAB Command Window.
10+
%
11+
% The file, |PicoVNA_GoldenDUT_Example.m| must be on your MATLAB Path. For
12+
% additional information on setting your MATLAB path, see
13+
% <matlab:doc('addpath') addpath>.
14+
%
15+
% Additionally you must have the |.cal| file for your device in the current
16+
% folder.
17+
%
18+
% *Example:*
19+
% PicoVNA_GoldenDUT_Example;
20+
%
21+
% *Description:*
22+
% Demonstrates how to use the VNA to collect and save data for a Golden
23+
% DUT for use in the PicoVNA_DUT_PassFail_Example.m script.
24+
%
25+
% *Copyright:* © 2017-2018 Pico Technology Ltd. See LICENSE file for terms.
26+
27+
%% Clear workspace, command window and close figures
28+
29+
clear;
30+
clc;
31+
close all;
32+
33+
%% Connect to VNA
34+
35+
picoVNACOMObj = connectVNA;
36+
37+
%% Load calibration
38+
% Load a calibration and settings file.
39+
% This needs to be generated and saved using the PicoVNA 2 software.
40+
%
41+
% Replace |DefCal.cal| with the correct calibration for your device, |Pico TD
42+
% demo with limits [Serial#].cal|.
43+
picoVNACOMObj.LoadCal('DefCal.cal');
44+
45+
%% Measure Golden DUT
46+
% Make measurement of the Golden DUT and retrieve the log magnitude data
47+
% for the S21 parameter.
48+
49+
picoVNACOMObj.Measure('ALL');
50+
[Golden.Frequency, Golden.S12LogMag] = getBlockDataVNA(picoVNACOMObj,'S21','logmag');
51+
52+
%% Save Golden DUT Data
53+
% Save the Golden DUT data read for use in the <PicoVNA_DUT_PassFail_Testing_example.html Pass/Fail Testing Example>.
54+
55+
save ('GoldenDUT.mat', 'Golden');
56+
57+
%% Disconnect VNA
58+
59+
disconnectVNA(picoVNACOMObj);
60+
61+
disp('Complete');

0 commit comments

Comments
 (0)