2
$\begingroup$

I want to apply the following steps in matlab

1) Read the audio data

2) Apply window function on that data

3) Apply fft on the result of window function

4) Make power spectrum of fft

5) divide power spectrum in Barks bands

[y,Fs,bits] = wavread('file1.wav');
Nsamps = length(y); 
ham= hamming(Nsamps);
ham_fft = abs(fft(ham));
ham_fft = ham_fft(1:Nsamps/2);      %Discard Half of Points
plot(f, ham_fft)
xlim([0 1000])  
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('FFT of Hamming Window of  a an audio');

I am not getting the correct waveform , want to draw the spectrum and then Divide into barks bands .

$\endgroup$
1
$\begingroup$
  • Read the audio data

    [y,Fs,bits] = wavread('file1.wav');
    
  • Apply window function on that data

    ham=hamming(Nsamps);
    windowed = y .* ham;
    
  • Apply fft on the result of window function

    ham_fft = fft(windowed);
    ham_fft = ham_fft(1:Nsamps/2);      %Discard Half of Points
    
  • Make power spectrum of fft

    PowSpec = abs(fft(ham_fft)).^2;
    
  • divide power spectrum in Barks bands

So here maybe start interesting things, based in wikipedia the 24 Critical Barks Bands in Hertz is:

20,100,200,300,400,510,630,770,920,1080,1270,1480,1720,2000,2320,2700,3150,3700,4400,5300 6400,7700,9500,12000,15500

Now to split the power spectrum in Barks bands you need to do something like:

BandBarks = [20 100 200 300 400 510 630 770 920 1080 1270 1480 1720 2000 2320 2700 3150 3700 4400 5300 6400 7700 9500 12000 15500];


for l = 1:length(BandBarks)-1 
    CurrentBand = [BandBarks(l):BandBarks(l+1)];
    PowSpec(CurrentBand,:) %% here is the power spectrum for each Barks bands
end 

OK by your commented error seems that your audios are in stereo, convert to mono, or get just one channel!

my example above assumes that each BIN number is the equivalent frequency (course this is nothing common was just an example), to find what bin is your frequency you need calculate:

$$ BandBarks * (\frac{Fs}{length(FFT)})$$

So based in this equation:

Bins = zeros(length(BandBarks),1);
for j = 1:length(BandBarks)

    Bins(j)=round(BandBarks(j)/(Fs/length(FFT)))

end

Now here how to plot individually each Bark band:

for l = 1:length(Bins)-1 
    CurrentBand = [Bins(l):Bins(l+1)];
    figure(l);
    plot(PowSpec(CurrentBand,:));
end 

I think I can not be clearer than that

$\endgroup$
  • $\begingroup$ Good start but 1/ It's unlikely you'll have to do that on the entire audio file - but rather short segment by short segment. 2/ You need to sum the power spectrum over each band. 3/ It's actually more common to use triangular-shaped filters, peaking at band n, and null at band n+1 and band n-1. $\endgroup$ – pichenettes Oct 9 '14 at 1:11
  • $\begingroup$ I am getting error at windowed = y .* ham; because the matrix size is not same, y is 2 by 3144549 and ham is 3144549 by 1 and i want to draw power spectrum individually of each band @ederwander $\endgroup$ – Hassan Anwer Oct 9 '14 at 15:44
  • $\begingroup$ OK take a look in my edit $\endgroup$ – ederwander Oct 9 '14 at 20:26

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.