working on code to segment an arbitrary envelope function