How can I read IMU and Microphone data from two different USB ports on my laptop simultaneously?

조회 수: 3 (최근 30일)
Here is my setup:
  1. I have an IMU sensor connected to my laptop over USB
  2. I have a 2-channel MEMS microphone connected to another USB port on my laptop. (I am using a MEMS microphone to USB audio interface)
I would like to record data from the IMU and the microphones simultaneously. I am able to properly record data individually from the IMU using serialport() and microphone using audioDeviceReader().
However, when I try to do them both together i.e. by using both the commands inside a while loop as shown below, the recorded data is not clean. For instance, I can hear audio artifacts in the microphone recording.
Essentially, I am asking if there is a way to parallelize this process so that the IMU and mics can be recorded simultaneously. Is there a way to leverage the Parallel Computing Toolbox for this purpose?
Code for what I am trying to do:
% Create serial port object for IMU
srl = serialport("/dev/cu.usbmodemcf3fb1281", 9600);
% Create serial port object for Audio
adr = audioDeviceReader('Device', 'MCHStreamer PDM16', ...
'SampleRate', 16000, ...
'SamplesPerFrame', 32, ...
'NumChannels', 2);
setup(adr);
afw = dsp.AudioFileWriter("audio.wav", 'FileFormat', 'WAV', 'SampleRate', 16000);
%% Log Data
disp('--- Start Logging ---');
tic;
while toc <= logTime
% Audio
audiodata = adr();
afw(audiodata);
% IMU
imudata = readline(srl);
writelines(imudata, "imu.txt", WriteMode="append");
end
disp('--- End Logging ---');

답변 (1개)

Ayush
Ayush 2023년 6월 19일
You can use the parfeval function that is available in Parallel Computing Toolbox. This function can be used to perform asynchronous computations and return the results once the computation is complete.

카테고리

Help CenterFile Exchange에서 Multichannel Audio Input and Output에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by