2014年7月15日 星期二

Finding Peak and Valley with 1st Derivative



    
Looks like need some threshold to eliminate small noise bug as the right photo...

 
       ...
      //Randomize the sample as input
      int v = (int)random(-40, 40);
      a+=0.2; A = (int) (80 + sin(a) * (v+50)); //add sine wave
   
      stroke(100, 100, 100);
      line(lastXPos, lastA,   xPos, A); //draw gray samples------------------------------------

      //smooth it
      B = smooth(A, 0.9, B);    
   
      //get 1st derivative
      C = B - lastB;                   //  f''(x) =  f(x) - f(x-1);
      C = (C + lastC) >> 1;        // some easy smooth
         
      stroke(250, 100, 100);
      line(lastXPos, 100+lastB,   xPos, 100+B);          //draw smoothed samples-------------
      line(lastXPos+1, 100+lastB,   xPos+1, 100+B);

      stroke(100, 100, 250);
      line(lastXPos, 400+(lastC*8),   xPos, 400+(C*8));//draw 1st derivatives  --------------
      if ((C*lastC) <= 0) {
        //f'(x) changed; when (f'(x)>0, f'(x-1)<0) or (f'(x)<0, f'(x-1)>0) or f'(x)=0 or f'x(x-1)=0    
        if (lastC >0)  {//found valley, draw line------
           stroke(40,40, 60);
           line(xPos, 400, xPos, 200);
           }
        if (lastC <0)  {//found peak, draw line-------
           stroke(80,80, 120);
           line(xPos, 400, xPos, 150);
           }
        }
 
      lastA = A;           //store current value for next iteration
      lastB = B;
      lastC = C;
   
      lastXPos = xPos; //move forward
      ...
Change random samples into Perlin noise

2014年7月4日 星期五

SI1143 Heartbeat Pulse Evaluate

Arduino reading
SI1143 setup
Processing Arduino SI1143 red data (baud:57600, samples:10)
After the SI1143 carefully setup, the total red light (IR+visible) data send to Processing for drawing, looks like finger tip is the best monitor place...
Processing red data w/ HRV (baud:115200, samples:2)

















































Processing red data w/ HRV (baud:115200, samples:1)
Improved one read from 2.5ms to 0.9ms, w/ some beers... (samples:4)










2014年7月3日 星期四

SI1143 Evaluate:Ambient Light, Proximity, Temperature


As default setup,
LED current sunk: 0x01, ~10cm stable detection
LED current sunk: 0x0F, ~30cm+ stable detection



...
  write_reg(HW_KEY, 0x17); 
  //0x0F:30cm detection, 0x01:10cm dectection
  write_reg(PS_LED21,0xFF); 
  write_reg(PS_LED3, 0x0F); 
  //Enable AUX as well
  param_set(CHLIST,0b01010111);
...

2014年7月2日 星期三

2014年7月1日 星期二

Hack Arduino Leonardo RX/TX LED


Use all LED on the Arduino Leonardo

int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);       
  }

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  RXLED1;
  TXLED1;
  delay(300);               // wait for a second
  
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  RXLED0;
  TXLED0;
  delay(300);               // wait for a second
}