Displaying real time data is not efficient. Am I doing something wrong or is it app designer that is slow?

Hi,
I'm building a real time GUI in app designer to display 768 double pixel values from the thermal camera through serial communication at a frame rate of 16Hz. I am using the CData to update the image everytime instead of calling the imagesc in every loop, but this responds well only in 8hz not more than that and sometimes it hangs even at 8hz. Further more in the program I'm also saving the read data in the .csv file (inclusion or deleting of which doesn't cause any difference in the speed of the program) before going to the display part. What is that I'm doing wrong here? Or is there any alternative way which does this more efficiently. Thanks for your time and patience in advance.
Below is the code that I'm making use of.
properties (Access = private)
filename='C:\Users\kmana\Desktop\Matlab\Serial_Read.csv';
fileID ;
pixData=zeros(1,768);%store every pixel data
mPktCnt =0;
imData=zeros(24,32); %matrix to store whole image data
end
function startupFcn(app)
I= imagesc(app.imData,'Parent',app.UIAxes);
colormap(app.UIAxes,jet(256));
% colorbar(app.UIAxes);
delete(instrfindall); %pre-emptively close all ports
s1 = serial('COM8'); %define serial port to read the Arduino
s1.BaudRate=115200; %define baud rate
s1.InputBufferSize=2^21; % increase the buffer size
s1.Terminator = 'CR'; % set the terminator to that on arduino
fopen(s1);
s1.ReadAsyncMode = 'continuous';
app.fileID = fopen(app.filename,'w'); % open csv file to store the data
while(s1.BytesAvailable <= 0) %wait until Arduino outputs data
end
while(1)
sSerialData = fscanf(s1);
temp = strsplit(sSerialData,',');
% reading the pixel data converting it into double and storing it in the pixData array and then in the csv file
for j=1:768
app.pixData(j) = str2double(temp(j));
fprintf(app.fileID, '%2.2f,', app.pixData(j));
end
fprintf(app.fileID, '\n');
% app.mPktCnt= app.mPktCnt+1;
% app.mPktCnt
% converting pixData array into 24X32 matrix which is stored in imData
for k=1:24
for l=1:32
app.imData(k,l)=app.pixData(((k-1)*32)+l);
end
end
% use this imData to update the CData of imagesc.
I.CData(:)= app.imData(:);
pause(0.001);
%drawnow;
end

8 Comments

It is more efficient to sscanf all of sSerialData at one time than to str2double() one item at a time from it.
Try uncommenting the drawnow so that it updates at each iteration, if that's what you want. Otherwise it might only update whenever it thinks it has enough time to do it.
Dear Walter, you have been my saviour since the day I sarted working on Matlab. I knew sscanf was more efficient and even tried implementing it earlier in normal matlab program but somehow I had not succeeded to use it and when I shifted to app designer I totally forgot that might have been an issue here. Thank you for pointing it out to me!
Dear image Analyst, I have commented drawnow because it slows down the interface even drawnow limitrate that's why I shifted to pause(0.001) but do you think it produces wrong results?
I have a new problem now. At 16Hz the code works perfectly fine but it works for ony 5 minutes and starts causing the delay again.
for k=1:24
for l=1:32
app.imData(k,l)=app.pixData(((k-1)*32)+l);
end
end
Try replacing this with reshape, possibly with a transpose as well.
Have you used the Profiler to determine what part of this code is the bottleneck? Is it displaying the image on the screen or the disk access?
Dear Steven, pause(0.001) consumes most of the time when I replace it with drawnow it is even worst. pause.PNG

Sign in to comment.

Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Asked:

on 25 Nov 2018

Commented:

on 26 Nov 2018

Community Treasure Hunt

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

Start Hunting!