public void detectPulse(Record record) {

        double value = record.getValue();
        if (value > THRESHOLD) {
            if (this.isInPeak) {
                // set buffer values to 100 and clear
                for (Record bufferedRecord : this.buffer) {
                    bufferedRecord.setValue(100);
                    processHeartRate(bufferedRecord);
                }
                this.buffer.clear();
            }
            record.setValue(100);
            processHeartRate(record);
            this.isInPeak = true;
        } else {
            if (this.isInPeak && this.buffer.size() < PULSE_WIDTH) {
                buffer.add(record);
            } else if (isInPeak) {
                isInPeak = false;
                for (Record bufferedRecord : this.buffer) {
                    bufferedRecord.setValue(0);
                    processHeartRate(bufferedRecord);
                }
                buffer.clear();
            } else {
                record.setValue(0);
                processHeartRate(record);
            }
        }

    }