心率算法2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package test
 
import java.io.Closeable
import java.io.PrintStream
 
class HeartUtils {
    private  val size = 256
    private  val sizeX = 255
    /**
     * 原始数据
     */
    private val src = FloatArray(size)
 
    private val mSrc = FloatArray(size)
    private var nIndex =240
    private var sIndex =137
    private var mIndex =125
    private var lIndex =0
 
    private val line = FloatArray(size)
 
 
    private val absSub = FloatArray(size)
    private val sm32 = Smooth32()
    private val t=CMidXFilter()
 
    var c = PrintStream("d:/c.txt")
    var d = PrintStream("d:/d.txt")
    var s = PrintStream("d:/s.txt")
    var o = PrintStream("d:/o.txt")
    private var lastPos = 0
    private  var maxPos = 0
    private var maxValue = 0f
    private val maxV = MaxVFiter()
    private var running = false
    private var index = 0
    private var flag = 0;
    fun init(v:Float):Int {
        src[sIndex] = v
 
        val m = sm32.init(v)
        mSrc[mIndex] = m
        val a = kotlin.math.abs(src[mIndex] - m)
        absSub[mIndex] = a
        line[lIndex] = t.init(a)
 
        c.println(absSub[nIndex])
        d.println(line[nIndex])
        s.println(src[nIndex])
        var running = line[nIndex] < (absSub[nIndex])
        if (running) {
            flag = 50
        }
        flag--
        if (running || flag > 0) {
            if (!this.running) {
                this.running = true
                maxV.maxPos = index
                maxV.maxValue = absSub[nIndex]
            } else {
                maxV.init(index, absSub[nIndex])
            }
 
        } else {
            if (this.running) {
                this.running = false
                maxV.maxValue = 0f
                this.lastPos = maxV.maxPos
                o.println(this.lastPos)
            }
        }
        index++
        sIndex=add(sIndex,size)
        mIndex=add(mIndex,size)
        lIndex=add(lIndex,size)
        nIndex=add(nIndex,size)
        return 0
    }
    private inline fun  add(x:Int, size:Int):Int{
        val r=x+1
        return if(r==size) 0 else r
    }
 
}