|
|
@ -17,11 +17,22 @@
|
|
|
|
##################################################
|
|
|
|
##################################################
|
|
|
|
################### It2charge ####################
|
|
|
|
################### It2charge ####################
|
|
|
|
##################################################
|
|
|
|
##################################################
|
|
|
|
It2charge <- function (current, time) {
|
|
|
|
It2charge <- function (time, current) {
|
|
|
|
## Calculates charge etc. for amperometric data
|
|
|
|
## Description:
|
|
|
|
## current may be a current or a current density
|
|
|
|
## Calculates cumulative charge, differentials, etc. from
|
|
|
|
## (up to the calling function to keep track of which it is)
|
|
|
|
## amperometric data (current and time).
|
|
|
|
# Calculate the difference of the time vector
|
|
|
|
## __Intended to be used from within other functions (CHI.R)__
|
|
|
|
|
|
|
|
## Usage:
|
|
|
|
|
|
|
|
## It2charge(time, current)
|
|
|
|
|
|
|
|
## Arguments:
|
|
|
|
|
|
|
|
## time: a vector with time data.
|
|
|
|
|
|
|
|
## current: a vector of the same length as time, with current data.
|
|
|
|
|
|
|
|
## May be either currents or current densities, no matter.
|
|
|
|
|
|
|
|
## Value:
|
|
|
|
|
|
|
|
## Returns a dataframe with columns:
|
|
|
|
|
|
|
|
## timediff, dIdt, charge, sumcharge
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
# Calculate the time vector difference
|
|
|
|
timediff <- c(time[1], diff(time))
|
|
|
|
timediff <- c(time[1], diff(time))
|
|
|
|
# timediff times the current gives the charge,
|
|
|
|
# timediff times the current gives the charge,
|
|
|
|
# since the time vector can be considered as
|
|
|
|
# since the time vector can be considered as
|
|
|
@ -29,11 +40,11 @@ It2charge <- function (current, time) {
|
|
|
|
# the current with the time elapsed since the last
|
|
|
|
# the current with the time elapsed since the last
|
|
|
|
# current measurement (the timediff).
|
|
|
|
# current measurement (the timediff).
|
|
|
|
charge <- current * timediff
|
|
|
|
charge <- current * timediff
|
|
|
|
differential <- cumsum(charge) / time
|
|
|
|
dIdt <- current / time
|
|
|
|
# Prepare the return dataframe
|
|
|
|
# Return value
|
|
|
|
ff <- data.frame(time = time, timediff = timediff,
|
|
|
|
ff <- data.frame(timediff = timediff,
|
|
|
|
current = current, charge = charge,
|
|
|
|
dIdt = dIdt, charge = charge,
|
|
|
|
sumcharge = cumsum(charge), dQdt = differential)
|
|
|
|
sumcharge = cumsum(charge))
|
|
|
|
return(ff)
|
|
|
|
return(ff)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|