test_new_spad_3


test of new spad process
/**
 * Macro for data evaluation on PhotosynQ.org
 * by: David M. Kramer
 * created: 2017-06-21 @ 10:36:29
 */


/*
light_1 = 530 nm top
light_2 = 650 nm top
light_3 = 605 nm top
light 4 = blue top
light_5 = 940 nm top

light_9 = 940 nm bottom
light_7 =  650 bottom
light_8 = 850 nm bottom
light 9 = 730 nm bottom
light 10 = 880 nm bottom
*/

// Define the output object here
var output = {};

// Check if the key time exists in json
if (json.time !== undefined){

	// Add key time and value to output
	output.time = json.time;
}

var number_spads=2;
var number_lights=5;
var s = new Array(number_lights);

for (var i=1; i< number_spads; i++){
output["t_"]=json.set[i].data_raw;
}

for (var i=1; i< number_lights; i++){
	s[j]=0;
}

for (var j=1; j<number_lights; j+1){
	for (var i=1; i< number_spads; i++){
  		s[j]+=json.set[i].data_raw[i][j];
    }
}

/*
for (var j; j<number_lights; j+1){
	output["sum s " + j]=s[i];
}

/*
var i_sample = new Array(number_spads-1);
var i_ref = new Array(number_spads-1);
var spad_out = new Array(number_spads-1);

var sample_led=2;
var ref_led=3;
var num_pulses = 10;
var offset=100;

//var i_1_3_0=MathMEAN(json.set[1].data_raw.slice(1,9));

for (var i=1; i< number_spads; i++){
	i_ref[i-1]=MathMEAN(json.set[i].data_raw.slice((ref_led)*num_pulses,(ref_led)*num_pulses+1));
	i_sample[i-1]=MathMEAN(json.set[i].data_raw.slice((sample_led)*num_pulses,(sample_led+1)*num_pulses));
	spad_out[i-1]=MathROUND(MathLOG(i_ref[i-1]-offset)-MathLOG(i_sample[i-1]-offset), 2);
}
output.i_ref=i_ref;
output.i_sample=i_sample;
output.spad_out=spad_out;

output.spad_out=spad_out.join(",");


/*
var i_1_3_0=MathMEAN(json.set[1].data_raw.slice(1,9));
var i_2_3_0=MathMEAN(json.set[1].data_raw.slice(11,19));
var i_3_3_0=MathMEAN(json.set[1].data_raw.slice(21,29));
var i_6_1_0=MathMEAN(json.set[1].data_raw.slice(31,39));
var i_7_1_0=MathMEAN(json.set[1].data_raw.slice(41,49));

var i_1_3=MathMEAN(json.set[2].data_raw.slice(0,9));
var i_2_3=MathMEAN(json.set[2].data_raw.slice(11,19));
var i_3_3=MathMEAN(json.set[2].data_raw.slice(21,29));
var i_6_1=MathMEAN(json.set[2].data_raw.slice(31,39));
var i_7_1=MathMEAN(json.set[2].data_raw.slice(41,49));

var DA_1_3=MathLOG(i_1_3_0/i_1_3);
var DA_2_3=MathLOG(i_2_3_0/i_2_3);
var DA_3_3=MathLOG(i_3_3_0/i_3_3);
var DA_6_1=MathLOG(i_6_1_0/i_6_1);
var DA_7_1=MathLOG(i_7_1_0/i_7_1);

output.DA_1_3=DA_1_3;
output.DA_2_3=DA_2_3;
output.DA_3_3=DA_3_3;
output.DA_6_1=DA_6_1;
output.DA_7_1=DA_7_1;

var DA_2_3=MathLOG(i_2_3_0/i_2_3);
var DA_3_3=MathLOG(i_3_3_0/i_3_3);
var DA_6_1=MathLOG(i_6_1_0/i_6_1);
var DA_7_1=MathLOG(i_7_1_0/i_7_1);


var DA_array=[DA_1_3,DA_2_3,DA_3_3,DA_6_1,DA_7_1];
output.DA_array=DA_array;



var i_1_3=MathMEAN(json.set[3].data_raw.slice(0,9));
var i_2_3=MathMEAN(json.set[3].data_raw.slice(11,19));
var i_3_3=MathMEAN(json.set[3].data_raw.slice(21,29));
var i_6_1=MathMEAN(json.set[3].data_raw.slice(31,39));
var i_7_1=MathMEAN(json.set[3].data_raw.slice(41,49));

var DA_1_3=MathLOG(i_1_3_0/i_1_3);
var DA_2_3=MathLOG(i_2_3_0/i_2_3);
var DA_3_3=MathLOG(i_3_3_0/i_3_3);
var DA_6_1=MathLOG(i_6_1_0/i_6_1);
var DA_7_1=MathLOG(i_7_1_0/i_7_1);

output.DA_1_3_2=DA_1_3;
output.DA_2_3_2=DA_2_3;
output.DA_3_3_2=DA_3_3;
output.DA_3_3_2=DA_3_3;
output.DA_6_1_2=DA_6_1;
output.DA_7_1_2=DA_7_1;

var DA_1_3_2=MathLOG(i_2_3_0/i_2_3);
var DA_2_3_2=MathLOG(i_2_3_0/i_2_3);
var DA_3_3_2=MathLOG(i_3_3_0/i_3_3);
var DA_6_1_2=MathLOG(i_6_1_0/i_6_1);
var DA_7_1_2=MathLOG(i_7_1_0/i_7_1);

var DA_array_2=[DA_1_3_2,DA_2_3_2,DA_3_3_2,DA_6_1_2,DA_7_1_2];
//output.DA_array_2=DA_array_2;

var number_leds=5;
var number_spads=5;
var leds=[1,2,3,6,7];
var lambda=[535,650,590,940,655];            
var start_pt=[1,101,201,301,401];
var end_pt=[91,191,291,391,491];
var spad_val=[7.9,15,30.3,24.9];

var ttp = new Array(number_spads);
for (var i = 0; i < number_leds; i++) {
  ttp[i] = new Array(number_spads);
  	for (var j = 0; j < number_leds; j++) {
     ttp[i][j]=i*j; 
    }
}
for (i = 0; i < number_leds; i++) {
	for (j = 0; j < number_spads; j++) {      	
  	  i_zero=MathMEAN(json.set[1].data_raw.slice(start_pt[j],end_pt[j]));
  	  i_l=MathMEAN(json.set[i+1].data_raw.slice(start_pt[j],end_pt[j]));
	  a=MathLOG(i_zero/i_l);
      ttp[j][i]=a;  
    }
}

var spad_outputs_1 = new Array(number_spads);
for (j = 0; j < number_spads; j++) { 
  spad_outputs_1[j]=ttp[2][j] - ttp[3][j];
}

output.so=spad_outputs_1;

var spad_outputs_2 = new Array(number_spads);
for (j = 0; j < number_spads; j++) { 
  spad_outputs_2[j]=ttp[0][j] - ttp[3][j];
}

output.so_2=spad_outputs_2;


var spad_outputs_3 = new Array(number_spads);
for (j = 0; j < number_spads; j++) { 
  spad_outputs_3[j]=ttp[4][j] - ttp[3][j];
}

output.so_3=spad_outputs_3;



//output.trial=ttp[3];
//for (i = 0; i < number_spads; i++) {
//	output["res"+i]=ttp[i];
//}

for (i = 0; i < number_leds; i++) {
	output["delta_A_"+lambda[i]]=ttp[i]; //.slice(1,5);
	//output["delta_A_"+i]=ttp[i];
}


output.spads=spad_val;

//output.DA1=ttp[2];

//output.d530=ttp[1];

/*
var d=0.0;
var c=(66.5); //(2*45.6);
var i_650_0=MathMEAN(json.set[1].data_raw.slice(0,90));
var i_940_0=MathMEAN(json.set[1].data_raw.slice(100,190));
output.i_650_0=i_650_0;
output.i_940_0=i_940_0;


i_650=MathMEAN(json.set[5].data_raw.slice(0,99));
i_940=MathMEAN(json.set[5].data_raw.slice(100,199));
var i_650_black=0; //i_650;
var i_940_black=0; //i_940;
output.i_650_black=i_650;
output.i_940_black0=i_940;

var s=1;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.trace_1=json.set[1].data_raw;

//spad=-1*MathLOG(T_650);

output.T_650_1=T_650;
output.T_940_1=T_940;
output.spad1=spad;
output.trace_1=json.set[s].data_raw;

var s=2;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));

output.T_650_2=T_650;
output.T_940_3=T_940;
//spad=-1*MathLOG(T_650);

output.spad2=spad;
output.trace_2=json.set[2].data_raw;

var s=3;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
var spad=(41/62.0)*100*MathLOG(((i_650_0)/(i_650))/((i_940_0-i_94_black0)/(i_940-i_94_black0)));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);

//T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_3=T_650;
output.T_940_3=T_940;
//spad=-1*MathLOG(T_650);

output.spad3=spad;
output.trace_3=json.set[s].data_raw;


var s=4;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_4=T_650;
output.T_940_4=T_940;
//spad=-1*MathLOG(T_650);

output.spad4=spad;
output.trace_4=json.set[s].data_raw;

var s=5;

var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_5=T_650;
output.T_940_5=T_940;
//spad=-1*MathLOG(T_650);

output.spad5=spad;
output.trace_5=json.set[s].data_raw;


var s=6;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));

output.T_650_6=T_650;
output.T_940_6=T_940;
//spad=-1*MathLOG(T_650);

output.spad6=spad;
output.trace_6=json.set[s].data_raw;


var s=7;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_7=T_650;
output.T_940_7=T_940;
//spad=-1*MathLOG(T_650);
output.spad7=spad;
output.trace_7=json.set[s].data_raw;


var s=8;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));
T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);

output.T_650_8=T_650;
output.T_940_8=T_940;
//spad=-1*MathLOG(T_650);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.spad8=spad;
output.trace_8=json.set[s].data_raw;

var s=9;
var i_650=MathMEAN(json.set[s].data_raw.slice(0,99));
var i_940=MathMEAN(json.set[s].data_raw.slice(100,199));

T_650=(i_650-i_650_black)/(i_650_0-i_650_black);
T_940=(i_940-i_940_black)/(i_940_0-i_940_black);
spad=c*(d*MathLOG(T_940)-MathLOG(T_650));
output.T_650_9=T_650;
output.T_940_9=T_940;
//spad=-1*MathLOG(T_650);

output.spad9=spad;
// Return data
output.trace_9=json.set[s].data_raw;
*/

