---
# System prepended metadata

title: 1 Data Acquistition and Observation
tags: [HAR mini, 工房]

---

# 1 Data Acquistition and Observation

[TOC]

###### tags: `工房` `HAR mini`

## What is accelerometer?
- learn the link below 
[学研さんと「加速度センサー」のヒミツ](https://topics.nintendo.co.jp/article/933eb428-b313-11e7-8cda-063b7ac45a6d)

## E1 How to design a 3-axis accelerometer?
- draw a draft about your idea


## Plot the selected files under the same folder
- a function to select the matched files, and plot them into one figure
```python=
import pandas as pd
import matplotlib.pyplot as plt
import os
import datetime
import math

# Function: show the line chart of the 3D time series acceleration data
# Input:
#    - fpath: file folder path,
#    - fext: file extension
#    - fprefix: select the file with specific prefix in the filename
#    - fig_w: figure width in inch
#    - fig_h: figure height in inch
# Output: plot the all files under the same folder within one figure, meanwhile, the figure is storaged in a PDF file

def plot_mfs(fpath, fext, fprefix, fig_w, fig_h):
    selected_f = []
    files = os.listdir(fpath)
    for file in files:
        if file.endswith(fext):
            if len(fprefix) == 0:
                selected_f.append(file)
            elif file.startswith(fprefix):
                selected_f.append(file)
    selected_f.sort()

    nf = len(selected_f)
    ax = [0] * nf
    print(selected_f)
    fig = plt.figure(figsize=(fig_w, fig_h), facecolor='lightsteelblue', tight_layout=True, frameon=True)

    for i in range(nf):
        data = pd.read_csv(fpath + selected_f[i])
        data.columns = ['rate', 'ax', 'ay', 'az', 'gx', 'gy', 'gz', 'mx', 'my', 'mz', 'battery', 'altitude',
                        'temperature']

        nrows = math.ceil(math.sqrt(nf))
        ncols = math.ceil(math.sqrt(nf))

        ax[i] = fig.add_subplot(nrows, ncols, i + 1, title=str(i + 1) + '.csv', fc='cornsilk')
        ax[i].plot(data['ax'], label='ax', color='blue')
        ax[i].plot(data['ay'], label='ay', color='green')
        ax[i].plot(data['az'], label='az', color='red')

    fig.savefig('./figures/figure_ex' + datetime.datetime.now().isoformat() + '.pdf')

    plt.show()
    return

def main():
    fpath = '../data/3x3/'
    fprefix = ''
    fext = '.csv'
    plot_mfs(fpath, fext, fprefix, 12, 7)
    return


if __name__== "__main__":
    main()
```


## E2 Category the acceleration data by observation 

- open the raw data with the python program or an Excel like spreadsheet software
    -  [data download link](https://www.dropbox.com/sh/f8cl68fsqq1vzie/AADPYxVmwH0e4qCQYRHjWbEva?dl=0)
    -  Nine csv files, each file represents one actions among the three actions (Walking, sit-down and stand up, eating), each action contains three files recorded from three people
    - NOTE 1: read all the data in a file may take a longer time on your PC, so you only need to read a part of data to finish this exercise
    - NOTE 2: Data Format in the csv file, it is different with the data format in last time E4 
        - sampling rate,ax,ay,az,gx,gy,gz,mx,my,mz,altitude,battery 
- show the waveform of the three axes acceleration data
- observe and category the waveform into three kinds of actions: Walking, sit-down and stand up, eating
- submit your answer in PDF including three items by **Jun.13th**
    1.     the snapshot of the waveforms
    2.     the answer (like Walking: 234, sit-down and stand up: 569, eating:178)
    3.     the reason or the basis of your judgement, it is recommended to use the figures plus discriptions for the explain purpose. 


## Appendix 1: What is the theory behind the Angular Speed sensor or Gyroscope?
- learn the concept from the following link
    - [ジャイロセンサー」のヒミツ](https://topics.nintendo.co.jp/article/151137c8-d0d9-11e7-8cda-063b7ac45a6d)
- [The theory of Coriolis force](https://www.youtube.com/watch?v=S2RtAI6fRIM)

## Appendix 2: Fundamental knowledge on the IMU sensor
- [an intro video on the 6-axis motion sensor MPU6050](https://www.youtube.com/watch?v=M9lZ5Qy5S2s)



