def testSimpleBeepScenario(self): # IGNORE------- FIRST--------- hiSampleData = [ 7, 9, 8, 2, 0, 1, 0, 2, 1, 0, 3, 8, 4, 1, 0, 1 ] loSampleData = [ -5, -7, -8, -9, -1, -1, -2, -1, 0, -8, -9, -9, -1, 0, -1, -1 ] # SECOND----------- IGNORE---- hiSampleData.extend([ 2, 6, 0, 9, 8, 2, 2, 0, 1, 8, 6, 9, 9 ]) loSampleData.extend([-4, -8, -9, -4, -6, -1, 0, -1, -1, -3, -6, -5, -8 ]) # offset it so it is not about 0 loSampleData = map(lambda x:x+100, loSampleData) hiSampleData = map(lambda x:x+100, hiSampleData) envelope = minMaxDataToEnvelopeData(loSampleData, hiSampleData) self.assertEquals(envelope, [12, 16, 16, 11, 1, 2, 2, 3, 1, 8, 12, 17, 5, 1, 1, 2, 6, 14, 9, 13, 14, 3, 2, 1, 2, 11, 12, 14, 17]) risingThreshold = 6 fallingThreshold = 3 minPulseDuration = 0 holdCount = 0 result = detectPulses(envelope, risingThreshold, fallingThreshold, minPulseDuration, holdCount) self.assertEquals(result, [10.5, 18.0]) holdCount = 1 result = detectPulses(envelope, risingThreshold, fallingThreshold, minPulseDuration, holdCount) self.assertEquals(result, [10.5, 18.0])
def testNoisySamplesScenario(self): risingThreshold = 7 fallingThreshold = 4 minPulseDuration = 2 holdCount = 1 # IGNORE- FIRST--- |noise| SECOND---------- IGNORE sampleData = [ 1, 8, 8, 0, 0, 0, 3, 8, 8, 7, 4, 1, 10, 1, 0, 7, 9, 1, 7, 9, 8, 3, 0, 0, 0, 8, 9 ] result = detectPulses(sampleData, risingThreshold, fallingThreshold, minPulseDuration, holdCount) self.assertEquals(result, [8.0, 17.5])
def testSimpleBeepScenario(self): # IGNORE------- FIRST--------- hiSampleData = [7, 9, 8, 2, 0, 1, 0, 2, 1, 0, 3, 8, 4, 1, 0, 1] loSampleData = [ -5, -7, -8, -9, -1, -1, -2, -1, 0, -8, -9, -9, -1, 0, -1, -1 ] # SECOND----------- IGNORE---- hiSampleData.extend([2, 6, 0, 9, 8, 2, 2, 0, 1, 8, 6, 9, 9]) loSampleData.extend( [-4, -8, -9, -4, -6, -1, 0, -1, -1, -3, -6, -5, -8]) # offset it so it is not about 0 loSampleData = map(lambda x: x + 100, loSampleData) hiSampleData = map(lambda x: x + 100, hiSampleData) envelope = minMaxDataToEnvelopeData(loSampleData, hiSampleData) self.assertEquals(envelope, [ 12, 16, 16, 11, 1, 2, 2, 3, 1, 8, 12, 17, 5, 1, 1, 2, 6, 14, 9, 13, 14, 3, 2, 1, 2, 11, 12, 14, 17 ]) risingThreshold = 6 fallingThreshold = 3 minPulseDuration = 0 holdCount = 0 result = detectPulses(envelope, risingThreshold, fallingThreshold, minPulseDuration, holdCount) self.assertEquals(result, [10.5, 18.0]) holdCount = 1 result = detectPulses(envelope, risingThreshold, fallingThreshold, minPulseDuration, holdCount) self.assertEquals(result, [10.5, 18.0])