How to run two dependent function simultaneously?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi!
I'm currently trying to solve this problem. A would like to simulate a real time biomedical signal acquisition and make some elaborations on that signal.
In order to do that, I'm using the timer function to feed a biomedical signal (arterial blood pressure previously saved in a my workspace) with a 50Hz frequency.
I can plot that signal as it seems generated in real time.
I would also like to make some elaboration on 60 seconds segments of that signal. It means that I acquire 60 sec of signals, save them in a buffer, and then make the desired elaboration.
The problem is that the elaboration takes more than 1/50 seconds. So I would like to run the elaboration in parallel with data "acquisition". Is there a way to do that?
In other words, I would like to keep acquiring the signal at 50Hz, save 60 seconds of signal in a buffer and then elaborate that buffer, without interrupting signal "acquisition" and visualization.
I will post a segment of explanatory code:
function []=realTimeNew(abp,cbfv)
%%Initialization
persistent buffer;
samplFreq=50;
buffer=60;
%%Create Figure
hFigure=figure(1);
TimerData=timer('TimerFcn', {@realTimeMachine,abp,cbfv},'Period',1/samplFreq,'ExecutionMode','fixedRate','BusyMode','queue','TasksToExecute',length(abp));
start(TimerData);
uiwait(hFigure);
stop(TimerData);
function realTimeMachine(obj, event,abp,cbfv)
persistent handlesPlot;
persistent handlesAx;
persistent sample;
% define costants
displayTime=5;
if isempty(handlesPlot),
sample=1;
handlesAx=subplot(2,1,1);
subplot(2,1,1);
handlesPlot=plot(abp(1));
sample=sample+1;
else
OldValues=get(handlesPlot,'YData');
set(handlesPlot,'YData',[OldValues abp(sample)]);
XLimitations=get(handlesAx,'XLim');
if XLimitations(2)> samplFreq*displayTime,
set(handlesAx,'XLim',[XLimitations(2)-samplFreq*displayTime sample]);
end
if rem(sample,buffer*samplFreq)==0,
% elaboration in progress every 60 seconds
elaboration();
end
sample=sample+1;
end
end
function []=elaboration()
pause(1);
end
0 Commenti
Risposte (1)
Hugo
il 19 Giu 2013
Dear Andrea,
you might consider to check the post in
http://www.mathworks.com/matlabcentral/answers/2081-how-to-execute-two-matlab-scripts-simultaneously
There, they suggest using two matlab sessions, and let the scripts talk to each other if necessary (they explain how).
Good luck. Hugo
0 Commenti
Vedere anche
Categorie
Scopri di più su Digital Input and Output in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!