There is a good tutorial on the Sobel algorithm at: [[1]]. He also wrote source code to read a bmp file as well as the actual code performing the Sobel algotihm [[2]]. The site is a little old so I have also uploaded a version here.