Monday, March 4, 2013

Breath Location

The last analysis interpretation task I want to post for now find the location of the breaths.


//===================~getLocation Task======================//
/*
The purpose of this task is to determine the 'location' of the breath. It can be listed as occuring anywhere from a single sensor up through 'everywhere'.

Information gathered includes:
1. The depth of the inspiration at the different sensors (not really sure what this is doing in this code)
2. Whether the breath is in a specific region or region(s) and what those region(s) are.

*/

~getLocation = Task({
inf.do({
  if(~breathArray.notNil, {
if(~breathArray[9] == 1, {
"there is an inspiration".postln; //now what i need to do is if there is an inspiration, i need to put the depth values into an array that i can reference later
~depthOfInspirationArray
[~depthAtZeroInspiration
  ~depthAtOneInspiration
  ~depthAtTwoInspiration
  ~depthAtThreeInspiration
  ~depthAtFourInspiration
  ~depthAtFiveInspiration];
"the depth of the sensors at inspiration is".postln;
~depthOfInspirationArray.postln;

 //----------------------------code to help check where the breath is---------------------------------//
//add numbers up for each group.
~upperSensorInhale = ~count1 + ~count5; //shoulder and side (upper)
~midSensorInhale = ~count2 + ~count3; //armpit and back (mid)
~lowerSensorInhale = ~count4 + ~count5; //low back and side (lower)
~frontSensorInhale = ~count0; //front
//depth for various regions....****this isn't yet actually used for anything!
~upperSensorDepth = ~depthAtOneInspiration + ~depthAtFiveInspiration;
~midSensorDepth = ~depthAtTwoInspiration + ~depthAtThreeInspiration;
~lowerSensorDepth = ~depthAtFourInspiration + ~depthAtFiveInspiration;
~frontSensorDepth = ~depthAtZeroInspiration;
//after adding up values, determine which group(s) win
//if uppersensors >= than mid and lower sensors, then upper sensor = 1, otherwise they = 0
if((~upperSensorInhale >= ~midSensorInhale).and(~upperSensorInhale >= ~lowerSensorInhale).and(~upperSensorInhale >= ~frontSensorInhale), { 
~upperSensorInhale = 1}, {~upperSensorInhale = 0});

//if mid sensors >= upper and lower then mid sensors are = 1, otherwise they = 0
if((~midSensorInhale >= ~upperSensorInhale).and(~midSensorInhale >= ~lowerSensorInhale).and(~midSensorInhale >= ~frontSensorInhale), { 
    ~midSensorInhale = 1}, {~midSensorInhale = 0});
//if low sensors >= mid and upper then low sensors = 1 otherwise, they = 0
if((~lowerSensorInhale >= ~upperSensorInhale ).and(~lowerSensorInhale >= ~midSensorInhale).and(~lowerSensorInhale >= ~frontSensorInhale), { 
    ~lowerSensorInhale = 1}, {~lowerSensorInhale = 0});
//if front sensor >= upper, mid and lower sensors, then low sensors = 1 otherwise, they = 0
if((~frontSensorInhale >= ~upperSensorInhale).and(~frontSensorInhale >= ~midSensorInhale).and(~frontSensorInhale >= ~lowerSensorInhale), {
    ~frontSensorInhale = 1}, {~frontSensorInhale = 0});

//create an array to store values and check where breath is...
~whereIsBreathArray = [~upperSensorInhale, ~midSensorInhale, ~lowerSensorInhale, ~frontSensorInhale];

//now an if statement (or series of if statements) to make a final determination of location of breath
if(~whereIsBreathArray.sum != 4, { //if the sum of the array is not 3, check to see if it is not equal to 2
if(~whereIsBreathArray.sum != 3, { //if the sum of the array is not 2, check more specifically where in the array the breath is
//check to see if breath is only in upper region
if(~whereIsBreathArray.sum != 2, {
if(~whereIsBreathArray[0] == 1, {
"breath is ONLY in upper region".postln;
~location0is = 1;}); //for gui
//check to see if breath is only in mid region
if(~whereIsBreathArray[1] == 1, {
"breath is ONLY in mid region".postln;
~location0is = 2});
//check to see if breath is only in lower region
if(~whereIsBreathArray[2] == 1, {
"breath is ONLY in low region".postln;
~location0is = 3;});
//check to see if breath is only in FRONT
if(~whereIsBreathArray[3] == 1, {
"breath is ONLY in FRONT".postln;
~location0is = 4;});

}, {
//otherwise figure out which two groups have breath

//check if breath is in upper and mid regions: shoulder, side, armpit and back
if(~whereIsBreathArray[0] + ~whereIsBreathArray[1] == 2, {
~location0is = 5;//for gui
~location1is = 5;//for gui
"two regions engaged.  they are: ".postln;
"UPPER and MID regions: SHOULDER, SIDE, ARMPIT AND BACK".postln});
//check if breath is in mid and low regions: ARMPIT, BACK, LOW BACK AND SIDE
if(~whereIsBreathArray[1] + ~whereIsBreathArray[2] == 2, {
~location0is = 6;
~location1is = 6;
"two regions engaged.  they are: ".postln;
"breath is in MID and LOW regions: ARMPIT, BACK, LOW BACK AND SIDE".postln});
//check if breath is in lower and front: LOW BACK AND SIDE AND FRONT
if(~whereIsBreathArray[2] + ~whereIsBreathArray[3] == 2, {
~location0is = 7;
~location1is = 7;
"two regions engaged.  they are: ".postln;
"breath is in LOW BACK, SIDE AND FRONT".postln});
//check if breath is in upper and low regions: shoulder and side, low back and side
if(~whereIsBreathArray[0] + ~whereIsBreathArray[2] == 2, {
~location0is = 8;
~location1is = 8;
"two regions engaged.  they are: ".postln;
"breath is in UPPER and LOW regions: shoulder and low back and side".postln});
//check if breath is in armpit and back and front
if(~whereIsBreathArray[1] + ~whereIsBreathArray[3] == 2, {
~location0is = 9;
~location1is = 9;
"two regions engaged.  they are: ".postln;
"breath is in ARMPIT AND BACK AND FRONT".postln});
//check if breath is in SHOULDER AND SIDE AND FRONT
if(~whereIsBreathArray[0] + ~whereIsBreathArray[3] == 2, {
~location0is = 10;
~location1is = 10;
"two regions engaged.  they are: ".postln;
"breath is in SHOULDER AND SIDE AND FRONT".postln});
});
}, {
//make if statements regarding ==3 ^%&^%^&%^&%&^^
if(~whereIsBreathArray[0] + ~whereIsBreathArray[1] + ~whereIsBreathArray[2] == 3, {
~location0is = 11;
"three regions engaged".postln;
"they are upper, mid and lower: shoulder, side, armpit, back, low back and side".postln});
if(~whereIsBreathArray[0] + ~whereIsBreathArray[2] + ~whereIsBreathArray[3] == 3, {
~location0is = 12;
"three regions engaged".postln;
"they are upper,lower, and front: shoulder, side, low back and side, front".postln});
if(~whereIsBreathArray[1] + ~whereIsBreathArray[2] + ~whereIsBreathArray[3] == 3, {
~location0is = 13;
"three regions engaged".postln;
"they are mid and lower and front: armpit, back, low back and side and front".postln});
if(~whereIsBreathArray[0] + ~whereIsBreathArray[1] + ~whereIsBreathArray[3] == 3, {
~location0is = 14;
"three regions engaged".postln;
"they are upper, mid and front: shoulder, side, armpit, back and front".postln});
}); 
}, { 
~location0is = 15;
"breath is everywhere".postln});
    }, {

 //I neglected to explore location of expiration...I think that's okay
if(~breathArray[9] == -1, { 
~depthOfExhalationArray = [
~depthAtZeroExhalation
~depthAtOneExhalation
~depthAtTwoExhalation
~depthAtThreeExhalation
~depthAtFourExhalation
~depthAtFiveExhalation];
"the depth of the sensors at exhalation is ".post;
~depthOfExhalationArray.postln;
//add numbers up for each group.
~upperSensorExhale = ~count1 + ~count5; //shoulder and side (upper)
~midSensorExhale = ~count2 + ~count3; //armpit and back (mid)
~lowerSensorExhale = ~count4 + ~count5; //low back and side (lower)
~frontSensorExhale = ~count0; //front
//depth for various regions....****this isn't yet actually used for anything!
~upperSensorExDepth = ~depthAtOneExhalation + ~depthAtFiveExhalation;
~midSensorExDepth = ~depthAtTwoExhalation + ~depthAtThreeExhalation;
~lowerSensorExDepth = ~depthAtFourExhalation + ~depthAtFiveExhalation;
~frontSensorExDepth = ~depthAtZeroExhalation;
});
});
});
0.1.wait;
});

});

Apologies for the lack of formatting...don't have the time to try to fix it today.  
The next subjects I will tackle have to do with generating sound and mapping the analysis of the sensor data to sonic output.  

No comments:

Post a Comment