Borrar filtros
Borrar filtros

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

4 visualizaciones (últimos 30 días)
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 ---');

Respuestas (1)

Ayush
Ayush el 19 de Jun. de 2023
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.

Categorías

Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by