trying to piece together some legacy code for slow wave detection