STFT_FREQ is a C application for frequency estimation in audio files. It calculates a Short Time Forier Transform (STFT) and picks the most promenten bin within a frequency region of interest. It subsequently refines the frequency estimation using parabolic interpolation. It prints out the estimated frequency together with the magnitude of the frequency FFT bin.
Most speech or music frequency estimators need relatively large FFT windows to allow precise frequency estimation. The assumption for speech and music is that frequency changes relatively slowly. For birdsong this assumption might not hold. In the example below a fast change is shown.
To use stft_freq ffmpeg
and ruby
need to be installed on your system. While the core of stft_freq is in pure c, a Ruby script provides an easy to use interface to its capabilities. The Ruby script converts audio (with ffmpeg), parses command line arguments and reports results in a readable format.
To install ffmpeg and ruby on a Debian like system:
apt-get install ffmpeg ruby
On macOS ruby is available by default and ffmpeg
can be installed with homebrew
brew install ffmpeg
To compile use toffolwing commands. By default the makefile uses gcc set to the C11 standard. It should be possible to use other compilers compliant with the C11 standard as well. So either make sure gcc is installed correctly or modify the Makefile for your compiler of choice. Compilation and installation:
make make install
After a successfull installation of stft_freq on your path calling the program should be as simple as
stft_freq audio.mp3
To import the results in Sonic Visualizer save the result to a csv file. Import out.csv into sonic visualiser with the first column the time in seconds and the second column the value. It might be of interest to filter out the fft bins with a low magnitude.
stft_freq audio.mp3 > out.csv
The c application can be used directly as well with correctly converted RAW files:
stft_freq audio_sr block_size step_size min_freq max_freq audio_file.raw
The parabolic interpolation and windowing function is described here:
Gasior, M., and J. L. Gonzalez. Improving FFT frequency measurement resolution by parabolic and gaussian interpolation. No. AB-Note-2004-021. CERN-AB-Note-2004-021, 2004.
Parts of the code are reused from Olaf .
STFTF_freq by Joren Six at IPEM, Ghent University.