I'm gathering temperature data from a refrigerator. The data looks like a wave. I would like to determine the period and frequency of the wave (so that I can measure if modifications to the refrigerator have any effect).
I'm using R, and I think I need to use an FFT on the data, but I'm not sure where to go from there. I'm very new to R and signal analysis, so any help would be greatly appreciated!
Here is the wave I'm producing:

Here is my R code so far:
require(graphics)
library(DBI)
library(RSQLite)
drv <- dbDriver("SQLite")
conn <- dbConnect(drv, dbname = "s.sqlite3")
query <- function(con, query) {
rs <- dbSendQuery(con, query)
data <- fetch(rs, n = -1)
dbClearResult(rs)
data
}
box <- query(conn, "
SELECT id,
humidity / 10.0 as humidity,
temp / 10.0 as temp,
ambient_temp / 10.0 as ambient_temp,
ambient_humidity / 10.0 as ambient_humidity,
created_at
FROM measurements ORDER BY id DESC LIMIT 3600
")
box$x <- as.POSIXct(box$created_at, tz = "UTC")
box$x_n <- box$temp - mean(box$temp)
png(filename = "normalized.png", height = 750, width = 1000, bg = "white")
plot(box$x, box$x_n, type="l")
# Pad the de-meaned signal so the length is 10 * 3600
N_fft <- 3600 * 10
padded <- c(box$x_n, seq(0, 0, length= (N_fft - length(box$x_n))))
X_f <- fft(padded)
PSD <- 10 * log10(abs(X_f) ** 2)
png(filename = "PSD.png", height = 750, width = 1000, bg = "white")
plot(PSD, type="line")
zoom <- PSD[1:300]
png(filename = "zoom.png", height = 750, width = 1000, bg = "white")
plot(zoom, type="l")
# Find the index with the highest point on the left half
index <- which(PSD == max(PSD[1:length(PSD) / 2]))
# Mark it in green on the zoomed in graph
abline(v = index, col="green")
f_s <- 0.5 # sample rate in Hz
wave_hz <- index * (f_s / N_fft)
print(1 / (wave_hz * 60))
I've posted the R code along with the SQLite database here.
Here is a plot of the normalized graph (with the mean removed):

So far, so good. Here is the spectral density plot:
Then we zoom in on the left side of the plot and mark the highest index (which is 70) with a green line:

Finally we calculate the frequency of the wave. This wave is very slow, so we convert it to minutes per cycle, and print out that value which is 17.14286.
Here is my data in tab delimited format if anyone else wants to try.
Thanks for the help! This problem was hard (for me) but I had a great time!

