-2
$\begingroup$

This question already has an answer here:

I want to apply Hamming window function the Audio sample then find out its fft..

[y,Fs,bits] = wavread('file1.wav');
Nsamps = length(y); 
ham= hamming(Nsamps);
ham_fft = abs(fft(ham));
ham_fft = ham_fft(1:Nsamps/2); % discarding Half points
plot(ham_fft);

This is my FFT of the song file1.wav

I don't know whether i am getting the correct fft or not ..

$\endgroup$

marked as duplicate by Paul R, jojek, Matt L., endolith, Deve Nov 17 '14 at 8:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ You need first to multiply the window with the signal (y), in the time domain, than perform the fft. Actually you get the correct fourier transform of the window itself. $\endgroup$ – Adiel Nov 2 '14 at 8:56
  • $\begingroup$ Anyway I believe that this question is absolutely unnecessary, as it is clearly answered in this answer to one of yours... $\endgroup$ – jojek Nov 3 '14 at 8:57
-1
$\begingroup$

Your procedure is kind of wrong. You should:

  1. Read the signal from a file.
  2. Create the Hamming window of the same length
  3. Multiply window by signal (on sample-by-sample basis)
  4. Take the FFT

Therefore code should be like:

[y,Fs,bits] = wavread('file1.wav');
Nsamps = length(y); 
ham= hamming(Nsamps);
y_ham = y.*ham';
ham_fft = abs(fft(y_ham));
ham_fft = ham_fft(1:Nsamps/2); % discarding Half points
plot(ham_fft);
$\endgroup$
  • $\begingroup$ I tried the following code but the problem is that the dimension of y and ham are not same so element by element multiplication is not possible ... What else is can do? $\endgroup$ – Hassan Anwer Nov 2 '14 at 12:04
  • $\begingroup$ Maybe the signal itself is also stored as a column vector, try y_ham=y.*ham; $\endgroup$ – Adiel Nov 2 '14 at 12:46
  • $\begingroup$ Depending on dimensions of your signal you can either transpose it with ' operator or not. $\endgroup$ – jojek Nov 2 '14 at 13:48
  • $\begingroup$ Note that you also have to define the X-axis. It can be written like that: plot(linspace(0,Fs/2-1/Nsamps,Nsamps),ham_fft) $\endgroup$ – Adiel Nov 3 '14 at 0:32

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