Final submission version. Added comments, added automatic threshold set, included TestScript_P1.m provided test script.