-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetdatafromSA.m
56 lines (45 loc) · 1.04 KB
/
getdatafromSA.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
%%%%% this is a program to connect to spectral analyzer and read data
%clear
objs = instrfind;
fclose(objs)
%fclose(vSA);
vSA = visa('ni','GPIB0::21::INSTR');
vSA.inputbuffersize = 10000;
fopen(vSA);
% Show display window
fwrite(vSA, 'SYST:DISP:UPD ON');
% define central frequency
fwrite(vSA, 'FREQ:CENT 3.3 GHz');
% define frequency span
fwrite(vSA, 'FREQ:SPAN 30 MHz');
% define rf bandwidth
fwrite(vSA, 'BAND 20 kHz');
% define video bandwidth
fwrite(vSA, 'BAND:VIDEO 50 kHz');
% number of sweep point
num_points = 301;
fprintf(vSA, 'SWEEP:POINTS %d\n', num_points);
% define data type as ASCII
fwrite(vSA, 'FORM ASCII');
N_meas=1;
spec=zeros(num_points,N_meas);
tic;
for n_meas=1:1:N_meas
% contintous (ON)/single sweep (OFF)
fwrite(vSA, 'INIT:CONT OFF');
% perform sweep
fwrite(vSA, 'INIT;');
% wait for sweep to complete
fprintf(vSA, '*OPC?');
%fscanf(vSA, '%d');
fprintf(vSA, 'TRACE? TRACE1');
warning off;
read_values = fscanf(vSA, '%f,', num_points);
spec(:,n_meas)=read_values;
end
toc
%fclose(vSA);
warning on;
%%
figure(4)
plot(spec(:,:));