Log file Plot using Matlab in Realtime

6 visualizaciones (últimos 30 días)
TAPAN PATEL
TAPAN PATEL el 7 de Oct. de 2019
Comentada: TAPAN PATEL el 8 de Oct. de 2019
Software generates log files contains complex values, a 16-bit real integer and a 16-bit imaginary integer which is shown in text file starting from line 13.
Before line 13 general information which is not needed.
How can I get that data in to matlab and plot in real time?
I can not attach log file so I converted and attached it into *.txt file
  1 comentario
TAPAN PATEL
TAPAN PATEL el 8 de Oct. de 2019
thank you so much and now this is how my code looks like:
fid = fopen('20191008-155724_DecaWaveAllAccum.log');
S = [ ];
Count = 0;
while ~feof(fid)
tline = fgetl(fid);
if contains (tline,'Accum Len')
Count = Count + 1;
s = textscan(fid,'%d16 %d16',1016,'Delimiter',',');
real = s{1};
Img = s{2};
ss = cell2mat(s);
sss = double(ss);
S = [S;sss];
end
end
fclose(fid);
with updating log file my count is not updating automatically. I need to run the code again in order to update the count. But I need it to be in REALTIME. Is there any other way to do this?

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 7 de Oct. de 2019
You will need to fopen() the file for reading.
Start an indefinite loop to read blocks
WIth the indefinite loop, start a second oop using fgetl() and looking for lines that start with 'Accum Len'. If the line does not start with that, loop back to fgetl(). If the line does start with it, then parse the line to get the number; that will be the number of samples to read.
Now use textscan() with appropriate format and delimiter ',' . Right after the format parameter, pass in the number of samples (e.g., 1016). cell2mat() the textscan results, and proceed to plot or store the information .
After that you loop back in the indefinite loop to read more blocks -- you would be back to the mode of skipping lines until you get to Accum Len.
  3 comentarios
Walter Roberson
Walter Roberson el 7 de Oct. de 2019
You mention that you want to do this in "Real Time". Is it correct that some other program will be writing more data to the end of the file while the MATLAB program is running to plot the data? If so then there are complications around reaching the end of file; unless there is some kind of protocol to signal between the two processes, at any one time that the MATLAB routine goes to look at the file, the other routine might be in the middle of reading the file. If you are using MS Windows that potentially mandatory locking could cause problems too.
TAPAN PATEL
TAPAN PATEL el 8 de Oct. de 2019
Hello Walter Roberson,
firstly, many thanks your reply.
So in detail: The log file is continuously updating by one software in MS windows platform (which is getting data via USB port from and CIRCUIT board connected to it). This data comming from USB port is accordingly procressed by PC software and log file is created and getting updated unless user select the stop button.
After log file started getting data, I should start MATLAB program manually to fetch data from it. I understand I need some protocole that control speed of MATLAB program that does not overtake the speed of updating log file. Is there any other way to do this?
and about 'mandatory file locking', for that I simply tried below code while log file was in updaing mode and it succefully fetch first 1016 data.
fid = fopen('filename.log');
s = textscan(fid,'%d16 %d16','Delimiter',',','headerlines',12);
fclose(fid);
and I have as result :
s =
1×2 cell array
{1016×1 int16} {1016×1 int16}
Regards,
Tapan Patel

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by