-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgageAcqAvg2Chan_fast.m
66 lines (59 loc) · 2.37 KB
/
gageAcqAvg2Chan_fast.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
function [sAvg, ret] = gageAcqAvg2Chan_fast(DAQ, AcqInfo, ChanInfo)
% function [sAvg, t_acq, t_tot] = gageAcq(DAQ, 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');
% % if hard_average~=0
% % transfer.Mode = CsMl_Translate('DATA32', 'TxMode');
% % end
% v2, yuanhui 20190319. Reconsult FPGA avg and software avg
if AcqInfo.isUsingHWAvg == false
transfer.Mode = CsMl_Translate('Default', 'TxMode');
elseif AcqInfo.isUsingHWAvg == true
transfer.Mode = CsMl_Translate('DATA32', 'TxMode');
end
% [ret, acqInfo] = CsMl_QueryAcquisition(DAQ);
% acqInfo = AcqInfo;
transfer.SegmentCount = AcqInfo.SegmentCount;
transfer.StartSegment = 1;
transfer.Segment = 1;
transfer.Start = -AcqInfo.TriggerHoldoff;
transfer.Length = AcqInfo.SegmentSize;
MaskedMode = bitand(AcqInfo.Mode, 15);
ChannelSkip = AcqInfo.ChannelCount / MaskedMode;
data=zeros(transfer.Length,transfer.SegmentCount,AcqInfo.nChan);
if AcqInfo.isUsingHWAvg == false
if AcqInfo.nChan == 1
transfer.Channel = AcqInfo.isUsingChan;
else
transfer.Channel = 0;
end
[ret, data, dataInfo] = CsMl_TransferEx(DAQ, transfer);
CsMl_ErrorHandler(ret);
dataInfo.SegmentCount = transfer.SegmentCount;
dataInfo.Length = transfer.Length;
[retval, data] = CsMl_ExtractEx(DAQ, data, dataInfo, 0);
% data = squeeze(mean(double(data),2));
elseif AcqInfo.isUsingHWAvg == true
% % CsMl_TransferEx is not proved/provided for FPGA averaging
for iChan = 1:ChannelSkip:AcqInfo.nChan
if AcqInfo.nChan == 1
transfer.Channel = AcqInfo.isUsingChan;
else
transfer.Channel = iChan;
end
for jSegm = 1:AcqInfo.SegmentCount
transfer.Segment = jSegm;
[ret, data(:,jSegm,iChan), actual] = CsMl_Transfer(DAQ, transfer,1);
CsMl_ErrorHandler(ret);
data(:,jSegm,iChan) = (((AcqInfo.SampleOffset - double(data(:,jSegm,iChan)) / double(AcqInfo.nHWAvg)) / AcqInfo.SampleResolution) * (ChanInfo(iChan).InputRange / 2000)) + (ChanInfo(iChan).DcOffset / 1000);
% data = squeeze(mean(double(data),3));
end
end
end
if (AcqInfo.isAvg == true) && (AcqInfo.nSWAvg > 1)
sAvg = mean(data,2);
elseif (AcqInfo.isAvg == false) || (AcqInfo.nSWAvg == 1)
sAvg = data;
end
end