Analyzing wav files in MATLAB

2019-07-11 20:53发布

问题:

So I have this piano recording (in .wav format). I am able to do an FFT on the whole recording and identify frequencies.

However, according to some articles I read, its best if the wav file is broken down into windows, where each window would include one particular note.

For this I need to initially plot a "power envelope" of my time domain signal (considering the note average energy concept) therefore there'll be one increase and one decrease for each note and note onsets can be determined by checking the local minima.

This is where 'windows' are introduced, where each window consists of only one onset and then FFT is performed on each window.

Im having difficulty in plotting the power envelope and moving onto breaking it down into windows. Would appreciate some help with the Matlab coding for this.

The code I've used is pretty straightforward:

[wave,fs] = wavread ('c scale fast.wav'); % read file into memory */

%sound(wave,fs); % see what it sounds like */

wave = wave.*hamming(length(wave));

t = 0:1/fs:(length(wave)-1)/fs; % and get sampling frequency */

figure(2);

      subplot(2,1,1);
      plot(t,wave);
      title('Wave File');
      ylabel('Amplitude');
      xlabel('Length (in seconds)');

L = length(wave);

NFFT = 2^nextpow2(L); % Next power of 2 from length of y

Y = fft(wave,NFFT)/L;

f = fs/2*linspace(0,1,NFFT/2+1);

% Plot single-sided amplitude spectrum.

   subplot(2,1,2);
   plot(f,2*abs(Y(1:NFFT/2+1))) 
   title('Single-Sided Amplitude Spectrum of y(t)')
   xlabel('Frequency (Hz)')
   ylabel('|Y(f)|')

After my signal (abs value of my wav file) is convolved with the Gaussian filter i try taking the 1st and 2nd derivatives, but i don't get an output when i try to plot it.

edges=fconv(abs(song),detect);

tedges=edges(P/2:N+P/2-1);

tedges=tedges/max(abs(tedges));

W= diff(tedge);

Z= diff(W);

It is when i try to plot W and Z that I don't get the output I need. My graph is empty in other words. I can't figure out what I'm doing wrong here...

回答1:

Useful: http://blogs.mathworks.com/videos/2009/12/31/basics-finding-a-subset-of-a-matrix/

Basic flow:

for v=1:window_length:length(data)
    data_subsection=data(v:v+window_length);
    subsection_fft = fft(data_subsection);
    plot(...);
end


标签: matlab fft