Randall
Randall

Reputation: 1

going from Inverse discrete FFT to spectrogram

I need to locate some generic C++ library that takes the inverse fft output (fftw_complex format, i.e. two doubles) and converts this data to an image file such as png. I can waterfall the dffts to obtain the 2d data (and use 10log10(rere+imim) to obtain magnitudes for each frequency component) but I don't know which image library will work.

I did use an older program called zimage at one time, but it seems no longer available. I do not have MATLAB on my Ubuntu 9.10 system (but I do have Octave)

Can Octave generate the waterfall images? I also need to convert the spectrogram into a wav sound file too.

Any ideas??

Upvotes: 0

Views: 888

Answers (2)

mpenkov
mpenkov

Reputation: 21904

OpenCV is one library that can handle PNG files, among a variety of other formats. It should be readily available on your Ubuntu 9.10 system using apt get libcv-dev (from memory, you may have to double-check the package name).

/*
 * compile with:
 *
 * g++ -Wall -ggdb -I. -I/usr/include/opencv -L /usr/lib -lm -lcv -lhighgui -lcvaux filename.cpp -o filename.out
 */

#include <cv.h>    
#include <highgui.h>

/*
 * Your image dimensions.
 */
int width;
int height;

CvSize size = cvSize(width, height);

/*
 * Create 3-channel image, unsigned 8-bit per channel.
 */
IplImage *image = cvCreateImage(size, IPL_DEPTH_8U, 3);

for (int i = 0; i < width; ++i)
for (int j = 0; j < height; ++j)
{
    unsigned int r;
    unsigned int g;
    unsigned int b;

    /*
     * Keep in mind that OpenCV stores things in BGR order.
     */
    CvScalar bgr = cvScalar(b, g, r);
    cvSet2D(image, i, j, bgr);
}

cvSaveImage("filename.png", image);
cvReleaseImage(&image);

Upvotes: 0

xscott
xscott

Reputation: 2430

The easiest image format to create is PNM. You can print it as a text file, and then convert it using most graphics programs. Here is an example from the Wikipedia page:

P2 24 7 15
0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
0  3  3  3  3  0  0  7  7  7  7  0  0 11 11 11 11  0  0 15 15 15 15  0
0  3  0  0  0  0  0  7  0  0  0  0  0 11  0  0  0  0  0 15  0  0 15  0
0  3  3  3  0  0  0  7  7  7  0  0  0 11 11 11  0  0  0 15 15 15 15  0
0  3  0  0  0  0  0  7  0  0  0  0  0 11  0  0  0  0  0 15  0  0  0  0
0  3  0  0  0  0  0  7  7  7  7  0  0 11 11 11 11  0  0 15  0  0  0  0
0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

Save that text in a file named "feep.pgm", and you'll see what I mean.

http://en.wikipedia.org/wiki/Netpbm_format

You'll have to scale your 10log10 information to pixel values.

Upvotes: 2

Related Questions