Real-time data acquisition and data plot problem

7 visualizzazioni (ultimi 30 giorni)
I' ve been having problems to acquire data and plot it in real time. I' ve been able to plot a graph that has a moving x-axis with the help of function drawnow nd by translating the x-axis with the help of function xlim. Now I' ve been wondering if there is a way to read acquisited data one by one (bite per bite), and to plot it in real - time using the same method. Also I' m wondering if the same method could be aplied to generate a signal and send it to an analog output(example winsound), but to make it go outside bit by bite.
function pushbutton3_Callback(hObject, eventdata, handles)
handles.StopGenSignal = 0;
guidata(hObject,handles);
amp=str2double(get(handles.edit7,'String'));
frek=str2double(get(handles.edit6,'String'));
% ao=analogoutput('winsound');
% addchannel(ao,1);
% set(ao,'StandardSampleRates',8000);
% set(ao,'TriggerType','Immediate');
% set(ao,'SampleRate',2*8000);
h=animatedline;
xlabel('Vrijeme [sec]');
ylabel('Amplituda [V]');
title('Generisani signal');
%axis([0 3 -amp-1 amp+1]);
%set(gca,'XLim','auto','YLim',[-amp-1 amp+1]);
axis([0 3 -amp-1 amp+1]);
grid on;
t=0;
while handles.StopGenSignal==0
y=amp*sin(2*pi*frek*t);
%putdata(ao,y);
if(t>3)
axis([t-2.9 t+0.1 -amp-1 amp+1]);
end
addpoints(h,t,y);
drawnow
pause(0.01);
t=t+0.01;
handles = guidata(hObject);
end
function pushbutton5_Callback(hObject, eventdata, handles)
handles.StopGenSignal = 1;
guidata(hObject,handles);
The given code represents the generated signal, my question is whether there is a way to make an analogoutput object (or analog input) and to send data (or recieve) data bite per bite (with a refresh period) so that I can use the same metod as in the shown while loop to plot date in real time, and to send it to winsound (or mcc). Thanks in advance.

Risposte (1)

Benjamin Thompson
Benjamin Thompson il 14 Mar 2022
If the frequency of the signal is maybe 50 Hz or less it might look OK. Windows and Linux processes typically can only handle events every 10-15 ms. For higher sampling rates and more precise timing you need hardware that buffers data for receiving in Windows or for displaying.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by