---
# System prepended metadata

title: 2017_BIME_snesor
tags: [Github]

---

# 2017_BIME_snesor
###### tags: `Github`
## Github Link
https://github.com/linnil1/2017_BIME_sensor

## HackMD Link
https://hackmd.io/s/SkwZer3_M

## What's in this repo

Programing part for lab and homeworks
(I will merge those in gist recently)

## HW1
https://github.com/linnil1/2017_BIME_sensor/tree/master/HW1

### Digital Data Acquisition
Simulate ideally what ADC do in real world.

### Data
Using python3 with numpy for simulating and matplotlib for plotting.

### Result
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/HW1/ADC_1.png)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/HW1/ADC_2.png)

## Lab03
https://github.com/linnil1/2017_BIME_sensor/tree/master/lab03

### Data Acquisition
Data collection and analysis by mean, deviation and confidence interval.

### Data
Signal generated by function generator.
Collected by NI ADC and LabVIEW.

### Result
For sin-wave ADC
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/sin_adc_bin.jpg)

For Chi square test
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/chi2.png)

For random data 
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/measurement_1.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/measurement_2.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/measurement_3.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/measurement_4.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab03/measurement_5.jpg)


## postLab03
https://github.com/linnil1/2017_BIME_sensor/tree/master/postLab03

### Practice Statistical Analysis
1. Estimate 95% confidence intervals for the true mean.

2. Determine whether there is overlap more than 95%, the diameter is considered to have remained unchanged.

3. If the number of samples N is increased from 10 to 100, determine whether outer diameters are the same for the above two batches.

### Data
Data is provided in problem.
Batch 117:
`1.0006 1.0072 0.9941 0.9918 0.9986 0.9991 1.0107 0.9981 1.0011 1.0218`
Batch 384:
`0.9854 1.0056 1.0041 1.0132 0.9902 0.9876 1.0094 0.9815 0.9999 1.0027`

### Result
1.
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab03/test_1.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab03/test_2.jpg)

3.
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab03/test_3.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab03/test_4.jpg)

2.
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab03/test.jpg)


## Lab04
https://github.com/linnil1/2017_BIME_sensor/tree/master/lab04

### Calibration of Temperature Transducers
Use linear regression to fit the data, and output slope and intercept in 99% confidence interval and $R^2$.

Code of `Thermo_calibration.py`
``` python3=34
slope, intercept, r_value, p_value, std_err = linregress(x, y)
# confidence of slope and intercept
# https://en.wikipedia.org/wiki/Simple_linear_regression
n = len(arr)
sb = np.sqrt(np.sum((y - slope * x - intercept) ** 2) \
             / np.sum((x - np.average(x)) ** 2) / (n + 2))
std_b = sb * t.ppf(0.995, len(arr))
sa = np.sqrt(np.sum((y - slope * x - intercept) ** 2) * np.sum(x ** 2) \
             / n / (n + 2) / np.sum((x - np.average(x)) ** 2 ))
std_a = sa * t.ppf(0.995, len(arr))
```

### Data
Water temperature got from Iron-constantan thermocouple(TC) and
Platinum resistanc temperature detector(RTD) compared to reference data from alcohol thermometer.
Data: `log2.txt` `log3.txt`
Format: First column is Temperature, second is data from TC, and third is RTD.

### Result
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab04/Cali_TC.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab04/Cali_RTD.jpg)

## postLab04
https://github.com/linnil1/2017_BIME_sensor/tree/master/postLab04

### Use linear regression analysis and report the line-fitting parameter estimates ($\hat{a}_1$, $\hat{a}_0$, $\hat{a}_𝑛$, adjusted $𝑅^2$, and unadjusted $𝑅^2$)

use `scipy.stat` can perform linear regression

code snap of `postLab04.py`
``` python3=25
slope, intercept, r_value, p_value, std_err = linregress(x, y)
n = len(x)

# r_value calculate with / (n - 1)
resdiual = -y + x * slope + intercept
var = np.sum(resdiual ** 2) / (n - 2) 
r = 1 - var / (np.std(y, ddof=1) ** 2)
un_r = 1 - (1- r) * (n - 2) / (n - 1)

# linearity and hysteresis
non_linear = np.max(np.abs(resdiual)) / (y.max() - y.min())
hysteresis = np.max(np.abs(y[:n//2] - y[n//2:])) / (y.max() - y.min())
```

### Data
Data got from problem description.
First three columns are for A, the others are B.
Column title: Temperature, Vup(mV), Vdown(mV)
``` python3
data = """
24  40  40  0   30  30 ;
30  50  58  10  40  45 ;
33  60  67  20  45  49 ;
45  68  77  30  50  52 ;
47  76  89  40  55  59 ;
55  84  90  50  62  65 ;
60  92  92  60  67  67 
"""
```

### Result
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab04/postlab04_A.png)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/postLab04/postlab04_B.png)


## Lab05
https://github.com/linnil1/2017_BIME_sensor/tree/master/lab05

### First Order System Identification Applied To Temperature Measurement System

We use RTD to measure water temperature after suddenly put devices from cold water to hot or vice versa.

### Collected Data
Measure 6 times

* Temperature Data
`temp = [[20.5, 56], [55.5, 21], [21, 76], [76, 22], [21.5, 68], [68, 22]]`

* Dynamic Data
`lab05log*.txt` from 7 to 12 
(First 6 times have some error due to some programming problems)
`

### Result
`python3 lab05.py`
and create *.jpg
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab05/log5_data_0.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab05/log5_data_1.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab05/log5_data_2.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab05/log5_data_3.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab05/log5_data_4.jpg)
![](https://github.com/linnil1/2017_BIME_sensor/raw/master/lab05/log5_data_5.jpg)