How can I read IMU and Microphone data from two different USB ports on my laptop simultaneously?
3 views (last 30 days)
Show older comments
Here is my setup:
- I have an IMU sensor connected to my laptop over USB
- 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 ---');
0 Comments
Answers (1)
Ayush
on 19 Jun 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.
Kindly read more about it here: Run function on parallel pool worker - MATLAB parfeval (mathworks.com)
0 Comments
See Also
Categories
Find more on Multichannel Audio Input and Output in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!