Looking Assistance for Data Acquisition and Parallel Processing with USRP B200 in MATLAB
이전 댓글 표시
Hello dear MATLAB Community,
I am looking for a solution to receive and save data from the USRP B200 using the USRP Communicatios Toolbox and Parallel Computing Toolbox. When I try to save data using a parallel pool, I experience a delay of 2-3 seconds, during which I believe some samples are lost.
I am seeking a solution that allows my program to continuously receive data and, after a certain number of samples or a specific time period, save it using a parallel process.
Below is a part of my code. My system specifications include an 8-core CPU, 32 GB of RAM, and the latest version of MATLAB R2023a.
Thank you very much!
%% Create a parallel pool
poolobj = gcp('nocreate'); % If no pool, do not create new one.
if isempty(poolobj)
poolobj = parpool(6); % Create a new pool
end
%% Data acquisition loop
data = complex(zeros(round(receiveSettings.samples_per_frame), round(calculatedParameters.corr_iterations)));
if hardware.radioFound
% Capture loop
for o_frame = 1 : calculatedParameters.capture_number
while i_frame < calculatedParameters.corr_iterations
[output, dataLen, overrun, timestamp] = radio();
% Overrun check
if overrun == 1
overrun_counter = overrun_counter + 1;
end
% Validate received data
if dataLen >= receiveSettings.samples_per_frame
step(scope, output); % Display frequency spectrum
data(:, i_frame) = output; % Save data from USRP
i_frame = i_frame + 1;
end
end
tic
f = parfeval(poolobj, @saveDataAsync, 0, data, calculatedParameters, recorderSettings, usrpSettings, o_frame); % call save fuction
toc
end
%% Function that handles the saving of data to a WAV file
function saveDataAsync(data, calculatedParameters, recorderSettings, usrpSettings, o_frame)
data = reshape(data, [], 1); % Reshape 'data' into a column vector
% Normalize IQ data
data_I = real(data) / max(abs(real(data)));
data_Q = imag(data) / max(abs(imag(data)));
data_cat = [data_I, data_Q];
% Prepare filename for WAV saving
wavefile_IQ = sprintf('%s_%dHz_MCR_%dHz_Cfr_%dDf_%d', char(recorderSettings.wav_time), usrpSettings.master_clock_rate, usrpSettings.center_frequency, usrpSettings.descimationfactor, o_frame);
folderPath = 'D:\test';
filePath = fullfile(folderPath, [wavefile_IQ, '.wav']);
wavwrite_personal_function(data_cat, calculatedParameters.sample_rate, recorderSettings.rcvr, recorderSettings.nbits, filePath);
disp('Audio file saved successfully.');
end
댓글 수: 4
Mario Malic
2023년 11월 17일
I don't know anything about your device, but are you sure parpool is necessary? This is what makes your execution slow.
Nik Rocky
2023년 11월 17일
Mario Malic
2023년 11월 18일
Can you get me the link for documentation on radio function?
Nik Rocky
2023년 11월 20일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Communications Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!