开发者

How to determine the magnitude of a frequency and the phase angle from an audio sample?

I'm currently working on this project that implies some DSP skills. I must extract the audio from a movie and then, by analyzing it, I must determine when someone speaks or not, more like an voice activity detector.

I'm writing the code in Java (yes, I know it's not the best choice) and only use a library to extract the audio from the video and JLayer so I can process an MP3.

My class that extracts the audio samples gets the samples consecutively for each channel, in my case two: LEFT0, RIGHT0, LEFT1, RIGHT1, LEFT2, RIGHT2, etc.

So this is what I've done so far:

  • I put the samples for each channel in an array.
  • I apply a Hamming window [N = 8192]:

    double 开发者_高级运维w = 0.54 - 0.46 * (Math.cos(2*Math.PI*buffer[i]/buffer.length-1)); fftBuffer[i] = new Complex(w, 0);

  • I then perform a simple FFT on each channel and then compute the magnitude mag = re^2 + im^2; after that, I do a log scale (dB): mag_dB = 10 * log10(abs(mag));

Because I am "looking for voice" here, I need frequencies between 80 and 1000 (even tough the voice ranges between 80 Hz and 255 Hz). So, from the FFT I get a mirrored N = 8129 array from witch I need only the first N/2.

The frequency per bin (slot in the array resulted from the FFT) would be the sample rate (48.000 kHz) / N; that would be 48000 / 8192 = 5 Hz per bin. So I only look in the array at the values from FFT_Result[15] to FFT_Result[199] (16 * 5Hz = 80 Hz; 200 * 5 = 1000 Hz) right?!

I took a look on the frequency analyzer in Cool Edit Pro and all the amplitudes are negative. In my case, the first ones (the sound is in the background and isn't loud) are negative, and after that, they are all positive. Aren't they supposed to be negative? Am I missing out something over here?

So far, based on what I've remarked by looking at the frequency analyzer and phase analyzer in Cool Edit Pro, I need a threshold on this frequency range, some kind of algorithm to determine over a period of n milliseconds if the magnitude is constant over that frequency range and determine if the sound is centered. The last one must be done (I think) analyzing the phase angle, when someone speaks, the sound is always centered.

I didn't manage to find a way to do that and I'm all confused with what I've done so far because I do not know if what I've done so far is right.

So, if you read all this, thank you for your patience and my questions are:

- have I done right what I've done so far?

- does the amplitude has to be negative?

- does anyone know how I can compute the phase for a number of samples?


In dB, the amplitude can be negative or positive, it doesn't matter. What matters, is the value relative to some threshold. I would base the threshold on surrounding samples. Because the energy in spoken words goes up and down as syllables are spoken, a simple average (multiplied by some arbitrary factor you'll have to play with to find what works well) would work fine as a threshold.

For phase in the time domain, you can first take a Hilbert transform, and then use atan2 on the real and imaginary parts of each sample to estimate instantaneous phase.


Instead of looking at the phase of the individual channels, you could check the delay between both channels. Assuming that the same signal is presented to both channels, the direction of the sound source can be found from this inter-channel delay. Assuming an ear-to-ear distance of some 20cm, this delay is at most .2/340=.58ms or some 30 samples @ 48kHz. If you calculate the cross-correlation over this range (30 samples) you should find a peak indicating the source direction.

To find the presence of a voice-like signal, you could calculate the total energy in the 80-1000Hz band and threshold it against some reasonable value. You can do this either in the frequency domain by summing the magnitudes in the bins from 80 to 1000Hz, or in the time-domain using a band-filter and an RMS value calculation.


You have a double sided transform. The midpoint is the DC component. A negative frequency is really a positive frequency that is 180 degrees out of phase! So, if you use the first half of the FFT values w/negative freqs you need to change the phase by pi to have an accurate picture of what is happening.

Alternatively, use the second half of the FFT values where the freqs are positive and the phases are correct.

I took a look on the frequency analyzer in Cool Edit Pro and all the amplitudes are negative. In my case, the first ones (the sound is in the background and isn't loud) are negative, and after that, they are all positive. Aren't they supposed to be negative? Am I missing out something over here?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