Main Content

线性麦克风阵列的到达估计的实时估计

此示例显示了如何获取和处理实时多通道音频。它还提出了一种简单的算法,用于使用线性阵列中的多个麦克风对估算声源的到达方向(DOA)。

选择并配置音频样本的来源

如果可用多通道输入音频接口,请修改此脚本以设置Sourcechoice'居住'。在此模式下,该示例使用实时音频输入信号。该示例假设所有输入(两个或更多)是由排列在线性阵列上的麦克风驱动的。如果没有麦克风阵列或多通道音频卡,请设置Sourcechoice'recorded'。In this mode the example uses prerecorded audio samples acquired with a linear array. ForSourcechoice= 'live',以下代码使用audioDeviceReader通过Microsoft®Kinect™为Windows®获取4个实时音频频道。要使用另一个麦克风阵列设置,请确保已安装的音频设备驱动程序是MATLAB®支持的常规类型之一,并设置金宝appDevice财产的audioDeviceReaderaccordingly. You can query validDevice通过调用计算机的作业getAudioDevicesobject function ofaudioDeviceReader。请注意,即使使用Microsoft Kinect,设备名称也可以在机器上有所不同,并且可能与此示例中使用的名称不同。使用选项卡完成以获取计算机上的正确名称。

Sourcechoice='recorded';

设置现场处理的持续时间。设置每个频道多少样本以获取和处理每次迭代。

末日= 20;AudioFrameLength = 3200;

创建源。

switchSourcechoicecase'居住'fs = 16000; audioInput = audioDeviceReader(...'Device',,,,'Microphone Array (Microsoft Kinect USB Audio)',,,,...'采样率',,,,fs,...'NumChannels',,,,4,...'OutputDataType',,,,'double',,,,...“SamplesPerFrame”,AudiooFrameLength);case'recorded'% This audio file holds a 20-second recording of 4 raw audio用Microsoft Kinect(TM)获取Windows(R)的%频道% the presence of a noisy source moving in front of the array% roughly from -40 to about +40 degrees and then back to the% 初始位置。audioFileName ='AudioArray-16-16-4channels-20secs.wav';AudioInput = dsp.audiofilereader(...'OutputDataType',,,,'double',,,,...'文件名',,,,audioFileName,...'播放计数',inf,...“SamplesPerFrame”,AudiooFrameLength);FS = AudioInput.smplater;结尾

Define Array Geometry

The following values identify the approximate linear coordinates of the 4 built-in microphones of the Microsoft Kinect™ relative to the position of the RGB camera (not used in this example). For 3D coordinates use [[x1;y1;z1], [x2;y2;z2], ..., [xN;yN;zN]]

micPositions = [-0.088, 0.042, 0.078, 0.11];

Form Microphone Pairs

此示例中使用的算法可独立使用成对的麦克风。然后,它结合了单个DOA估计值,以提供单个实时DOA输出。可用的对越多,DOA的估计值越强(但计算昂贵)。可用的最大对数可以计算为nchoosek(length(micPositions),2)。在这种情况下,选择了最大的毛间间距离的3对。麦芽管间距离越大,DOA估计值越敏感。以下矩阵的每一列描述了阵列中麦克风对的选择。所有值必须是1和1之间的整数length(micPositions)

micPairs = [1 4; 1 3; 1 2]; numPairs = size(micPairs, 1);

初始化DOA可视化

创建一个辅助绘图对象doadisplay的实例。这显示了估计的DOA活在极地上的箭头。

DOAPointer = DOADisplay();

Create and Configure the Algorithmic Building Blocks

根据如何选择麦克风对的方式,使用辅助对象重新排列输入样品。

bufferLength = 64; preprocessor = PairArrayPreprocessor(...``micpositi'',麦片,...'MicPairs',麦片,...'BufferLength',,,,bufferLength); micSeparations = getPairSeparations(preprocessor);

The main algorithmic building block of this example is a cross-correlator. That is used in conjunction with an interpolator to ensure a finer DOA resolution. In this simple case it is sufficient to use the same two objects across the different pairs available. In general, however, different channels may need to independently save their internal states and hence to be handled by separate objects.

室间因子= 8;b = interpactor*fir1((2*interpactor*8-1),1/interpactor);groupDelay =中值(grpdelay(b));Interpolator = DSP.FirinterPolator('InterpolationFactor',,,,interpFactor,'分子',,,,b);

在循环中获取和处理信号

For each iteration of the following while loop: read有声明samples for each audio channel, process the data to estimate a DOA value and display the result on a bespoke arrow-based polar visualization.

抽动为了idx = 1 :(末端*fs/audioframeLength)cyclestart = toc;% Read a multichannel frame from the audio source% The returned array is of size AudioFrameLength x size(micPositions,2)multichannelAudioFrame = audioInput();% Rearrange the acquired sample in 4-D array of size% bufferLength x numBuffers x 2 x numPairs where 2 is the number of% channels per microphone pairbufferedFrame = preprocessor(multichannelAudioFrame);%首先,估算每对的DOA,独立%初始化可用对的阵列Numbuffers = size(BufferedFrame,2);延迟=零(1,numpairs);anglesinradians =零(1,numpairs);XCDense = ZEROS((2*BufferLength-1)*Interpactor,numpairs);% Loop through available pairs为了kpair = 1:numpairs% Estimate inter-microphone delay for each 2-channel bufferdelayVector = zeros(numBuffers, 1);为了kbuffer = 1:麻木%交叉折叠对频道以获得粗糙的通道百分比互相关xccoarse = xcorr(...BufferedFrame(:,Kbuffer,1,Kpair),...bufferedFrame(:,kBuffer,2,kPair));%插值以增加空间分辨率XCDENSE = interpolator(flipud(xccoaress));%提取的位置maximum, equal to delay in sample time% units, including the group delay of the interpolation filter[~,idxloc] = max(xcDense); delayVector(kBuffer) =...(idxloc - groupDelay)/interpFactor - bufferLength;结尾%通过选择中位数来组合跨对的DOA估计delays(kPair) = median(delayVector);% Convert delay into angle using the microsoft pair spatial% separations providedAnglesinradians(kpair)= HelperDelayToangle(delays(kpair),FS,...micseparations(kpair));结尾% Combine DOA estimation across pairs by keeping only the median valueDOAInRadians = median(anglesInRadians);%箭头显示DOAPointer(DOAInRadians)%延迟周期执行如果使用记录的数据if(strcmp(Sourcechoice,'recorded')暂停(AudiooFrameLength/fs- TOC + Cyclestart)结尾结尾

release(audioInput)