% Signals and Systems Lab % Drumbeat identification % Written by David Egan % DT021/2A function drum = drumbeats(signal) % Setting the function a = 0; % using 'a' variable as counter beat = max(signal)*.99; % Setting 99% of max amplitude as beat for (k = 1 : length(signal)) % Looping through the signal length if(signal(k) > beat) % Checking to see if the magnitude is greather that 99% of max a = a + 1; % Using 'a' to count the beats if > 99% segment = signal(k : k + 20000); % Using k to segment a part of each beat for further anaylsis fft_segment = fft(segment); % Getting the Fourier Transform of the segment mag_values = abs(fft_segment); % Gets the magnitude of the frequencies of the segment if (max(mag_values(1:500)) > 500) % Checks the maximum magnitude to distinguish between tom sounds tom = 2; % Sets variable 'tom' to 2 for the second tom else tom = 1; % Sets variable 'tom' to 1 for the first tom end str = ['Drumbeat ',num2str(a),' at ', num2str(k),' is tom ',num2str(tom)]; % setting a string with variables disp(str); % Displaying the string with beat position and tom type for each beat end end str1 = ['There are ', num2str(a), ' drumbeats in total. ']; % Displaying the total number of beats disp(str1);

# Drumbeat Identification

**27**
*Saturday*
Oct 2012

Posted MATLAB code

in