[Stk] any FFT available on STK
Craig Sapp
craigsapp at gmail.com
Mon Apr 14 16:05:55 PDT 2008
Hello Josep,
2008/4/14 Josep Comajuncosas <josep.comajuncosas at gmail.com>:
> Hi,
> well just this, does anyone have a nice working example of an FFT library
> implemented in the stk framework?
> Thanks in advance
> Josep M
>
Not quite what you want, but close: I have a C++ interface for FFTW
(http://www.fftw.org) which is probably the most efficient FFT library
available for free.
Here is my C++ interface class to FFTW:
http://sv.mazurka.org.uk/src/MazurkaTransformer.cpp
http://sv.mazurka.org.uk/include/MazurkaTransformer.h
which I use to make vamp plugins for the Sonic Visualiser
audio editor (http://www.sonicvisualiser.org).
The MazurkaTransformer::initialize function demonstrates the
setup requried for running the FFTW transform, and the function
doTransform() does the actual work of calculating the transform
using FFTW's function called fftw_execute().
Example usage:
////////////////////////////////
#include "MazurkaTransformer.h"
#include <iostream>
#include <iomanip>
#include <math.h>
#define SIZE 32
using namespace std;
int main(void) {
MazurkaTransformer bumblebee;
bumblebee.setSize(SIZE);
int i;
double signal[SIZE];
double window[SIZE];
for (i=0; i<SIZE; i++) {
signal[i] = sin(2.0 * M_PI * 5 * i / SIZE); // putting energy in bin
5
window[i] = 0.5 - 0.5 * cos(2.0 * M_PI * i / SIZE); // Hann window
}
for (i=0; i<SIZE; i++) {
bumblebee.signalNonCausal(i) = signal[i] * window[i];
}
bumblebee.doTransform();
for (i=0; i<SIZE; i++) {
cout << "bin " << i << ":"
<< setiosflags(ios::fixed)
<< setprecision(3)
<< "\treal= " << setw(7) << bumblebee.getSpectrum(i).re
<< "\timag= " << setw(7) << bumblebee.getSpectrum(i).im
<< "\tmag= " << setw(7) << bumblebee.getSpectrumMagnitude(i)
<< "\n";
}
return 0;
}
/* compiling example:
g++ -Iinclude MazurkaTransformer.cpp test.cpp -Lfftw/lib -lfftw3 -o test
*/
/////////////////////////////////
Which produces the following printout (bin 0 = 0 Hz, bins 1-15 are the
positive frequencies):
bin 0: real= -0.000 imag= 0.000 mag= 0.000
bin 1: real= -0.000 imag= 0.000 mag= 0.000
bin 2: real= 0.000 imag= -0.000 mag= 0.000
bin 3: real= 0.000 imag= -0.000 mag= 0.000
bin 4: real= 0.000 imag= 4.000 mag= 4.000
bin 5: real= 0.000 imag= 8.000 mag= 8.000
bin 6: real= 0.000 imag= 4.000 mag= 4.000
bin 7: real= 0.000 imag= 0.000 mag= 0.000
bin 8: real= 0.000 imag= 0.000 mag= 0.000
bin 9: real= -0.000 imag= -0.000 mag= 0.000
bin 10: real= -0.000 imag= -0.000 mag= 0.000
bin 11: real= -0.000 imag= 0.000 mag= 0.000
bin 12: real= 0.000 imag= -0.000 mag= 0.000
bin 13: real= -0.000 imag= -0.000 mag= 0.000
bin 14: real= -0.000 imag= 0.000 mag= 0.000
bin 15: real= 0.000 imag= 0.000 mag= 0.000
bin 16: real= -0.000 imag= 0.000 mag= 0.000
bin 17: real= 0.000 imag= -0.000 mag= 0.000
bin 18: real= -0.000 imag= -0.000 mag= 0.000
bin 19: real= -0.000 imag= 0.000 mag= 0.000
bin 20: real= 0.000 imag= 0.000 mag= 0.000
bin 21: real= -0.000 imag= -0.000 mag= 0.000
bin 22: real= -0.000 imag= 0.000 mag= 0.000
bin 23: real= -0.000 imag= 0.000 mag= 0.000
bin 24: real= 0.000 imag= -0.000 mag= 0.000
bin 25: real= 0.000 imag= -0.000 mag= 0.000
bin 26: real= 0.000 imag= -4.000 mag= 4.000
bin 27: real= 0.000 imag= -8.000 mag= 8.000
bin 28: real= 0.000 imag= -4.000 mag= 4.000
bin 29: real= 0.000 imag= 0.000 mag= 0.000
bin 30: real= 0.000 imag= 0.000 mag= 0.000
bin 31: real= -0.000 imag= -0.000 mag= 0.000
-=+Craig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://ccrma-mail.stanford.edu/pipermail/stk/attachments/20080414/d0f8a4e9/attachment.html
More information about the Stk
mailing list