├── README.md ├── pedometer.py ├── readme for video.txt └── sensor_data.ino /README.md: -------------------------------------------------------------------------------- 1 | # Pedometer 2 | 1 Sensor 3 | 4 | We attempted to collect data using Gyroscope within the Inertial Measurement Unit (IMU). 5 | 6 | 2 Location 7 | 8 | We assumed that we use the pedometer as a smartphone and we mimic the scenario when a walker holds their smartphone to walk. 9 | Specifically, human can have various activities with their smartphones (i.e., swinging hands, 10 | device in the trousers’ pockets, standing and typing). This essence can largely distinguish it 11 | from the pedometer for wearables/ smartwatch/ glasses, whose location is unitary and fixed. 12 | For example, using smartphone to type can also cause jitters. 13 | To make our problem clearer, we attempt to classify the following scenarios except counting 14 | steps: 15 | 1. Walking when holding the smartphone 16 | 2. Standing and typing/ Standing 17 | 18 | In order to classify activities based on both time domain and frequency domain features 19 | extracted from sensory data, we used fast fourier transformation (FFT) to extract the clustering 20 | features. 21 | In order to let the data update when the user is walking or standing, we used the sliding window 22 | to collect the data every 1.2s and fit the algorithm for the previous 1.2 seconds 23 | 24 | In order to increase the step count accuracy, we choose 2.4 seconds sliding window to add more data points, however, this will make the processing a bit slow and hard to observe the classification result. If we decrease the sliding window duration to 1.2 seconds, the data points will be decreased and hence decrease the processing duration, yet the step count accuracy might be penalized. 25 | -------------------------------------------------------------------------------- /pedometer.py: -------------------------------------------------------------------------------- 1 | # pedometer algorithm 2 | 3 | import serial 4 | import numpy as np 5 | from scipy.fftpack import fft 6 | import os 7 | 8 | 9 | ser = serial.Serial("COM3",115200) # computer serial port is COM3 10 | gz = [] # the gyroscope of z-axis 11 | i_step = [] 12 | flag = False 13 | 14 | def count_step(g_window): 15 | # applying fft algorithm 16 | sliding_window = len(g_window) 17 | T = 0.05 # 50ms 18 | g_windowf = fft(g_window) 19 | g_f = 2.0/sliding_window * np.abs(g_windowf[0:sliding_window//2]) 20 | xf = np.linspace(0.0, 1.0/(2.0*T), sliding_window//2) 21 | 22 | index = np.where(np.logical_and(xf>=0.6, xf<=2)) 23 | index_1 = np.where(np.logical_and(xf>=0, xf<=0.6)) 24 | if index[0].size == 0: 25 | return 0 26 | else: 27 | xf_between = xf[index] 28 | g_windowf_between = g_f[index] 29 | # g_windowf_between_1 = g_f[index_1] 30 | if np.mean(g_windowf_between) >= 2.5: 31 | index_max = np.where(g_windowf_between == max(g_windowf_between)) 32 | count_step = xf_between[index_max[0][0]]*1.2 33 | return count_step 34 | else: 35 | return 0 36 | 37 | while True: 38 | cc = str(ser.readline()) 39 | raw_data = cc.split(",") 40 | if (len(cc)<16) or len(raw_data) != 3: 41 | continue 42 | else: 43 | gz.append(float(raw_data[1])) 44 | 45 | if len(gz)% 50 == 0: 46 | flag = True 47 | i_th_step = round(count_step(gz)) 48 | i_step.append(i_th_step) 49 | if i_th_step == 0: 50 | flag = False 51 | gz = [] 52 | os.system('cls') 53 | if flag: 54 | print("Current Status: Walking") 55 | print("Step Count:", sum(i_step)) 56 | else: 57 | print("Current Status: Standing or Typing") 58 | print("Step Count:", sum(i_step)) 59 | -------------------------------------------------------------------------------- /readme for video.txt: -------------------------------------------------------------------------------- 1 | Needless to say, in order to increase the step count accuracy, we choose 2.4 seconds sliding window to add more data points, however, this will make the processing very slow and hard to observe the classification. 2 | If we decrease the sliding window duration to 1.2 seconds, the data points will be decreased and hence decrease the processing duration. 3 | Hence we separate the classification and step count videos! Thanks a lot! -------------------------------------------------------------------------------- /sensor_data.ino: -------------------------------------------------------------------------------- 1 | // collect sensor data gyroscope 2 | #include 3 | #include 4 | LSM9DS1 imu; 5 | unsigned long time; 6 | 7 | 8 | void setup() { 9 | Serial.begin(115200); 10 | Wire.begin(); 11 | imu.begin(); 12 | 13 | } 14 | 15 | void loop() { 16 | time = millis(); 17 | if ( imu.accelAvailable() ) 18 | imu.readAccel(); 19 | if ( imu.gyroAvailable() ) 20 | imu.readGyro(); 21 | 22 | float ax = imu.calcAccel(imu.ax); 23 | float ay = imu.calcAccel(imu.ay); 24 | float az = imu.calcAccel(imu.az); 25 | 26 | float gx = imu.calcGyro(imu.gx); 27 | float gy = imu.calcGyro(imu.gy); 28 | float gz = imu.calcGyro(imu.gz); 29 | 30 | // Serial.print(ax); 31 | // Serial.print("\t"); 32 | // Serial.print(ay); 33 | // Serial.print("\t"); 34 | // Serial.print(az); 35 | // Serial.print("\t"); 36 | Serial.print(gy); 37 | Serial.print(","); 38 | Serial.print(gz); 39 | Serial.print(","); 40 | Serial.print(gx); 41 | Serial.println(); 42 | delay(50); 43 | } 44 | --------------------------------------------------------------------------------