From f8ad854bd72a9256c752f3c1a7ed5eb3f68734a7 Mon Sep 17 00:00:00 2001 From: Taha Ahmed Date: Mon, 14 Mar 2011 22:36:00 +0100 Subject: [PATCH] New function It2charge() in common.R - amperometry2df() updated accordingly. --- CHI.R | 6 ++++++ common.R | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/CHI.R b/CHI.R index 8994f2e..10413f6 100644 --- a/CHI.R +++ b/CHI.R @@ -296,6 +296,12 @@ amperometry2df <- function(datafilename, wearea = 1) { # Calculate current density currentdensity <- ff$current / wearea 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) # ### Collect attributes of this experiment # These attributes are specific for each kind of experiment, diff --git a/common.R b/common.R index 1f1bf96..f63d6fa 100644 --- a/common.R +++ b/common.R @@ -3,6 +3,7 @@ # Taha Ahmed, Jan 2011 # CONTENTS +# >>>> It2charge # >>>> ProvideSampleId # >>>> ConvertRefPot # >>>> Celsius2Kelvin @@ -13,6 +14,31 @@ +################################################## +################### 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 + timediff <- c(time[1], diff(time)) + # timediff times the current gives the charge, + # since the time vector can be considered as + # the cumulative time, while we need to multiply + # 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) + return(ff) +} + + + ################################################## ################ ProvideSampleId ################# ##################################################