Baseflow separation

Introduction
Chapman (1999) gives an excellent overview of baseflow separation techniques. Recursive digital filters are easiest to automate. Below are a few R implementations of the filter equations listed on the site:

NOTE: this is work in progress - the scripts have not yet been thoroughly tested and may contain bugs!

One-parameter algorithm
Chapman (1999) equation 8:

bf_oneparam <- function(discharge, k){ bf <- rep(discharge[1],length(discharge)) for(i in 2:length(discharge)) { bf[i] <- (k*bf[i-1]/(2-k)) + ((1-k)*discharge[i]/(2-k)) if(bf[i] > discharge[i]) bf[i] <- discharge[i] }   return(bf) }

Parameter k is the recession constant during periods without direct runoff.

Boughton two-parameter algorithm
Chapman (1999) equation 9:

bf_boughton <- function(discharge, k, C){ bf <- rep(discharge[1],length(discharge)) for(i in 2:length(discharge)) { bf[i] <- (k*bf[i-1]/(1+C)) + (C*discharge[i]/(1+C)) if(bf[i] > discharge[i]) bf[i] <- discharge[i] }   return(bf) }

IHACRES three-parameter algorithm
Chapman (1999) equation 11:

bf_IHACRES <- function(discharge, k, C, a){ bf <- rep(discharge[1],length(discharge)) for(i in 2:length(discharge)) { bf[i] <- (k*bf[i-1]/(1+C)) + (C*(discharge[i] + a*discharge[i-1])/(1+C)) if(bf[i] > discharge[i]) bf[i] <- discharge[i] }   return(bf) }