import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',',dtype='int')
rawdata_microseconds = rawdata[:,0] / 1000000
rawdata_zacurate_output = rawdata[:,1]
rawdata_zacurate_sensor = rawdata[:,2]
rawdata_fab_sensor = rawdata[:,3]
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(rawdata_microseconds, rawdata_zacurate_output)
ax.set_xlabel('seconds')
ax.set_ylabel('SpO2 (%)')
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',',dtype='int')
rawdata_microseconds = rawdata[:,0] / 1000000
rawdata_zacurate_output = rawdata[:,1]
rawdata_zacurate_sensor = rawdata[:,2]
rawdata_fab_sensor = rawdata[:,3]
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(rawdata_microseconds, rawdata_zacurate_sensor, marker='o', linestyle='none', markersize=0.2, label='zacurate')
ax.plot(rawdata_microseconds, rawdata_fab_sensor, marker='o', linestyle='none', markersize=0.2, label='fab')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('ADC counts') # Add a y-label to the axes.
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',',dtype='int')
rawdata_microseconds = rawdata[80000:80500,0] / 1000000
rawdata_zacurate_output = rawdata[80000:80500,1]
rawdata_zacurate_sensor = rawdata[80000:80500,2]
rawdata_fab_sensor = rawdata[80000:80500,3]
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(rawdata_microseconds, rawdata_zacurate_sensor, marker='o', markersize=3, label='zacurate')
ax.plot(rawdata_microseconds, rawdata_fab_sensor, marker='o', markersize=3, label='fab')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('ADC counts') # Add a y-label to the axes.
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',',dtype='int')
rawdata_microseconds = rawdata[80030:80150,0] / 1000000
rawdata_zacurate_output = rawdata[80030:80150,1]
rawdata_zacurate_sensor = rawdata[80030:80150,2]
rawdata_fab_sensor = rawdata[80030:80150,3]
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(rawdata_microseconds, rawdata_zacurate_sensor, marker='o', markersize=5, label='zacurate')
ax.plot(rawdata_microseconds, rawdata_fab_sensor, marker='o', markersize=5, label='fab')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('ADC counts') # Add a y-label to the axes.
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',')
threshold = 0.1 #change percentage must be below this value to register a stable data point
prev_zacurate_sensor = 1 #previous sensor value for threshold calculation (starts at 1 to avoid divide-by-zero error)
counter = 0 #for averaging and checking for background
background_mintime = 5 #consecutive stable readings needed to indicate a background value
accumulator = np.zeros([2,1]) #for averaging
cleandata_zacurate_sensor_pulse_0 = np.zeros([2,0]) #output np.array for first pulse
cleandata_zacurate_sensor_pulse_1 = np.zeros([2,0]) #output np.array for second pulse
cleandata_zacurate_sensor_background = np.zeros([2,0]) #output np.array for background data
bucket = -1 #-1 for start (unknown bucket), 0 for pulse_0, 1 for pulse_1, 2 for background
for x in rawdata:
if abs((x[2] - prev_zacurate_sensor) / prev_zacurate_sensor) > threshold:
if counter > 0: #checks for repeated over-threshold changes
temp = np.array([accumulator[0] / counter, accumulator[1] / counter])
if counter > background_mintime:
cleandata_zacurate_sensor_background = np.append(cleandata_zacurate_sensor_background,temp,axis=1)
bucket = 2
elif bucket == 2:
cleandata_zacurate_sensor_pulse_0 = np.append(cleandata_zacurate_sensor_pulse_0,temp,axis=1)
bucket = 0
elif bucket == 0: # ignore background pulse between signal pulses
bucket = 0.5
elif bucket == 0.5:
cleandata_zacurate_sensor_pulse_1 = np.append(cleandata_zacurate_sensor_pulse_1,temp,axis=1)
bucket = 1
counter = 0
accumulator = np.zeros([2,1])
else:
counter += 1
accumulator[0] += x[0] / 1000000
accumulator[1] += x[2]
prev_zacurate_sensor = x[2]
print(cleandata_zacurate_sensor_background.shape)
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(cleandata_zacurate_sensor_pulse_0[0,:], cleandata_zacurate_sensor_pulse_0[1,:], label='pulse_0')
ax.plot(cleandata_zacurate_sensor_pulse_1[0,:], cleandata_zacurate_sensor_pulse_1[1,:], label='pulse_1')
ax.plot(cleandata_zacurate_sensor_background[0,:], cleandata_zacurate_sensor_background[1,:], label='background')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('ADC counts') # Add a y-label to the axes.
ax.set_title('Zacurate sensor')
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',')
threshold = 0.1 #change percentage must be below this value to register a stable data point
prev_zacurate_sensor = 1 #previous sensor value for threshold calculation (starts at 1 to avoid divide-by-zero error)
counter = 0 #for averaging and checking for background
background_mintime = 5 #consecutive stable readings needed to indicate a background value
accumulator = np.zeros([2,1]) #for averaging
cleandata_zacurate_sensor_pulse_0 = np.zeros([2,0]) #output np.array for first pulse
cleandata_zacurate_sensor_pulse_1 = np.zeros([2,0]) #output np.array for second pulse
cleandata_zacurate_sensor_background = np.zeros([2,0]) #output np.array for background data
bucket = -1 #-1 for start (unknown bucket), 0 for pulse_0, 1 for pulse_1, 2 for background
for x in rawdata:
if abs((x[2] - prev_zacurate_sensor) / prev_zacurate_sensor) > threshold:
if counter > 0: #checks for repeated over-threshold changes
temp = np.array([accumulator[0] / counter, accumulator[1] / counter])
if counter > background_mintime:
cleandata_zacurate_sensor_background = np.append(cleandata_zacurate_sensor_background,temp,axis=1)
bucket = 2
elif bucket == 2:
cleandata_zacurate_sensor_pulse_0 = np.append(cleandata_zacurate_sensor_pulse_0,temp,axis=1)
bucket = 0
elif bucket == 0: # ignore background pulse between signal pulses
bucket = 0.5
elif bucket == 0.5:
cleandata_zacurate_sensor_pulse_1 = np.append(cleandata_zacurate_sensor_pulse_1,temp,axis=1)
bucket = 1
counter = 0
accumulator = np.zeros([2,1])
else:
counter += 1
accumulator[0] += x[0] / 1000000
accumulator[1] += x[2]
prev_zacurate_sensor = x[2]
print(cleandata_zacurate_sensor_background.shape)
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(cleandata_zacurate_sensor_pulse_0[0,:1000], cleandata_zacurate_sensor_pulse_0[1,:1000], label='pulse_0')
ax.plot(cleandata_zacurate_sensor_pulse_1[0,:1000], cleandata_zacurate_sensor_pulse_1[1,:1000], label='pulse_1')
ax.plot(cleandata_zacurate_sensor_background[0,:1000], cleandata_zacurate_sensor_background[1,:1000], label='background')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('ADC counts') # Add a y-label to the axes.
ax.set_title('Zacurate sensor')
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',')
threshold = 0.1 #change percentage must be below this value to register a stable data point
prev_zacurate_sensor = 1 #previous sensor value for threshold calculation (starts at 1 to avoid divide-by-zero error)
counter = 0 #for averaging and checking for background
background_mintime = 5 #consecutive stable readings needed to indicate a background value
accumulator = np.zeros([2,1]) #for averaging
cleandata_zacurate_sensor_pulse_0 = np.zeros([2,0]) #output np.array for first pulse
cleandata_zacurate_sensor_pulse_1 = np.zeros([2,0]) #output np.array for second pulse
cleandata_zacurate_sensor_background = np.zeros([2,0]) #output np.array for background data
bucket = -1 #-1 for start (unknown bucket), 0 for pulse_0, 1 for pulse_1, 2 for background
for x in rawdata:
if abs((x[2] - prev_zacurate_sensor) / prev_zacurate_sensor) > threshold:
if counter > 0: #checks for repeated over-threshold changes
temp = np.array([accumulator[0] / counter, accumulator[1] / counter])
if counter > background_mintime:
cleandata_zacurate_sensor_background = np.append(cleandata_zacurate_sensor_background,temp,axis=1)
bucket = 2
elif bucket == 2:
cleandata_zacurate_sensor_pulse_0 = np.append(cleandata_zacurate_sensor_pulse_0,temp,axis=1)
bucket = 0
elif bucket == 0: # ignore background pulse between signal pulses
bucket = 0.5
elif bucket == 0.5:
cleandata_zacurate_sensor_pulse_1 = np.append(cleandata_zacurate_sensor_pulse_1,temp,axis=1)
bucket = 1
counter = 0
accumulator = np.zeros([2,1])
else:
counter += 1
accumulator[0] += x[0] / 1000000
accumulator[1] += x[2]
prev_zacurate_sensor = x[2]
# combine data sets and subtract background levels
normalized_zacurate = np.zeros([6,0])
counter2 = 0
for y in cleandata_zacurate_sensor_background.T:
counter2 += 1
if counter2 < cleandata_zacurate_sensor_pulse_0.shape[1] and counter2 < cleandata_zacurate_sensor_pulse_1.shape[1]:
temp2 = np.array([[y[0]],[cleandata_zacurate_sensor_pulse_0[1,counter2] - y[1]],[cleandata_zacurate_sensor_pulse_1[1,counter2] - y[1]],[0],[0],[0]])
normalized_zacurate = np.append(normalized_zacurate, temp2, axis=1)
# determine rolling minimum value and divide out
counter3 = 0 # index
averaging_period = 50
for z in normalized_zacurate.T:
counter3 += 1
if (counter3 < averaging_period):
normalized_zacurate[3,counter3] = normalized_zacurate[1,counter3] / np.amin(normalized_zacurate[1,0:counter3])
normalized_zacurate[4,counter3] = normalized_zacurate[2,counter3] / np.amin(normalized_zacurate[2,0:counter3])
normalized_zacurate[5,counter3] = normalized_zacurate[3,counter3] / normalized_zacurate[4,counter3]
elif (counter3 < normalized_zacurate.shape[1]):
normalized_zacurate[3,counter3] = normalized_zacurate[1,counter3] / np.amin(normalized_zacurate[1,(counter3 - averaging_period):counter3])
normalized_zacurate[4,counter3] = normalized_zacurate[2,counter3] / np.amin(normalized_zacurate[2,(counter3 - averaging_period):counter3])
normalized_zacurate[5,counter3] = normalized_zacurate[3,counter3] / normalized_zacurate[4,counter3]
normalized_zacurate[3,0] = 1
normalized_zacurate[4,0] = 1
normalized_zacurate[5,0] = 1
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(normalized_zacurate[0,:1000], normalized_zacurate[3,:1000], label='pulse_0')
ax.plot(normalized_zacurate[0,:1000], normalized_zacurate[4,:1000], label='pulse_1')
ax.plot(normalized_zacurate[0,:1000], normalized_zacurate[5,:1000], label='R')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('normalized value') # Add a y-label to the axes.
ax.set_title('Zacurate sensor')
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',')
threshold = 0.1 #change percentage must be below this value to register a stable data point
prev_zacurate_sensor = 1 #previous sensor value for threshold calculation (starts at 1 to avoid divide-by-zero error)
counter = 0 #for averaging and checking for background
background_mintime = 5 #consecutive stable readings needed to indicate a background value
accumulator = np.zeros([2,1]) #for averaging
cleandata_zacurate_sensor_pulse_0 = np.zeros([2,0]) #output np.array for first pulse
cleandata_zacurate_sensor_pulse_1 = np.zeros([2,0]) #output np.array for second pulse
cleandata_zacurate_sensor_background = np.zeros([2,0]) #output np.array for background data
bucket = -1 #-1 for start (unknown bucket), 0 for pulse_0, 1 for pulse_1, 2 for background
for x in rawdata:
if abs((x[2] - prev_zacurate_sensor) / prev_zacurate_sensor) > threshold:
if counter > 0: #checks for repeated over-threshold changes
temp = np.array([accumulator[0] / counter, accumulator[1] / counter])
if counter > background_mintime:
cleandata_zacurate_sensor_background = np.append(cleandata_zacurate_sensor_background,temp,axis=1)
bucket = 2
elif bucket == 2:
cleandata_zacurate_sensor_pulse_0 = np.append(cleandata_zacurate_sensor_pulse_0,temp,axis=1)
bucket = 0
elif bucket == 0: # ignore background pulse between signal pulses
bucket = 0.5
elif bucket == 0.5:
cleandata_zacurate_sensor_pulse_1 = np.append(cleandata_zacurate_sensor_pulse_1,temp,axis=1)
bucket = 1
counter = 0
accumulator = np.zeros([2,1])
else:
counter += 1
accumulator[0] += x[0] / 1000000
accumulator[1] += x[2]
prev_zacurate_sensor = x[2]
# combine data sets and subtract background levels
normalized_zacurate = np.zeros([6,0])
counter2 = 0
for y in cleandata_zacurate_sensor_background.T:
counter2 += 1
if counter2 < cleandata_zacurate_sensor_pulse_0.shape[1] and counter2 < cleandata_zacurate_sensor_pulse_1.shape[1]:
temp2 = np.array([[y[0]],[cleandata_zacurate_sensor_pulse_0[1,counter2] - y[1]],[cleandata_zacurate_sensor_pulse_1[1,counter2] - y[1]],[0],[0],[0]])
normalized_zacurate = np.append(normalized_zacurate, temp2, axis=1)
# determine rolling minimum value and divide out
counter3 = 0 # index
averaging_period = 150
for z in normalized_zacurate.T:
counter3 += 1
if (counter3 < averaging_period):
normalized_zacurate[3,counter3] = normalized_zacurate[1,counter3] / np.amin(normalized_zacurate[1,0:counter3])
normalized_zacurate[4,counter3] = normalized_zacurate[2,counter3] / np.amin(normalized_zacurate[2,0:counter3])
if (counter3 > 1):
normalized_zacurate[5,counter3] = np.amax(normalized_zacurate[3,0:counter3]) / np.amax(normalized_zacurate[4,0:counter3])
elif (counter3 < normalized_zacurate.shape[1]):
normalized_zacurate[3,counter3] = normalized_zacurate[1,counter3] / np.amin(normalized_zacurate[1,(counter3 - averaging_period):counter3])
normalized_zacurate[4,counter3] = normalized_zacurate[2,counter3] / np.amin(normalized_zacurate[2,(counter3 - averaging_period):counter3])
normalized_zacurate[5,counter3] = np.amax(normalized_zacurate[3,counter3 - averaging_period:counter3]) / np.amax(normalized_zacurate[4,counter3 - averaging_period:counter3])
normalized_zacurate[3,0] = 1
normalized_zacurate[4,0] = 1
normalized_zacurate[5,0] = 1
normalized_zacurate[5,1] = 1
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
#ax.plot(normalized_zacurate[0,:], normalized_zacurate[3,:], label='pulse_0')
#ax.plot(normalized_zacurate[0,:], normalized_zacurate[4,:], label='pulse_1')
ax.plot(normalized_zacurate[0,:], normalized_zacurate[5,:], label='R')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('normalized value') # Add a y-label to the axes.
ax.set_title('Zacurate sensor')
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',')
threshold = 0.1 #change percentage must be below this value to register a stable data point
prev_zacurate_sensor = 1 #previous sensor value for threshold calculation (starts at 1 to avoid divide-by-zero error)
counter = 0 #for averaging and checking for background
background_mintime = 5 #consecutive stable readings needed to indicate a background value
accumulator = np.zeros([2,1]) #for averaging
cleandata_zacurate_sensor_pulse_0 = np.zeros([2,0]) #output np.array for first pulse
cleandata_zacurate_sensor_pulse_1 = np.zeros([2,0]) #output np.array for second pulse
cleandata_zacurate_sensor_background = np.zeros([2,0]) #output np.array for background data
bucket = -1 #-1 for start (unknown bucket), 0 for pulse_0, 1 for pulse_1, 2 for background
for x in rawdata:
if abs((x[2] - prev_zacurate_sensor) / prev_zacurate_sensor) > threshold:
if counter > 0: #checks for repeated over-threshold changes
temp = np.array([accumulator[0] / counter, accumulator[1] / counter])
if counter > background_mintime:
cleandata_zacurate_sensor_background = np.append(cleandata_zacurate_sensor_background,temp,axis=1)
bucket = 2
elif bucket == 2:
cleandata_zacurate_sensor_pulse_0 = np.append(cleandata_zacurate_sensor_pulse_0,temp,axis=1)
bucket = 0
elif bucket == 0: # ignore background pulse between signal pulses
bucket = 0.5
elif bucket == 0.5:
cleandata_zacurate_sensor_pulse_1 = np.append(cleandata_zacurate_sensor_pulse_1,temp,axis=1)
bucket = 1
counter = 0
accumulator = np.zeros([2,1])
else:
counter += 1
accumulator[0] += x[0] / 1000000
accumulator[1] += x[2]
prev_zacurate_sensor = x[2]
# combine data sets and subtract background levels
normalized_zacurate = np.zeros([6,0])
counter2 = 0
for y in cleandata_zacurate_sensor_background.T:
counter2 += 1
if counter2 < cleandata_zacurate_sensor_pulse_0.shape[1] and counter2 < cleandata_zacurate_sensor_pulse_1.shape[1]:
temp2 = np.array([[y[0]],[cleandata_zacurate_sensor_pulse_0[1,counter2] - y[1]],[cleandata_zacurate_sensor_pulse_1[1,counter2] - y[1]],[0],[0],[0]])
normalized_zacurate = np.append(normalized_zacurate, temp2, axis=1)
# determine rolling minimum value and divide out
counter3 = 0 # index
averaging_period = 50
for z in normalized_zacurate.T:
counter3 += 1
if counter3 > averaging_period and counter3 + averaging_period < normalized_zacurate.shape[1]:
normalized_zacurate[3,counter3] = np.amin(normalized_zacurate[1,counter3-averaging_period:counter3+averaging_period])
normalized_zacurate[4,counter3] = np.amax(normalized_zacurate[1,counter3-averaging_period:counter3+averaging_period])
print(counter3)
print(counter4)
plot_min = averaging_period + 1
plot_max = normalized_zacurate.shape[1]-averaging_period
fig, ax = plt.subplots(figsize=(16,9), dpi=60)
ax.plot(normalized_zacurate[0,plot_min:plot_max], normalized_zacurate[1,plot_min:plot_max], label='pulse_0')
ax.plot(normalized_zacurate[0,plot_min:plot_max], normalized_zacurate[3,plot_min:plot_max], label='pulse_0_min')
ax.plot(normalized_zacurate[0,plot_min:plot_max], normalized_zacurate[4,plot_min:plot_max], label='pulse_0_max')
ax.set_xlabel('seconds') # Add an x-label to the axes.
ax.set_ylabel('normalized value') # Add a y-label to the axes.
ax.set_title('Zacurate sensor')
ax.legend()
import matplotlib.pyplot as plt
import numpy as np
rawdata = np.genfromtxt('../data/log_holdingbreath.csv', delimiter=',')
rawdata_seconds = rawdata[:,0] / 1000000
rawdata_zacurate_output = rawdata[:,1]
threshold = 0.1 #change percentage must be below this value to register a stable data point
prev_zacurate_sensor