You can use the vanilla kernel from kernel.org or install the linux-source package from the Ubuntu repository. I used the latter as it also has the Ubuntu specific patches.
For the compilation process this guide is the best.
After compile you will find that the sound on your compiled kernel does not work and the nvidia ( or ATI ) drivers are also not detected. To make this right just follow the guides below::
For alsa drivers, install the alsa-source package extract the archive and then give the following commands as root.
# ./configure --with-kernel=dir #where dir = your kernel source directory
# make install-modules
If for some reason this fails, check these pages.
Getting the nvidia drivers working in the compiled kernel was a royal pain for me. May be I was googling for the wrong things. Anyways, I finally found the answer. Just follow this guide and you will have the nvidia drivers installed and running on your compiled kernel just fine.
I was also able to get this guide for installing ATI drivers from source. Don’t know if this works or not. If anyone does try it, please comment about its validity.