On 13/01/2017 05:55, Oliver Kroth wrote:
>
>
> Am 12.01.2017 um 22:53 schrieb Fernando Jefferson:
>>
>> I'm developing a Lua application and I need to identify frequencies in
>> an audio recording (Wav format).
>>
>> By theory, it would be enough to apply a Fast Fourier Transform in the
>> sample sequence and extract the real part.
>>
>> I got a package of FFT for Lua:
>> Https://rosettacode.org/wiki/Fast_Fourier_transform#Lua
>>
>> My first test was with a very simple audio (1 second of 440Hz tone,
>> sample rate 16KHz). The output of the routine would be an array with
>> only the value 440 on all elements ... But it is not working.
>>
>> I would appreciate any help. I can send the test audio and the Lua
>> routine which reads the wav file and tries to apply the FFT.
>>
>> Fernando Jefferson
> HI Fernando,
>
> do you have to test for a single (or a few) known frequency?
> In that case, the Goertzel algorithm may be your friend. It is a DFT
> (not fast one) for a single frequency, which is faster for a single
> frequency tha FFT
> If you have to find the loudest tone; FFT is the first step. Then find
> the highest amplitude; for this don't rely on the real part, it may be
> zero with the imaginary part carrying all the power of the signal.
>
> Real and imaginary part can be converted to amplitude and phase angle.
> Phase is irrelevant in terms of power, amplitude is relevant. If you
> want to be exact, you need to computer the sum of the squares of real
> and imaginary part, and find the position of the largest result.
>
> Which frequency this is depends on the number of samples that you
> computed the FFT of. With 1024 samples, you get a frequency resolution
> of 16kHz/512.
>
Yes that is an option for special cases.
Many people have thought they can easily measure audio frequencies. In
fact this is in all but a few cases a very hard problem. Mention of FFT
tends to point to the writer not really understanding what is facing them.
Most audio frequencies do not fit with Fourier frequencies, nasty things
happen. The rate of detection is usually another gotcha.
So...
Decoding an audio file is a simple problem to sort out. Getting a
Fourier Transform code working is also something to sort out. In other
words you can get the framework working and reliable and with diagnostics.
You then need to do a lot of technical reading about frequency
detection. A lot is written in DSP forums etc.
Beware Rossetta code, most of it is forced to GPL and means your IP is
owned by others. There are good FFT codes under really open source.
I use code from here
http://www.kurims.kyoto-u.ac.jp/~ooura/ but I've
never tried this in connection with Lua.
"
Copyright Takuya OOURA, 1996-2001
You may use, copy, modify and distribute this code for any purpose
(include commercial use) and without fee. Please refer to this package
when you modify this code."