java - 如何模拟心电图(心电图)

时间:2014-04-19 08:43:38

标签: java random plot sensor graphing

我正在研究某种涉及模拟心电图(心电图)的项目。我是通过在间隔之间生成一些随机数并将该数据发送到另一个程序来分析和绘制它来实现的。但是,问题是在一个区间之间产生的随机数说[a,b]由java代码有很多方差,这意味着下一个生成的随机值与前一个数字有很大不同。我想要的是随机数的流量稍微变化,以便图表看起来平滑。此时,生成的图形非常尖锐,但我希望它是平滑的并且像真实的ECG图一样变化。

请帮我这样做。

Here is what I have got so far

这是代码

//setup ECG graph
        StdDraw.setXscale(0.0, 100.0);
        StdDraw.setYscale(0.0,200.0); 
        StdDraw.setPenColor(StdDraw.BLUE); 
        StdDraw.setPenRadius(0.0009);
        //generate random points between interval of range
        int t = 0; 

        int prevVal = 0; 
        int nextVal; 
        while(true){

            nextVal = range.getRandomValue(); 
            System.out.println(nextVal);

            StdDraw.point(prevVal, nextVal);
            StdDraw.line(t-1, prevVal, t, nextVal);

            StdDraw.show(100);

            prevVal = nextVal; 
            t = (t+1) % 100;
            if(t == 0){
                StdDraw.clear(); 

            }
        }

谢谢

1 个答案:

答案 0 :(得分:4)

为什么不尝试使用sin(t)函数调制随机信号:

long n = 0; 

double randomWeight = 0.5;

while(true) {

    nextVal = range.getRandomValue(); 

    double temp = AMPLITUDE*(randomWeight*((double)nextVal)+(1.0-randomWeight)*Math.sin(2.0*Math.PI*((double)n)*WIDTH_FACTOR));


    nextVal = (long)temp; 

    n++;

    System.out.println(nextVal);

    StdDraw.point(prevVal, nextVal);
    StdDraw.line(t-1, prevVal, t, nextVal);

    StdDraw.show(100);

    prevVal = nextVal; 
    t = (t+1) % 100;
    if(t == 0){
        StdDraw.clear(); 

}

这个想法是生成正弦波函数并为其添加一些随机噪声。 您可能希望将此噪声添加到方波中。我真的不太了解心电图的样子,但我想它必须受到心跳的控制。

修改

我刚检查过这些信号的样子: enter image description here

在我看来,由周期性尖峰中断的相对平坦的随机信号会给出更准确的模型:

long n = 0; 

while(true) {

    nextVal = range.getRandomValue(); 
    if(n % SPIKE_PERIOD == 0) nextVal = SPIKE_APLITUDE*nextVal;

    n++;


    System.out.println(nextVal);

    StdDraw.point(prevVal, nextVal);
    StdDraw.line(t-1, prevVal, t, nextVal);

    StdDraw.show(100);

    prevVal = nextVal; 
    t = (t+1) % 100;
    if(t == 0){
        StdDraw.clear(); 

}