SND2FFTW

SourceForge.net Logo

snd2fftw is a small tool that reads samples from audio file (WAV for example)  and makes DFT on them. Text stream is produced. This stream may be loaded from any spreadsheet or may be used as input data for GNU plot. Audio files is handled using libsndfile library and Fourier transform makes FFTW library. Because these libraries are licensed under GPL license this tool is GPL-ed also. 

This utility currently works only on Windows 2K or above.
This utility was created using VC++ 2005. It is written in pure C. I believe that snd2fftw may be compiled on other platforms (compilers) with minor modifications.

Source and binary you can download here.

snd2fftw.exe is dynamically linked to fftw3-3.dll (FFTW libray) and libsndfile-1.dll (libsndfile library) libraries. These libraries are not included in my package. You must download them separatley.

Precompiled binaries of FFTW library you can download from http://www.fftw.org/install/windows.html.
Precompiled binaries of libsndfile library you can download from libsndfile site.

Usage.

snd2fftw [-v] [-w] [-3] [-l] [-s pos] [-n samples][-c channels] -i infile [-o outfile] [-h]

Option Description
-v Be more verbose.
-w Do not Fourier transform on input file. Just simply dump samples as text stream with two columns: time (in seconds) and value (normalized [-1;1]).
-3
Do "windowed" Fourier transform. By default all samples form input file are taken to one-step Fourier transform. This produces text stream with two columns frequency (Hz) and frequency power. Using this option Fourier transform is computed on small blocks (see -n option). This produces text stream with three columns: time (in seconds), frequency (Hz) and power.
-l
Generates "locale friendly" text stream. Simply calls setlocale function to set default user locale. This changes behavior of fprintf function for example.
-n samples
IF no -3 option is used only samples samples are used to Fourier transform. If -3 ioption is used this option specify block (window) size (default 256).
-s pos
Seek to specified position in samples.
-c channel
Specify channel (numbered from 0) in multichannel audio file. Default zero.
-i infile
Input audio file. This option must be used.
-o outfile
Specify output file. By default output stream is directed to StdOut.
-h
Prints simple help.

In text stream columns are separated by tabulator.

Example.

Lets take simple DTMF sample and Windows port of GNU plot.

At first we create simple wave drawing:

snd2fftw -w -idtmf.wav -osnd.dat
wgnuplot_pipes.exe plot_snd.plt

where plot_snd.plt looks like this:

set grid
set xtics rotate
set xlabel "Time (s)"
set ylabel "Amplitude [-1:1]"
set terminal png transparent interlace large size 400,300
set output "snd.png"
plot "snd.dat" notitle with lines

This script generates snd.png file:
DTMF entrie wave

Now its time to simple Fourier transform:

snd2fftw -idtmf.wav -odft.dat
wgnuplot_pipes plot_dft.plt

where plot_dft.plt looks like this:

set grid
set xtics rotate
set xlabel "Frequency (Hz)"
set ylabel "Energy"
set terminal png transparent interlace large size 400,300 enhanced
set output "dft.png"
plot "fftw.dat" notitle with lines

This script generates dft.png file:
DTMF simple one-step transform

And now 3D (?) plot:

snd2fftw -3 -idtmf.wav -o3dft.dat
wgnuplot_pipes plot_3dft.plt

Where plot_3dft.plt looks like this

set pm3d at s corners2color c1
set palette model XYZ functions gray**0.35, gray**0.5, gray**0.8
unset hidden3d
unset surf
set view map
unset clabel
unset colorbox
set grid xtics ytics ztics
set xlabel 'Time (s)'
set ylabel 'Frequency (Hz)'
set terminal png transparent interlace large size 800,600 enhanced
set output "3dft.png"
splot '3dft.dat' notitle

This script generates 3dft.png file:
DTMF Fourier transform

At last true 3D plot:

wgnuplot_pipes plot_3dft_ex.plt

Where plot_3dft_ex.plt looks like this

set pm3d at s hidden3d 100
set style line 100 lt 20 lw 0
set palette model XYZ functions gray**0.35, gray**0.5, gray**0.8
unset hidden3d
unset surf
set view 50,145
set border 1023-128
unset clabel
unset colorbox
set grid xtics ytics ztics
set xlabel 'Time (s)'
set ylabel 'Frequency (Hz)'
set zlabel 'Energy'
set terminal png transparent interlace large size 800,600 enhanced
set output "3dft_ex.png"
splot '3dft.dat' every 2 notitle

This script generates 3dft_ex.png file:
Truly 3D plot

I hope now everything is clear of course if you know what Fourier transform is :)

Contact: roed at onet dot eu
SourceForge.net Logo