Performing TDOA on Arduino Mega with 4 INMP441 for sound source localization

Hi, I want to make a sound source localization module using TDOA/FDOA/Phase difference method/intensity of sound method. The 4 microphones are arranged in a square pattern and my aim is to find 3d co-ordinate position of the source (moving) wrt the center of the arrangement.

**The out come is further used in a different project for pointing the camera in the direction of the sound source

I have an arduino mega board and 4 INMP441 microphone modules (not Invensense, refer the link)

Well, I guess, your going to have to reconcile the relatively slow ADC in the baseline arduinos,@# well,as the ~4uS timing resolution in micros() results.

You can do a lot in that time, but need to closely watch your code structure and timing to avoid any wasted clock cycles.

INMP441 module gives a digital output which rules out the effect of ADC in the Mega board, the timing of ~4us is the main issue I am concerned with but considering my application is for personal use I am slacking on that for now.

Since, this is my first time using a mega board, I also need help with connections for the microphones and mega board. I have used uno earlier but only for simple projects like line following rc vehicles, and controlling motors only.

A while back I did some experiments on this concept. My setup was an STM32 "Blue Pill" board with four analog microphone modules. The ADC on that microcontroller has a cyclical free run mode, that is, it would sequentially sample each of the four channels and repeat with the only intervention from the CPU being to retrieve the data as it became available. The point is that the relative time relationship between samples across channels was fixed and known. To the extent I pursued this project (thus far) I streamed data off the microcontroller to a PC for processing. I got as far as "proving" 2D angle of arrival measurements were viable.

It's not clear to me how synchronization of sample time across the four channels works with an I2S digital microphone, but you will need to know the relationship of the "time of sample" across the four channels to do any sort of TDOA/FDOA/Interferometry sort of math on the back end.

In any case, welcome to the forum and I look forward to any progress updates you can make.

What is your plan to read four I2S signals, and account for the various time delays to read in each data point?

Arduino Mega is not the right tool for such task, it neither has interfaces nor processing power, and it's short on ram for such problem. The simplest way would be to use stm32 with 2 hardware I2S (L and R channels for two mics on each) - then if you take stm32x4 or x7 series, you may even have some reasonable MCU time available to make on-board analysis.
Having said that, it's quite complicated project with many challenges. If you don't have years of experience in the area - then you might need quite a few months to get there

I have an STM32F103C8T6 module from a previous project not being used, I can switch to that. But the microphones I have are digital, I'll have to figure out on that.

Can you please, provide a link to your project? It would be of great help

I agree on the suggestion but STM32x4 and X7 series is very hard to get hands on in Indian markets. Either the international shipping costs will be equal or more than the product price or it takes weeks or months for a local dealer to get one for me.

And again Indian knockoffs and look alikes are hard to differentiate to get a genuine product.

The good news is that I still have the STM32F103C8T6 side code.
The bad news is that it was written in Forth:

                   4 constant #adcs
                $400 constant #asamples
#adcs #asamples * 2* constant #abytes
                  10 constant arate-us
       arate-us 72 * constant arate-clk

             #abytes buffer:  adata

: adc1-dma ( addr count pin rate -- )  \ continuous DMA-based conversion
  3 timer-init        \ set the ADC trigger rate using timer 3
  adc-init  adc drop  \ perform one conversion to set up the ADC
  2dup 0 fill         \ clear sampling buffer

  0 bit ADC1-CR2 bic!	\ clear ADON (stop ADC1)

    0 bit RCC-AHBENR bis!  \ DMA1EN clock enable
      2/ DMA1-CNDTR1 !     \ 2-byte entries
          DMA1-CMAR1 !     \ write to address passed as input
  ADC1-DR DMA1-CPAR1 !     \ read from ADC1

  0 bit DMA1-CCR1 bic!	\ clear EN (stop DMA1)

                0   \ register settings for CCR1 of DMA1:
  %01 10 lshift or  \ MSIZE = 16-bits
   %01 8 lshift or  \ PSIZE = 16 bits
          7 bit or  \ MINC
                   \ CIRC
                    \ DIR = from peripheral to mem
          0 bit or  \ EN
      DMA1-CCR1 !

                 0   \ ADC1 triggers on timer 3 and feeds DMA1:
          23 bit or  \ TSVREFE
          20 bit or  \ EXTTRIG
  %100 17 lshift or  \ timer 3 TRGO event
           8 bit or  \ DMA
                     \ ADON
        ADC1-CR2 ! ;

: quad-adc ( -- ) \ configure ADC and DMA for quad-channel continuous sampling 
  adc-init 6 us adc-calib
  adata #abytes pa0 arate-clk adc1-dma
  pa0 adc# 		\ channel 0
  pa1 adc#  5 lshift or \ channel 1 
  pa2 adc# 10 lshift or	\ channel 2
  pa3 adc# 15 lshift or	\ channel 3 
  ADC1-SQR3 ! 		\ set up the ADC scan channels 
  3 20 lshift ADC1-SQR1 ! \ four scan channels 
  8 bit ADC1-CR1 bis! 	\ enable SCAN mode 
;

: dump-adata ( -- )	\ Dump adata buffer with 4 channels
  cr
  #asamples 0 do
    #adcs 0 do
      adata i 2* + j #adcs * 2* + h@ . 
    loop
    cr 2 ms
  loop ;

: snapShotDMA ( -- )
  quad-adc  
  0 bit ADC1-CR2 bis! 
\  DMA1-ISR cr .
  \ 1000 ms
  #adcs #asamples * arate-us * 1000 / ms
\  DMA1-ISR cr .
  0 bit ADC1-CR2 bic!  
  0 bit DMA1-CCR1 bic!  
  $0FFFFFFF DMA1-IFCR !  
;

Improvent in the project:

I am now succesfully able to locate the sound source using TDOA and then trilateration to get the 3d co-ordinates of the source wrt center of the arrangement.

Outcome: Output is at 1s delay wrt to the movement of the source. Sufficient enough for my application of mapping the path of sound source and tracking it on the video
Setup: Arduino mega, Omni directional Digital MEMS microphones ( 4 X INMP441 microphones)
Calculation methods: RMS of location from Intensity of sound method and phase difference method.
Additional tips: TDOA requires a bit more of setup (better microcontroller and analog mics + ADC) and not feasible for indoor environment, FDOA has a lot of frequency variations due to echoing but possible for out door environment

Are you able to share the code/math to do this? I'd love to be able to put in 4 time stamps to represent the 4 microphones and see the 3d position.

I know the regular Arduino would struggle getting accurate timestamps, but I can still learn from the math.

Thanks!