<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/technology/cnxml/schema/dtd/0.5/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:m="http://www.w3.org/1998/Math/MathML" id="new">
  <name>Edge Detection</name>
  <metadata>
  <md:version>1.2</md:version>
  <md:created>2006/12/18 22:46:31 US/Central</md:created>
  <md:revised>2006/12/23 13:55:11.814 US/Central</md:revised>
  <md:authorlist>
      <md:author id="barron">
      <md:firstname>Barron</md:firstname>
      <md:othername>D.</md:othername>
      <md:surname>Stone</md:surname>
      <md:email>barron@rice.edu</md:email>
    </md:author>
      <md:author id="robsmith">
      <md:firstname>Rob</md:firstname>
      
      <md:surname>Smith</md:surname>
      <md:email>rob@rice.edu</md:email>
    </md:author>
      <md:author id="narayann">
      <md:firstname>Neil</md:firstname>
      <md:othername>K.</md:othername>
      <md:surname>Narayan</md:surname>
      <md:email>narayann@rice.edu</md:email>
    </md:author>
      <md:author id="brent">
      <md:firstname>Brent</md:firstname>
      <md:othername>E.</md:othername>
      <md:surname>Stephens</md:surname>
      <md:email>brents@rice.edu</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="barron">
      <md:firstname>Barron</md:firstname>
      <md:othername>D.</md:othername>
      <md:surname>Stone</md:surname>
      <md:email>barron@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="robsmith">
      <md:firstname>Rob</md:firstname>
      
      <md:surname>Smith</md:surname>
      <md:email>rob@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="narayann">
      <md:firstname>Neil</md:firstname>
      <md:othername>K.</md:othername>
      <md:surname>Narayan</md:surname>
      <md:email>narayann@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="brent">
      <md:firstname>Brent</md:firstname>
      <md:othername>E.</md:othername>
      <md:surname>Stephens</md:surname>
      <md:email>brents@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="richb">
      <md:firstname>Richard</md:firstname>
      <md:othername>G.</md:othername>
      <md:surname>Baraniuk</md:surname>
      <md:email>richb@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="Markpanzee">
      <md:firstname>Mark</md:firstname>
      <md:othername>A.</md:othername>
      <md:surname>Davenport</md:surname>
      <md:email>md@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>beat</md:keyword>
    <md:keyword>beat detection</md:keyword>
    <md:keyword>detection</md:keyword>
    <md:keyword>edge</md:keyword>
    <md:keyword>edge detection</md:keyword>
    <md:keyword>gaussian</md:keyword>
    <md:keyword>music</md:keyword>
    <md:keyword>sound</md:keyword>
  </md:keywordlist>

  <md:abstract>This module investigates the use of Matlab filters to determine when notes are played within a recording from an electric guitar.</md:abstract>
</metadata>
  <content>
    <para id="delete_me">In order to determine the speed at which the user is playing it is first necessary to determine where in the recording individual notes are plucked.  When a note is played on the guitar, a sharp peak occurs which is then followed by a decay as the vibrations in the string dampen.  To determine where these edges occur the signal is first low pass filtered to remove some of the noise, then it is convolved with an edge detector function which produces a signal with peaks located at large edges (where notes are played).</para><para id="element-486">Due to the non-uniform qualities of guitar waveforms, an edge detector function with rounded edges produced the best results.  A good function to use for an edge detector function is the derivative of a Gaussian.  This produces a filter that can be tuned to work well with certain frequencies specific to the instrument being tested.</para><figure id="element-876"><name>Derivative of a Gaussian</name>   <media type="image/bmp" src="derivativeGaussian.bmp"/>   <caption>This derivative of a Gaussian was produced in Matlab with f(x) = y(x)*exp(-y(x)^2/100000);</caption></figure><para id="element-128">After the original signal is convolved with the Gaussian edge detector the result is a signal with peaks located where edges occurred in the original signal.  A simple algorithm is used to create a vector of zeros with ones located at the locations of the peaks.  Due to the nature of the guitar signal, it is not uncommon for the convolved signal to contain "double peaks" where two or more closely spaced peaks are created to represent what should be considered a single edge.  To accommodate for this error, the algorithm is designed that once it finds a peak, it ignores any other peaks that occur within a given threshold range.</para><figure id="element-93"><name>Orignal Signal and Convolved Signal</name>   <media type="image/bmp" src="OrignalAndConvolved.bmp"/>   <caption>The top plot represents the original signal from the guitar.  The bottom plot represents product of the convolution of the orignal signal with the derivative of a Gaussian.</caption></figure><figure id="element-476"><name>Location of Edges</name>   <media type="image/bmp" src="overlay.bmp"/>   <caption>The vector of zeros and ones representing edge locations overlayed on top of the original signal.</caption></figure><para id="element-244">To use the information produced by the edge detection to determine how fast the user is playing, the vector of ones and zeros representing peak locations is windowed into equal length chunks.  The values within each of these chunks are summed together to determine the number of notes played within that window of time.  From this, the program can determine whether the user was playing fast or slow during that period of time based on whether the number of notes played is above or below a previously decided threshold.</para><figure id="element-742"><media type="file/m" src="EdgeDetect.m"/>
      	  <caption>This is the Matlab code for the function EdgeDetect.</caption></figure><figure id="element-369"><media type="file/m" src="GaussianFilter.m"/>
      	  <caption>This is the Matlab code for the function GaussianFilter which works with EdgeDetect.</caption></figure>   
  </content>
  
</document>
