Borrar filtros
Borrar filtros

Create a infinite while loop

3 visualizaciones (últimos 30 días)
Miguel Albuquerque
Miguel Albuquerque el 22 de Jun. de 2022
Comentada: dpb el 22 de Jun. de 2022
Hey guys thanks in advance.
I have a code that reads samples from a hardware receiver. I want that the hardware keeps receiving until I press ctrl+c.But I need to write to a .txt file the samples and the time it ocurred. Is it better to do it after the while loop as I have or in between?
So the code I have, it starts the hardware to start receiving, then records the date time and between the while loop is the samples receiving.
% Start the module
fprintf('Start of LimeSDR\n');
start_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');
while true
% Receive samples on RX1 channel
indRx1 = 1; % index of the last received sample
[samples1, ~, samplesLength1] = dev.receive(Fs*Ts,1);
bufferRx1(indRx1:indRx1+samplesLength1-1) = samples1;
% Cleanup and shutdown by stopping the RX stream and having MATLAB delete the handle object.
stop_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');
clear dev;
fprintf('Stop of LimeSDR\n');

Respuesta aceptada

dpb el 22 de Jun. de 2022
Editada: dpb el 22 de Jun. de 2022
As is, it would be better to open the file first and write each record; the line
bufferRx1(indRx1:indRx1+samplesLength1-1) = samples1;
where bufferRx1 has not been preallocated will cause memory reallocation to augment its size on every pass through the loop. This won't be terribly noticeable for a short time frame if the amount of data isn't very large, but will begin to noticeably impact time as the acquisition proceeds.
  2 comentarios
Miguel Albuquerque
Miguel Albuquerque el 22 de Jun. de 2022
Thanks, I understand what you said, but what should I change in the code?
dpb el 22 de Jun. de 2022
'Pends on the form of the data -- it would be best to use lower-level i/o functions for a continuous acquistion instead of the overhead of the higher-level routines that open/close the file on every write -- that also has a lot of overhead associated with it.
But, we don't know the form of the data in either type nor number of samples/channels/etc.... to be able to write precise code.
Your buffer is just appending onto the end of what appears to be a vector; if so, then probably the lowest overhead option would be to insert an fopen first to a file for write before starting the device/acquisition, then read the start time and begin the acquisition. If you don't have some other restriction on the file having to be human-readable, then unformatted ("binary') output with frwrte iwould be fastest for recording the data; you can then post-process that file to create the time table for convenience.

Iniciar sesión para comentar.

Más respuestas (0)


Más información sobre Logical 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