% noteparse.m % usage: divs = noteparse(data) % takes in a double array specified by data % and outputs a vector of division points % that correspond to seperate and distinct notes % in other words, trying to find when one note stops % and another starts. % the returned vector will include the midpoint of the % end of note and the beginning of the next. function divs = noteparse(data) len = length(data); %let's find a threshold value so we know when a note starts/stops threshup = .2 * max(data); % 20% of the maximum value threshdown = .04 * max(data); quiet=1; % a flag so we know if we're noisy or quiet right now j=1; for i=51:len-50, if quiet == 1 % we're trying find the begining of a note if (max(abs(data(i-50:i+50))) > threshup) quiet = 0; % we found it divs(j) = i; %record this division point j=j+1; end else if (max(abs(data(i-50:i+50))) < threshdown) quiet = 1; %note's over divs(j) = i; j=j+1; end end end