This question has to do with audio signalling between two web appliances (i.e. desktop to mobile, mobile to mobile, desktop to desktop) and sometimes the device is signaling itself.
I can currently do something similar to this using FFT analysis of the bin frequencies in an audio pulse. But I am looking now into using phase along with or as a replacement to frequency strength at the bin center.
I need to transmit and receive an open air multitone pulse of 50 sine waves spaced at the FFT bin centers of a 3 second audio pulse. On the receive side, 44.1 KHz sample rate with FFT size 32768 (16384 bins). Would be best if I could transmit the 50 tones in adjacent bins but I could space them in alternating bins.
In the pulse creation on the transmit side, I can shift the phase of each sine wave as I mix/create the pulse. What I would like to do is phase shift 20 of the sine waves in the pulse so that I can distinguish them from the other 30, not by their signal strength which can greatly vary in an open air transmission, but by their phase as compared to the other 30 bin pulses.
I could use say 51 tones where the first bin holds a marker tone such that the other 20 tones I want to identify all match the phase of the marker tone OR simply use 30 tones all with different phases to the 20 bins I want to identify (that have an identical or at least a predetermined identifiable phase).
So the bigger question is how easy/reliable is it to recover the phase of a sine wave at the center of an FFT bin given the real and imaginary components of a continuous 32768 microphone sample? And can I do it in Javascript as this will execute in a browser (mobile or desktop) using webRTC audio samples which are now available even on apple devices.
It appears that you can apply the javascript Math.atan2 to the (real,imag) output from the FFT to get phase but that is about all I know including how to interpret that into phase. Fortunately I am in control of both sender and receiver where short distance is fine and the burst can be at any base frequency under 21 Khz. Unfortunately this is open air and I know very little about how sideband and ambient noise in the transmitted band can affect phase.
Ultimately I want to determine which 20 of the 50 bins have a common dominant phase at the bin center.
Do I pulse only 20 sine frequencies on the transmit side at predetermined frequencies and phases for the bin centers I want to signal?
Do I use signal strength and phase to identify the 20 bins?
Do I space the signalling bins to avoid spectral leakage or is that less of an issue when determining phase at the bin center?
Do I use something other than FFT or in combination with windowing (and which window would work best.. manning, blackman, flat top???)?
And If I do use a window function, do I window the raw microphone sample before the FFT or after the FFT result (or does it even matter if phase at the bin center is the goal)?
Does it take two or more FFT samples to get phase or can it be done on a single 32768 sample?
FYI: It may not be 20 out of 50, I just used that as an example but it will always be N out of M where N and M are fixed values on each pulse and around half of M.