Updated It2charge() and fixed the relevant parts of amperometry2df().

It2charge() is now explicitly meant to be used only from within
other functions, such as amperometry2df().
master
Taha Ahmed 13 years ago
parent f8ad854bd7
commit c810ef66ba

@ -298,10 +298,7 @@ amperometry2df <- function(datafilename, wearea = 1) {
ff <- cbind(ff, currentdensity = currentdensity)
# Calculate charge densities and differentials
charge.df <- It2charge(ff$currentdensity, ff$time)
ff <- cbind(ff, timediff = charge.df$timediff,
chargedensity = charge$charge,
sumchargedensity = charge$sumcharge,
dQdt = charge$dQdt)
ff <- cbind(ff, charge.df)
#
### Collect attributes of this experiment
# These attributes are specific for each kind of experiment,

@ -17,11 +17,22 @@
##################################################
################### It2charge ####################
##################################################
It2charge <- function (current, time) {
## Calculates charge etc. for amperometric data
## current may be a current or a current density
## (up to the calling function to keep track of which it is)
# Calculate the difference of the time vector
It2charge <- function (time, current) {
## Description:
## Calculates cumulative charge, differentials, etc. from
## amperometric data (current and time).
## __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 times the current gives the charge,
# 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
# current measurement (the timediff).
charge <- current * timediff
differential <- cumsum(charge) / time
# Prepare the return dataframe
ff <- data.frame(time = time, timediff = timediff,
current = current, charge = charge,
sumcharge = cumsum(charge), dQdt = differential)
dIdt <- current / time
# Return value
ff <- data.frame(timediff = timediff,
dIdt = dIdt, charge = charge,
sumcharge = cumsum(charge))
return(ff)
}

Loading…
Cancel
Save