I invented an algorithm to quantify sleep/wake in 1 sec epochs (not stage) back in 1989, called z-ratio. We published in 1990 and have it all posted at www.z-eeg.com. I opened it to the open-source community then and still do. Please ask me anything.
I sit on the Scoring Manual Committee of the American Academy of Sleep Medicine as well as on the Inter-Scorer Reliability Committee.
It is my opinion that we should not make electronic versions of a categorical system (sleep staging) that was borne out of need to collapse huge datasets of paper recordings. The data we house contains all manner of useful information and sleep staging, being the gross 30 second categorizing process, is truly a harbinger of old thinking. We need to turn our talents into pushing the envelope and thinking more fluidly about sleep and wake, and not relegate them to artificially constructed 30 second epochs.