Last active
September 12, 2018 14:08
-
-
Save ksasao/c23e60b41a4620b2697d091f10f28066 to your computer and use it in GitHub Desktop.
iPhoneで心拍を取るテスト。Pythonista 用。実行すると5秒後から5秒間測定を行います。仰向けになってiPhoneを胸の上に置き、息を止めてじっとしていてください。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''This script records your device's orientation (accelerometer data) for 5 seconds, and then renders a simple plot of the gravity vector, using matplotlib.''' | |
import motion | |
import matplotlib.pyplot as plt | |
from time import sleep | |
import console | |
def main(): | |
motion.start_updates() | |
sleep(0.2) | |
print('Capturing motion data...') | |
num_samples = 1000 | |
data = [] | |
sleep(5) | |
for i in range(num_samples): | |
sleep(0.005) | |
g = motion.get_gravity() | |
data.append(g) | |
motion.stop_updates() | |
print('Capture finished, plotting...') | |
data2 = [] | |
f = 5 | |
for i in range(num_samples-f): | |
u = 0 | |
for j in range(f): | |
u=u+data[i+j][2] | |
data2.append((data[i][2]-u/f)*5000) | |
x_values = [x*0.005 for x in range(num_samples-f)] | |
plt.plot(x_values, data2, 'R', lw=2) | |
plt.grid(True) | |
plt.xlabel('t') | |
plt.ylabel('G') | |
plt.gca().set_ylim([-1.0, 1.0]) | |
plt.legend() | |
plt.show() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment