How can I read the most recent scans from a data acquisition object during continuous background recording?
Show older comments
I’m recording voltage from microphones continuously in the background using an NI PXIe-1085 chassis and PXIe-4464 acquisition cards while changing the frequency, relative amplitude, and relative phase of voltages that are driving an array of loudspeakers. These drive voltages are also running continuously from a separate waveform generator (not part of the NI chassis).
In my code example below, I read "X" milliseconds of scans once during each frequency/amplitude/phase combination. The first read command reads the first acquired scan and each subsequent read command picks up with the scan where the previous left off, no matter how long the processing portion of the code takes. Instead, I’d like each read command to read the most recent “X” milliseconds of scans from the data acquisition object. How can I do that?
% Drive parameters
freq = 100:10:1000; % frequencies
dAmp = 0.1:0.1:1; % relative amplitudes
dPhase = 0:1:180; % relative phases
arb_volts = 0.5; % maxmum drive voltage
% Receive parameters
setting_time = 0.2; % seconds
num_cyc = 20; % number of cycles of the waveform to record
% setup arbitrary function generator and return instrument control object
arb = arbInitialize(arb_volts);
% Setup NI chassis and start acquiring data in the background
d = daq("ni");
ai0 = addinput(d, "PXI1Slot3", "ai0","Voltage");
% ai1 = addinput(...
% etc. for more channels
d.Rate = 200000;
% Start background acquisition
start(d, "continuous")
pause(0.1)
% loop over drive frequencies
for f = length(freq):-1:1
arbSetFreq(arb, freq(f))
record_duration = num_cyc / freq(f); % seconds
% loop over relative amplitudes and phases
for dA = 1:length(dAmp)
for dP = 1:length(dPhase)
arbSetAmpAndPhase(arb, arb_volts, dAmp(dA), dPhase(dP))
% measure voltages from microphones
pause(config.settling_time + record_duration)
data = read(d, seconds(record_duration));
% do some processing
% store outputs
end
% do some processing
end
% do some processing
end
% Write outputs
Accepted Answer
More Answers (0)
Categories
Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!