return output;
{
  "time": "1498155710240",
  "device_name": "MultispeQ",
  "device_version": "1",
  "device_id": "01:12:53:21",
  "device_battery": 40,
  "device_firmware": 1.18,
  "sample": [
    [
      {
        "time": "1498155710240",
        "light_intensity_raw": 0,
        "data_raw": [

        ],
        "protocol_id": 1,
        "set": [
          {
            "time": "1498155710240",
            "blank:": "blank"
          },
          {
            "time": "1498155710250",
            "data_raw": [
              50266,
              51,
              53031,
              51078,
              2507,
              50299,
              50,
              53031,
              51082,
              2516,
              50308,
              51,
              53031,
              51095,
              2511,
              50278,
              49,
              53038,
              51101,
              2510,
              50310,
              46,
              53030,
              51083,
              2511,
              50278,
              51,
              53023,
              51082,
              2506,
              50323,
              49,
              53028,
              51101,
              2510,
              50274,
              52,
              53023,
              51086,
              2517,
              50300,
              51,
              53030,
              51081,
              2511,
              50299,
              53,
              53019,
              51102,
              2507,
              50268,
              51,
              53023,
              51087,
              2509,
              50307,
              51,
              53024,
              51078,
              2510,
              50274,
              50,
              53029,
              51111,
              2512,
              50283,
              51,
              53019,
              51112,
              2507,
              50255,
              51,
              53020,
              51098,
              2507,
              50275,
              53,
              53020,
              51097,
              2514,
              50325,
              48,
              53015,
              51114,
              2515,
              50287,
              51,
              53015,
              51086,
              2507,
              50273,
              49,
              53012,
              51099,
              2513,
              50323,
              50,
              53023,
              51099,
              2514
            ]
          },
          {
            "time": "1498155713107",
            "data_raw": [
              50290,
              54,
              53019,
              51083,
              2509,
              50291,
              51,
              53021,
              51091,
              2515,
              50289,
              53,
              53021,
              51108,
              2515,
              50312,
              49,
              53016,
              51108,
              2511,
              50240,
              53,
              53007,
              51087,
              2508,
              50309,
              54,
              53019,
              51090,
              2513,
              50306,
              52,
              53011,
              51109,
              2511,
              50311,
              49,
              53020,
              51110,
              2509,
              50293,
              56,
              53015,
              51107,
              2507,
              50309,
              53,
              53014,
              51091,
              2507,
              50321,
              52,
              53019,
              51106,
              2516,
              50298,
              47,
              53021,
              51125,
              2511,
              50317,
              53,
              53009,
              51103,
              2506,
              50311,
              51,
              53007,
              51101,
              2512,
              50301,
              51,
              53019,
              51087,
              2514,
              50289,
              47,
              53023,
              51087,
              2510,
              50277,
              57,
              53029,
              51089,
              2506,
              50285,
              48,
              53021,
              51071,
              2509,
              50279,
              51,
              53010,
              51100,
              2509,
              50281,
              47,
              53023,
              51087,
              2509
            ]
          }
        ]
      }
    ]
  ],
  "app_os": "darwin-x64",
  "app_name": "PhotosynQ",
  "app_version": "0.0.11-DMK",
  "app_device": "x64",
  "location": [
    "42.7223740",
    "-84.4746367"
  ],
  "time_offset": "America/Detroit",
  "ConsoleMacro": "354"
}
Dave in cap img 4615
Created by

David M. Kramer


Protocol connections:
0
Latest Update:
Jun 2017