i'm trying to get an FFT of a signal

my FFT has 1024 samples

i added two sin functions one of freq 86,13Hz (2*44100/1024) and one of freq 129,19Hz (3*44100/1024)

the WAV looks like that (for 1 period) :

enter image description here

i then use this code to inspect the FFT

FFTSize = 1024;

Y = wavread('2sins.wav');

current_window = zeros(FFTSize, 1);

for k = 1:length(Y)/(FFTSize)

   for m = 1:FFTSize
       current_window(m, 1) = Y((k-1)*(FFTSize)+m, 1);


   a = abs(Ydft);
   p = angle(Ydft);


the bins 2 and 3 have the maximum amplitude of 256 which is right as i used two sin of frequency 2 and 3

enter image description here

but when i look at the phases they are -pi/2 which is weird as they should be 0 no ?

here are the phases :

enter image description here

so you see they are -pi/2, why is that ?

and here is the WAV file i used so you can try yourself: http://www.khaelis.com/tmp/2sins.zip

thanks for help



Matlab is right, as usually. The DFT of a sine is imaginary. If you do the same with the sum of two cosines, you would get a real-valued result.

  • $\begingroup$ i thought DFT was decomposing the signal in sinuses not cosinuses $\endgroup$
    – ionone
    Apr 14 '14 at 11:01
  • 1
    $\begingroup$ @ionone, neither. It decomposes into complex exponentials $\exp(i \omega) = \cos(\omega) + i \sin(\omega)$ $\endgroup$
    – Jazzmaniac
    Apr 14 '14 at 11:08
  • $\begingroup$ yes but when i have the phase and magnitude, they represent what ? sinuses or cosinuses ? $\endgroup$
    – ionone
    Apr 14 '14 at 11:27
  • $\begingroup$ oh i get it : DCT = discrete COS transform but originally the FT was with sinuses ...get it now $\endgroup$
    – ionone
    Apr 14 '14 at 11:58

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.