function [result]=findChord(sound) fftlength=8000; numRuns = ceil(length(sound) / fftlength); result = ones(numRuns, 1); filter = ones(3, 1); for run=1:numRuns sample = sound(((run-1) * fftlength + 1):min([(run * fftlength), length(sound)])); fftsound = abs(fft(sample)); fftsound = conv(filter, fftsound); % figure(2 * run - 1); % plot(fftsound(1:fftlength/2)); % figure(2 * run); % plot(fftsound(1:200)); maxf = 0; for x=1:length(fftsound) if(fftsound(x) > maxf) maxf = fftsound(x); end end thres = maxf / 3; freq = 0; for x=1:length(fftsound) if(fftsound(x) > thres) freq = x; else if(freq ~= 0) break; end end end fundamental = freq; lowerBound = round(freq * 1.2); upperBound = round(freq * 1.8); additionalNotes = zeros(0, 1); freq = 0; for x=lowerBound:upperBound if(fftsound(x) > thres) freq = x; else if(freq ~= 0) freqresult(run) = freq; additionalNotes(result(run)) = freq; result(run) = result(run) + 1; freq = 0; end end end % figure(run); % plot(fftsound(1:100)); % hold on; % stem(fundamental, max(fftsound(1:100)), 'g'); % stem(upperBound, max(fftsound(1:100)), 'g'); % for i=1:length(additionalNotes) % %disp(['additionalNotes of i = ' int2str(i) ' = ' int2str(additionalNotes(i))]); % stem(additionalNotes(i), max(fftsound(1:100)), 'r'); % end % hold off; end figure(3); subplot(2, 1, 1); plot(8000 * [1:numRuns], result); title('Number of Notes Playing'); subplot(2, 1, 2); plot(sound / norm(sound, inf), 'r'); title('Music Sample Tested');