How can I collect the real-time signals and process the collected signals at the same time?
2 views (last 30 days)
Show older comments
Dear all,
I am trying to collect the time series signals from the daq device. In the meantime, I also want to periodically process the snapshot signals extracted from the collected signals for analysis.
What I have done is to use parallel computing toolbox and DSP System Toolbox to achieve this function.
- First, I used one worker to collect the real-time signals and store them in the buffer (achieved).
- Second, I plan to use another worker to periodically extract snapshot signals from the buffer for analysing (not achieved).
Part of my code is as follows:
spmd
switch spmdIndex
%%
% -------------------------------------------------------------------
% Workers 1 Save the data from buffer
% -------------------------------------------------------------------
case 1
%% Create DataAcquisition Object
%Create a DataAcquisition object for the specified vendor.
d = daq("ni");
%% Set DataAcquisition Rate
% Set scan rate.
d.Rate = sampleRate;
%% Add Channels
%Add channels and set channel properties, if any.
addinput(d,"cDAQ1Mod1","ai0","Voltage");
addinput(d,"cDAQ1Mod1","ai1","Voltage");
addinput(d,"cDAQ1Mod1","ai2","Voltage");
%% write into buffer
dataBuff = dsp.AsyncBuffer(sampleRate*60) ;
for i = 1:5
n = ceil(d.Rate);
data = read(d,n);
dToB = [data.cDAQ1Mod1_ai0 data.cDAQ1Mod1_ai1 data.cDAQ1Mod1_ai2];
write(dataBuff, dToB); %write into buffer
end
dToP = read(dataBuff,i*sampleRate);
send(rQ, dToP) %send raw data to queue
%% Data processing
% -------------------------------------------------------------------
% Workers 2 Processes the data
% -------------------------------------------------------------------
case 2
pause(10)
end
end
I would like to ask if you have a way to use Worker 2 to extract the signal from the buffer, and Worker 2 should not suspend the data collection from Worker 1?
1 Comment
Alvaro
on 27 Dec 2022
I am not too familiar with the DSP toolbox but I believe that you are looking for smpdSend and spmdReceive.
Answers (0)
See Also
Categories
Find more on Spectral Analysis 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!