R> source('NokiaN9-battery-period.R') Period: 24.02245 hours
# How long is battery life on the Nokia N9? # Find the period of charge of battery # Read CSV file BAT <- read.csv("NokiaN9-batterydata-5months.csv", sep = "\t") # Interpolate on regular grid APPROX <- approx(BAT$TIME, BAT$BATTERY,xout = seq(f = min(BAT$TIME), t = max(BAT$TIME), len = length(BAT$TIME))) # Get spectrum SPECTRUM <- spectrum(APPROX$y,plot=F) # Find maximum period # First find frequency of greatest amplitude # Invert this frequency to get the period # Multiply this period that is in units of timesteps with the timestep to get the period in seconds PERIOD <- 1/SPECTRUM$freq[which.max(SPECTRUM$spec)] * unique(zapsmall(diff(APPROX$x))) # Output period in hours cat("Period:", PERIOD / 60 / 60,"hours")