Create a infinite while loop

5 ビュー (過去 30 日間)
Miguel Albuquerque
Miguel Albuquerque 2022 年 6 月 22 日
コメント済み: dpb 2022 年 6 月 22 日
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
dev.start();
fprintf('Start of LimeSDR\n');
tic;
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;
end
% Cleanup and shutdown by stopping the RX stream and having MATLAB delete the handle object.
dev.stop();
tempo_rececao=toc;
stop_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');
clear dev;
fprintf('Stop of LimeSDR\n');
TT=array2timetable(samples1,'SampleRate',Fs,'StartTime',start_time);
writetimetable(TT,'Timetable_Rx1.txt','Delimiter','bar');

採用された回答

dpb
dpb 2022 年 6 月 22 日
編集済み: dpb 2022 年 6 月 22 日
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 件のコメント
Miguel Albuquerque
Miguel Albuquerque 2022 年 6 月 22 日
Thanks, I understand what you said, but what should I change in the code?
dpb
dpb 2022 年 6 月 22 日
'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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by