-
Notifications
You must be signed in to change notification settings - Fork 0
/
washdry.Rmd
162 lines (146 loc) · 3.75 KB
/
washdry.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
---
title: "WashDry"
author: "Ryszard Czerminski"
date: "2017-09-19"
header-includes:
- \usepackage{amsmath}
- \usepackage{color}
- \usepackage{xcolor}
- \usepackage{mathtools}
- \DeclareMathOperator*{\E}{\mathbb{E}}
- \usepackage{hyperref}
- \hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=cyan,
}
output:
pdf_document
---
\section{Intro}
\section{Setup global contants for data and libs}
```{r}
cat('cwd:', getwd(), '\n')
dir <- list()
dir$libs <- Sys.getenv('SPRINGBOARD_LIBS')
dir$data <- Sys.getenv('SPRINGBOARD_DATA')
fn.libs <- paste(dir$libs, 'sigUtils.R', sep='/')
probs <- seq(0.1, 0.9, 0.1)
probs <- seq(0.25, 0.75, 0.5)
cat('SPRINGBOARD_LIBS:', dir$libs, '\n')
cat('SPRINGBOARD_DATA:', dir$data, '\n')
cat('fn.libs:', fn.libs, '\n')
```
\section{Production line sample}
```{r}
fn <- paste(dir$data, 'sample.csv', sep='/')
x <- read.csv(fn)
fmt <- '%m/%d/%Y %I:%M %p'
x$Start <- as.POSIXct(x$Start.Time, format=fmt)
x$End <- as.POSIXct(x$End.Time, format=fmt)
x$Start.Time <- x$End.Time <- NULL
x$Span <- x$End - x$Start
```
Note, that \texttt{Duration} (from csv) and \texttt{Span} (calculated as diff beteen \texttt{Start}
and \texttt{End} are not the same:
```{r}
head(x[, c('Duration', 'Span')])
head(x)
```
I am removing \texttt{Duration} column and will use \texttt{Span} column for know.
`r x$Duration <- NULL`
\textbf{You should find out what is the reason for this discrepancy.}
```{r}
head(x)
```
\subsection{Are there any spans of length 0?}
```{r}
w <- which(x$Span == 0)
x[w, c('State', 'Reason', 'Span')]
```
Apparently there are. Let's remove them since these do not seem
to be very meaningful. I will remove old row numbering as well.
```{r}
x <- x[-w,]
row.names(x) <- NULL
```
\subsection{Check for gaps}
```{r}
i <- 1:(nrow(x)-1); j <- i + 1
d <- x$Start[j] - x$End[i]
w <- which(d > 0)
```
There is a `r d[w]` `r units(d[w])` gap in data around row `r w`.
Code needs to be able to deal with time gaps like this.
\subsection{How many different states we have?}
```{r}
tb <- table(x$State)
tb
```
Let's recode them as follows
```{r}
codes <- c(Running=0, Standby=1, Setup=2, Down=3)
```
Now we can convert the data frame. Let's just select a fixed slice of a df
e.g.8h beetween 8am and 4pm)
```{r}
slice <- list()
slice$start <- as.POSIXct('2017-08-11 08:00:00', format='%Y-%m-%d %H:%M:%S')
slice$end <- as.POSIXct('2017-08-11 16:00:00', format='%Y-%m-%d %H:%M:%S')
```
\subsection{Read vib data}
```{r}
source(fn.libs)
data.sets <- c('dry', 'wash')
cols <- c('red', 'blue')
names(cols) <- data.sets
v <- prep.signals(data.sets, dir=dir$data, verbose=1)
if (length(v$err) > 0) {
for (x in v$err) cat(x, '\n')
stop()
} else {
signal <- v$data
}
```
```{r}
plt.signals(signal)
```
\section{Signal amplitude analysis}
```{r}
plt.cdfs(signal, xlab='amplitude', value='norm', titl='signals')
qSig <- list() # list of signal quantiles
qSig$dry <- quantile(signal$dry$norm, probs)
qSig$wash <- quantile(signal$wash$norm, probs)
```
\section{Frequency analysis}
```{r}
source(fn.libs)
power <- list()
for (name in names(signal)) {
y <- signal[[name]]$norm; t <- signal[[name]]$t
v <- get.fft(y, t, tag=name)
plt.power(y, t, v$pw, v$f, tag=name)
power[[name]] <- list(f=v$f, pw=v$pw)
}
```
```{r}
qPow <- list() # power quantiles
plot(1, xlim=c(0,50), ylim=c(0,1), type='n', xlab='freq', ylab='Cummulative power')
for (x in names(power)) {
f <- power[[x]]$f; p <- power[[x]]$pw
v <- cumsum(p)
v <- v/max(v)
qf <- splinefun(v, f)
qPow[[x]] <- qf(probs)
lines(f, v, type='l', col=cols[x])
}
legend('topleft', legend=names(power), col=cols, lwd=2)
```
\section{Quantiles for commulative power spectrum}
```{r}
cat('signal quantiles:\n')
print (qSig)
cat('power quantiles:\n')
print (qPow)
```