-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgageAcq2.m
89 lines (74 loc) · 3.22 KB
/
gageAcq2.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
function [sAvg, ret] = gageAcq2(handle, rawdata, nAvg, acqMode)
% function [sAvg, t_acq, t_tot] = gageAcq(handle, rawdata, nAvg)
% t_start_acq_all = tic;
% Define how the data is transferred to Matlab from the DAQ system
transfer.Mode = CsMl_Translate('Default', 'TxMode');
transfer.Segment = 1;
[ret, acqInfo] = CsMl_QueryAcquisition(handle);
transfer.Start = -acqInfo.TriggerHoldoff;
transfer.Length = acqInfo.SegmentSize;
nPts = transfer.Length;
Fs = acqInfo.SampleRate;
if nargin == 1
rawdata = 1;
nAvg = 1;
elseif nargin == 2
nAvg = 1;
elseif nargin == 3
acqMode = 'Single';
end
switch acqMode
case 'Single'
if rawdata
s = zeros(1, nPts, 'int16');
sAvg = zeros(1, nPts, 'int16');
else
s = zeros(1, nPts, 'double');
sAvg = zeros(1, nPts, 'double');
end
for i = 1:nAvg
ret = CsMl_Capture(handle); % Start acquisition and await trigger event
CsMl_ErrorHandler(ret, 1, handle);
status = CsMl_QueryStatus(handle);
while status ~= 0 % Wait until measurement is done (status = 0)
status = CsMl_QueryStatus(handle);
end
transfer.Channel = 1;
% t_trans_start = tic;
[ret, s] = CsMl_Transfer(handle, transfer, rawdata); % Transmit raw ADC data to Matlab
CsMl_ErrorHandler(ret, 1, handle);
% sAvg = (s + sAvg*(i-1))/i;
sAvg = sAvg + s/nAvg;
end
% t_trans = toc(t_trans_start); % Time for data transmission
% t_acq = nPts/Fs + t_trans; % Total acquisition time (samples + data transmission)
% t_tot = toc(t_start_acq_all);
case 'Dual'
if rawdata
s = zeros(nPts, 2, 'int16');
sAvg = zeros(nPts, 2, 'int16');
else
s = zeros(nPts, 2, 'double');
sAvg = zeros(nPts, 2, 'double');
end
for chan=1:2
for i = 1:nAvg
ret = CsMl_Capture(handle); % Start acquisition and await trigger event
CsMl_ErrorHandler(ret, 1, handle);
status = CsMl_QueryStatus(handle);
while status ~= 0 % Wait until measurement is done (status = 0)
status = CsMl_QueryStatus(handle);
end
transfer.Channel = chan;
% t_trans_start = tic;
[ret, s(:,chan)] = CsMl_Transfer(handle, transfer, rawdata); % Transmit raw ADC data to Matlab
CsMl_ErrorHandler(ret, 1, handle);
% sAvg = (s + sAvg*(i-1))/i;
sAvg(:,chan) = sAvg(:,chan) + s(:,chan)/nAvg;
end
% t_trans = toc(t_trans_start); % Time for data transmission
% t_acq = nPts/Fs + t_trans; % Total acquisition time (samples + data transmission)
% t_tot = toc(t_start_acq_all);
end
end
end