A fast and easy solution
I know this thread has been dead for several months, but Frisbeet pointed it out to me, and I thought I'd provide an easy way to accomplish this, without going into the discrete behind it.
This works great if you have access to Matlab, a good TI, or some other...