1
$\begingroup$

At first, I want to say that I'm totally beginner in DSP and I don't have enough math education to understand Fast-Fourier transformation.

I'm a programmer and I want to archieve something like this:

Spectrum in VLC

My example file is in 8kHz, 16-bit samples, but currently, I'm trying to do with my own raw data - one sin(x) function. I know that I need to pass N samples to FFT function, but how interpret result? As I see, FFT need some input data (N samples) and gives N output data.

How I can know where is frequency and scale it - for example - to 5 scopes like 0 - 200Hz, 200 - 400Hz etc.

Or maybe I don't understand FFT correctly? I think that I can pass some samples and get information "how much" is each frequency.

Technically, I'm using FFTW3 library.

$\endgroup$
2
$\begingroup$

I think we need a little more information to fully answer your question. Most FFT routing (like FFTW) provide many different ways to call the transform, and the return result will depend on exactly what routine you call, and how you call it.

Having said the standard disclaimer, if you perform an FFT on $N$ real data points, you will get back $N/2$ unique complex points. The basic algorithm though will assume your $N$ real points are $N$ complex points with zero imaginary parts. Many routines will thus return $N$ complex points, but the second half will be (in the case of real input) hermitian symmetric (that is, point $N/2+i$ will be the complex conjugate of point $N/2-j$).

So, start by recognizing that your result is complex numbers, not real, and you will need to at least plot the "square" ($xx^*$) or each point. If you have the real and imaginary points returned as $X_r$ and $X_i$, then you want to plot $X_r^2+X_i^2$.

So you are probably pretty close. You will want to consider a few other things: windowing your input data, and averaging your output data. To do the first, you need to perform the transform on weighted data, rather than your direct data. See http://en.wikipedia.org/wiki/Window_function for more info. You will simply hand the FFT function data of the form $W_k {x_k}$ instead of just the $x_k$ (where $k$ is the index number). This will be particularly important if you use a fractional frequency in your sin function (try it, you'll see).

The averaging step involves averaging the squared output. You will simply want to average a few outputs, point by point, together. You will also often want to plot the output as a logarithm though, instead of simply plotting the squared output.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.