% noterecog.m % note recognition function % usage: notes = noterecog(data) % % where data is an array of sample points function notes = noterecog(data) tic; % get the note windows w = notewindows(data) % how many notes in this sample num_notes = length(w)-1; for i=1:num_notes, %take the window for the current note cur_note = data(w(i):w(i+1)); cur_fft = abs(fft(cur_note)); cur_fft = cur_fft(1:length(cur_fft)/2); %figure(i); plot(cur_fft) [Y,I] = max(cur_fft); % I is the frequency of the note freqs(i) = I; end %let's go through one more time to get rid of any noisy notes j=1; for i=1:num_notes if ((freqs(i) > 20) & (freqs(i) < 20000)) f(j) = freqs(i); j=j+1; end end for i=1:length(f), [p,o] = findpitch(f(i)); notes(i,1) = notes(i,2) = o; notes(i,3) = p; end toc