Interface microphones using matlab

I have three microphones and i want to record the signals from the microphones simultaneously, is it possible in matlab?
i used the below mentioned program and i can acquire data from one microphone but im not able to get from all the three at the same time
clear all
close all
clc
AI = analoginput('winsound');
addchannel(AI, 1);
Fs = 8000;
set (AI, 'SampleRate', Fs)
duration = 20;
set(AI, 'SamplesPerTrigger', duration*Fs);
start(AI);
data = getdata(AI);
delete(AI)

10 Comments

Can you use multiple addchannel() for the additional microphones ?
im found from a website that 2 microphones can be interfaces and data can be collected using addchannel(AI,2), i tried it but it does not work too, i think it is because of sound card problem in my computer. but i have not tried what you said, thanks for you comment i will try it and let you know whether it works or not.
I assume you have at least 3 input channels on your sound card! Is there more than one sound card in your system? You may need to specify which one you want in your call to analoginput(). Also, I thought the addchannel() call took zero-based hardware indices, so maybe you want channels 0, 1 and 2. Have you tried adding them all at once?
addchannel(AI, [0 1 2]);
or addchannel(AI, [1 2 3]);
in windows 7 only one microphone is enabled and the others are disabled automatically, when i connect one microphone at the jack behind the CPU and the other in front only the jack behind is enabled, i can get data from the jack behind but not from the front, i have not tried the 3rd microphone yet, i tried addchannel(AI, [0 1 ]); and it shows the index should be minimum one and i tried addchannel(AI, [1 2]); and still get the same output
Is this a theoretical question or do you have actual microphones/soundcards. If it is not theoretical, are you willing to change your computer OS and the microphones/soundcards? If you are not willing to change, what OS and microphones/soundcards are you using. Can you record from each microphone individually?
I suspect the dual jacks are for convenience and are both leading to the same sound card.
Mr.Daniel-I have the microphones but im trying to use the sound card built in the pc,The OS im using is windows 7, today i tried to interface the microphones to the PC using USB mic jack, until today only one jack (either front or back jack) was detected but today both the USB and the back jack is detected,but still when i use the same program i get same data from both the microphones(there is no different values)
Mr.Walter Roberson- even i suspect the same, is there any other way to over come this draw back? i want to connect 3 microphones and collect data simultaneously using Matlab,but initially im trying two microphones
I think the data which comes into the matlab workspace is only from the default device,
i used the following code but still not able to interface
AI = analoginput('winsound',0);
AI1 = analoginput('winsound',1);
addchannel(AI,1);
addchannel(AI1,1);
Fs = 8000;
set (AI, 'SampleRate', Fs)
set (AI1, 'SampleRate', Fs)
duration = 20;
set(AI1, 'SamplesPerTrigger', duration*Fs);
set(AI, 'SamplesPerTrigger', duration*Fs);
start(AI1);
start(AI);
data = getdata(AI,AI1);
plot(data,'DisplayName','data','YDataSource','data');figure(gcf)
delete(AI1)
delete(AI)

Sign in to comment.

 Accepted Answer

Sorry mate, it looks like you are expecting the two-channel mic jack on your sound card to have three inputs.
Go and buy yourself a USB sound interface with 4 mic preamps.
The Alesis iO4 or Tascam US-600 are among the cheapest devices out there. Bonus is they will take a 5mm jack on all channels, since I assume you are not using professional microphones.
As for using only two microphones on one sound card, yes you should be able to do this. But you need to make a stereo splitter cable (or there may be something at your local electronics shop) which turns a single male stereo 3.5mm male jack into two mono 3.5mm female sockets (corresponding to left and right).
Plug that into your computer, and a mic into each of the sockets on the splitter. Then you should be able to at least record two mono channels (assuming that the mic input is stereo). You will, however, not have individual gain control on the two mics.
If you really do have more than one device, then you should be able to choose that device with your initial call to analoginput:
doc analoginput
It might not be 'winsound', and if it is, try the second parameter which selects the hardware ID.
Also, if you are using 64-bit MatLab, you need to read the documentation, which states that you can't use the analoginput interface.

5 Comments

Is it possible to add two USB sound cards (winsound1(Pc sound card), winsound 2(USB) and windsound3(USB)) and collect data from the microphones?? im using simple microphones?
As described in one of your other questions, you will have difficulty synchronizing sampling from different USB devices.
is it possible using a NI DAQ?
If you have a multi-channel NI DAQ, then Yes, the inputs could be synchronized.
Over the years I came across the fact that the standard Windows drivers for audio are two channels at most, so even if you could get a third channel in physically, that the drivers would not deal with it. The workaround involved using ASIO drivers (I am sure of this), and I cannot quite recall for sure whether using PortAudio drivers would work but I think so. Or use the data acquisition toolbox to talk to a multichannel A/D card.

Sign in to comment.

More Answers (1)

Goz Qht
Goz Qht on 26 Feb 2020
clear all close all clc AI = analoginput('winsound'); addchannel(AI, 1); Fs = 8000; set (AI, 'SampleRate', Fs) duration = 20; set(AI, 'SamplesPerTrigger', duration*Fs); start(AI); data = getdata(AI); delete(AI)

Categories

Find more on Audio I/O and Waveform Generation 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!