recursive_digital_filter: Recursive digital filter

Description Usage Arguments Details Examples

View source: R/baseflow_separation.R

Description

Recursive digital filter for baseflow separation

Usage

1

Arguments

x

Baseflow timeseries

alpha

Filter parameter (see details)

Details

This functions executes the recusive digital filter for baseflow separation as described by Nathan and McMahon (1990). The digital filter operates by removing out high frequency components of streamflow. These high frequencies can be considered quickflow which is calculated as:

f[k] = alpha * f[k-1] + (1+alpha)/2 * (y[k] - y[k-1])

The filter is run forwards, then backwards, then forwards again, and each time baseflow is calculated as b[k] = y[k] - f[k]. Nathan and McMahon found that a values of 0.9-0.95 closely matched baseflow separation via manual separation techniques, with 0.9 the closest match in their study.

Nathan, R. J., & McMahon, T. A. (1990). Evaluation of automated techniques for base flow and recession analyses. Water resources research, 26(7), 1465-1473.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Generate random streamflow timeseries (not necessarily realistic)
kern <- rep(1/15, 15)
flow <- data.frame(t = seq(1, 365 * 4 + length(kern)))
flow$sin_annual <- cos(flow$t * 2 * pi / 365 - pi)
flow$rain_sin <- sin(flow$t * 2 * pi / 365 - )
flow$total_flow <- flow$sin_annual + (flow$sin_annual + 1) * as.numeric(stats::filter(exp(rnorm(nrow(flow))), kern)) + 1
flow$baseflow90 <- recursive_digital_filter(flow$total_flow, 0.9)
flow$baseflow95 <- recursive_digital_filter(flow$total_flow, 0.95)

# Plot the results
library(ggplot2)
ggplot(flow) +
  geom_line(aes(t, total_flow, color = "Total flow")) +
  geom_line(aes(t, baseflow90, color = "Baseflow, alpha = 0.9")) +
  geom_line(aes(t, baseflow95, color = "Baseflow, alpha = 0.95"))

gopalpenny/gohydro documentation built on Dec. 20, 2021, 12:43 p.m.