Highlights

Showing posts with label Programming. Show all posts

ECG:Coding

By : Noctis King
A new version of 

collection heart rate program

      In this week, we updated and changed the collection and graphing program. this new program could graph and calculated the heart rate more accurately. The reason why calculated more accurately than last one because this program used the "moving average" theory to calculate the heart rate. 
      The last one just use a some if{} sentences to compare, count and find the gaps between one peak and another. So it would make the heart rate very unstable and disordered. 
      However, this new program was used the "moving average" theory to calculate and count to find out the correct time between two peaks. It not only find one but also find two gaps. By using two data to calculate the heart rate would more accurately than only use one.
      The new program would collect enough sample data first and calculated the biggest range from those data. Then, the program would scale those data and made than easy to calculate and compared.
      After scaling the data, the program would begin to filter the data to ready for computing the heart rate. 
      Computing the heart rate was the most important part in the program. The program would find the peak and minima value from the data which after filter again. Then, it would begin to find three successive peaks. After a series judge, save three successive peaks, then, used the "moving average" theory to calculate the heart rate. 
      The program would still looping the calculate the heart rate until the user close it.
    



ECG: Coding

By : Noctis King

The program of collection and graphing data

    This program ran on the Arduino and used to collect and graphing the heart rate data and calculated the BPM (heart rate/minute).
    There were three parts of this program: the collecting part, graphing part and calculating part. The collecting part was the most important part in these parts, because the data which collected from this part was necessary from next two part.
    The program would use the ECG which connected on the Arduino to detect the heart beat from the user. The user can set the different port if they wanted to change the port of ECG;
    After the program got the real-time data, it would start the graphing and calculating.
    In the graphing part, the program would group the heart beat on a new window.
    In the calculating part, the program would find out the data of changing and judging them weather a heart beat and counted the number of heart beat to calculated the BPM.

import processing.serial.*;

Serial myPort; 
int val, screen_increment, old_x=0, old_y=0;  
String inString;  
int lf = 10; 
double bpm,t,lbpm;
int lval=510;
void setup() 
{

  size(displayWidth-100, 1000);  //set the size of window
  
  String portName = Serial.list()[0]; //the port of input
  println(Serial.list());
  
  myPort = new Serial(this, portName, 115200);
  myPort.bufferUntil(lf);
  background(0,0,0);//the color of background of window
}

void draw()
{

}

void serialEvent(Serial myPort) { 

  inString = myPort.readString();
  inString = trim(inString);
  val = int(inString);//get the value of rate
  strokeWeight(5);
  stroke(255, 255, 255);
  println(val);
  
  line(old_x, old_y, screen_increment, 1000-val); //graph the hate rate
  
  old_x = screen_increment;
  old_y = 1000-val;
  
  screen_increment=screen_increment+2;
  if(screen_increment>(displayWidth-100))
  {
    background(0,0,0); 
    screen_increment=-50; 
  old_x = -50;
  old_y = 0;
  }
  if(val-lval>7) //calculate the BPM
  {
    t=t+1;
    lval=val;
  }
  if(val<lval)
  {
    lval=val;
    t=t+1;
  }
  if(val-lval>5)
  {
    bpm=60/(0.015*t);
    t=0;
  }
  
  if (bpm<130 && lbpm-bpm<40)
  {
  text(bpm+ "                                      BPM",600,200);
  //println(bpm);
  lbpm=bpm;
  }
}



Program: Accelerometer

By : Noctis King

The program of LEDs and Accelerator

    In this week, our group made a monitor by using LEDs to react the change of accelerator.
    Now, we will show and explain how this program work.


const int groundpin = 18;             // analog input pin 4 -- ground
const int powerpin = 19;              // analog input pin 5 -- voltage
const int xpin = A0;                  // x-axis of the accelerometer
const int ypin = A1;                  // y-axis
const int zpin = A2;                  // z-axis (only on 3-axis models)
int ledx=13;                          // the pin of x-axis LED
int ledy=10;                          // the pin of y-axis LED
int ledz=4;                           // the pin of z-axis LED

void setup()
{
  // initialize the serial communications:
  Serial.begin(9600); // set the data rate in bits per second
  
  //initialize the digital pin as an output.
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH); 
  pinMode(ledx, OUTPUT); 
  pinMode(ledy,OUTPUT); 
  pinMode(ledz,OUTPUT); 
}

void loop()
{
  // set the initial value of accelerator
  int ax = analogRead(xpin); // the initial value of x-axis
  int ay = analogRead(ypin); // the initial value of y-axis
  int az = analogRead(zpin); // the initial value of z-axis
  
  while (true) // loop, tracking and reacting the change 
  {
    int Tax = analogRead(xpin); // reading the x-axis value after changing
    // determining the changing margin of x-axis' value 
    // if value change bigger than 50, the LED will blink
    // if not, it will closs
    if (abs(Tax - ax) > 50)  
    {
      digitalWrite(ledx, HIGH); 
    }
    else
    {
      digitalWrite(ledx, LOW);
    }
    int Tay = analogRead(ypin);
    if (abs(Tay - ay) > 50)
    {
      digitalWrite(ledy, HIGH);
    }
    else
    {
      digitalWrite(ledy, LOW);
    }
    int Taz = analogRead(zpin);
    if (abs(Taz - az) > 50)
    {
      digitalWrite(ledz, HIGH);
    }
    else
    {
      digitalWrite(ledz, LOW);
    }
  }
  
  
  // delay before next reading:
  delay(100);
}

- Copyright © 2013 Group 106-11 - Date A Live - Powered by Blogger - Designed by Johanes Djogan -