'Real-time data acquisition and data plot problem in Matlab
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. The folowing is Matlab code used for gui.
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]);
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
