Java - how to simulate an ECG (electrocardiogram)

I am working on a project that includes an ECG simulation (electrocardiogram). I do this by generating some random numbers between the intervals and sending this data to another program, analyzing and graphically displaying it. But the problem is that the random number generated between the intervals says that [a, b] in the java code have a large variance, that is, the next generated random value is very different from the previous number. I want the random number stream to change slightly so that the graph looks smooth. At this stage, the generated graph is very stabbing, but I want it to be smooth and change like a real ECG graph.

Please help me do this.

Here is what I have got so far

Here is the code

//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(); 

            }
        }

thank

+4
1

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(); 

}

. . , , , .

EDIT:

, : 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(); 

}
+4

Source: https://habr.com/ru/post/1537183/


All Articles