Discret fourier transform help needed



I juste made some C code to compute the discret fourier
transform of a one dimention array (of size N) (I use
a simple DFT for testing, but will code it as a FFT
very soon). I have some questions regarding the
interpretation of it's output. first I must say that
this code will be used in an audio frequency analyser
program. I would like to output a realtime graphic of
the frequencies from 20Hz-22000KHz and a graphic of the
phase of the signal (something like the frequency and
phase analysis in cooledit pro).

I think I may be missing some points, I'm currently
learning how to use DFT in my programs. If you can help
me with some hints or by telling me if I'm doing something
wrong it will be very helpful. Here some things I did but
I'm not certain I'm on the right track.

1) I know that only the first N/2 complex values should
be used, the rest is redundent, right?

2) The magnitude of the frequencies:
If I understand it correctly I should calculate the
module of each complex outputs (sqrt(real[n]^2+img[n]^2))
But the magnitude changes whenever I change the FFT
size (N). How can I normalize this to be able to convert
it into dB. Divide it by N or something like that?

3) The phase of the signal
I calculate it using atan2(real[n],img[n]), I'm I right?

4) Convert the complex outputs to their respective frequencies
I found somewhere that analogue frequency=2*Pi*n/N*T in radians/s
so if I sample the signal at 44.1kHz, I set T=1/44100
and calcule f=n/N*T, is it correct? N the DFT size is 32 in
my example.

5) Here's 32 points DFT output:
(in this output the sample rate is 44000Hz not 44100Hz)
I have compared it's output to a comparable FFT I made in maple
and the results seems to be correct. But I would like to know
if anyone see something abnormal in this output or if it seems
fine.

sample rate=44000
T=1/44000
N=32
f(x)=sin(2*Pi*k/N-1) k=0..31 So it's a 1375Hz signal at 44000Hz
Output:

n real imaginary module argument(phase in rad)
frequency(Hz)
-----------------------------------------------------------------
[ 0] 0.000000 0.000000 mod: 0.000000 arg: 0.000000 freq:0
[ 1] 1.540578 -15.641746 mod:24.097323 arg:-1.472622 freq:1375
[ 2] -0.137671 0.692121 mod: 0.095285 arg: 1.767146 freq:2750
[ 3] -0.114565 0.377669 mod: 0.043267 arg: 1.865321 freq:4125
[ 4] -0.108212 0.261247 mod: 0.028270 arg: 1.963495 freq:5500
[ 5] -0.105509 0.197393 mod: 0.020827 arg: 2.061670 freq:6875
[ 6] -0.104101 0.155799 mod: 0.016219 arg: 2.159845 freq:8250
[ 7] -0.103276 0.125842 mod: 0.012996 arg: 2.258020 freq:9625
[ 8] -0.102753 0.102753 mod: 0.010558 arg: 2.356194 freq:11000
[ 9] -0.102403 0.084040 mod: 0.008606 arg: 2.454369 freq:12375
[10] -0.102162 0.068262 mod: 0.006974 arg: 2.552544 freq:13750
[11] -0.101991 0.054516 mod: 0.005560 arg: 2.650719 freq:15125
[12] -0.101871 0.042196 mod: 0.004299 arg: 2.748894 freq:16500
[13] -0.101787 0.030877 mod: 0.003143 arg: 2.847068 freq:17875
[14] -0.101732 0.020236 mod: 0.002059 arg: 2.945243 freq:19250
[15] -0.101700 0.010017 mod: 0.001019 arg: 3.043418 freq:20625
[16] -0.101690 -0.000000 mod: 0.000000 arg:-3.141593 freq:22000
[17] -0.101700 -0.010017 mod: 0.001019 arg:-3.043418 freq:23375
[18] -0.101732 -0.020236 mod: 0.002059 arg:-2.945243 freq:24750
[19] -0.101787 -0.030877 mod: 0.003143 arg:-2.847068 freq:26125
[20] -0.101871 -0.042196 mod: 0.004299 arg:-2.748894 freq:27500
[21] -0.101991 -0.054516 mod: 0.005560 arg:-2.650719 freq:28875
[22] -0.102162 -0.068262 mod: 0.006974 arg:-2.552544 freq:30250
[23] -0.102403 -0.084040 mod: 0.008606 arg:-2.454369 freq:31625
[24] -0.102753 -0.102753 mod: 0.010558 arg:-2.356194 freq:33000
[25] -0.103276 -0.125842 mod: 0.012996 arg:-2.258020 freq:34375
[26] -0.104101 -0.155799 mod: 0.016219 arg:-2.159845 freq:35750
[27] -0.105509 -0.197393 mod: 0.020827 arg:-2.061670 freq:37125
[28] -0.108212 -0.261247 mod: 0.028270 arg:-1.963495 freq:38500
[29] -0.114565 -0.377669 mod: 0.043267 arg:-1.865321 freq:39875
[30] -0.137671 -0.692121 mod: 0.095285 arg:-1.767146 freq:41250
[31] 1.540578 15.641746 mod:24.097323 arg: 1.472622 freq:42625

Thanks in advance.
.



Relevant Pages

  • Re: dft : property of symmetry for real & even seq
    ... you should use a discrete cosine transform (DCT). ... is why people normally have a complex-output DFT (even if they have ... positive frequencies (as I understand it when the time domain samples ... The relationship between the real DFT polar form and the complex DFT ...
    (comp.dsp)
  • Re: Why window in time domain before FFT?
    ... alledged *inherent* periodic nature of the DFT (which is what the FFT ... DTFT is sampled at N equal frequencies from -Nyquist to +Nyquist, ... FFTs of these signals will produce the ...
    (comp.dsp)
  • Re: Spectra of Unequally Sampled Data
    ... Automatic Spectra Analysis and the ARMASA toolbox. ... % Compute DFT at frequencies given ... give the same coefficients at usual DFT frequencies as the usual DFT ... at the uniformly spaced frequencies that the conventional DFT ...
    (comp.soft-sys.matlab)
  • Re: Spectra of Unequally Sampled Data
    ... Automatic Spectra Analysis and the ARMASA toolbox. ... % Compute DFT at frequencies given ... give the same coefficients at usual DFT frequencies as the usual DFT ... The reason why it is mostly used with uniform sampling is obvious. ...
    (comp.soft-sys.matlab)
  • Re: MATLABs FFT and fftshifting the input
    ... shifted, when N is even, MATLAB's fftshift puts the Nyquist ... and there is no Nyquist point for N odd. ... nonnegative frequency interval by the fft. ... just like the DFT except for a scaling factor. ...
    (comp.dsp)