How can I read IMU and Microphone data from two different USB ports on my laptop simultaneously?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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.
Kindly read more about it here: Run function on parallel pool worker - MATLAB parfeval (mathworks.com)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!