Title: | Compute Maximal Overlap Discrete Wavelet Transform (MODWT) and À Trous Discrete Wavelet Transform |
---|---|
Description: | A lightweight package to compute Maximal Overlap Discrete Wavelet Transform (MODWT) and À Trous Discrete Wavelet Transform by leveraging the power of 'Rcpp' to make these operations fast. This package was designed for use in forecasting, and allows users avoid the inclusion of future data when performing wavelet decomposition of time series. See Quilty and Adamowski (2018) <doi:10.1016/j.jhydrol.2018.05.003>. |
Authors: | John Quilty [aut] , John You [aut, cre] |
Maintainer: | John You <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2.0.0.9000 |
Built: | 2024-11-01 03:53:35 UTC |
Source: | https://github.com/johnswyou/fastwavelets |
This function calculates the wavelet and scaling coefficients of the a trous (AT) version of the Discrete Wavelet Transform (DWT).
atrous_dwt(X, filter, J, remove_boundary_coefs = FALSE)
atrous_dwt(X, filter, J, remove_boundary_coefs = FALSE)
X |
An (N x 1) matrix or a vector |
filter |
Filter name (see Details below) (string) |
J |
Decomposition level (integer, 1 < J < N/2) |
remove_boundary_coefs |
Remove boundary affected coefficients? |
The argument filter
can take one of the following values:
c('bl7', 'bl9', 'bl10', 'beyl', 'coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12', 'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23', 'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33', 'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22', 'han2_3', 'han3_3', 'han4_5', 'han5_5', 'dmey', 'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3', 'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14', 'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27', 'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40', 'sym41', 'sym42', 'sym43', 'sym44', 'sym45', 'vaid', 'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
Wavelet and scaling coefficients (N x J+1) (wavelet coefficients in first J columns of returned matrix)
Benaouda, D., F. Murtagh, J. L. Starck, and O. Renaud (2006), Wavelet-based nonlinear multiscale decomposition model for electricity load forecasting, Neurocomputing, doi:10.1016/j.neucom.2006.04.005.
Maheswaran, R., and R. Khosa (2012), Comparative study of different wavelets for hydrologic forecasting, Comput. Geosci., doi:10.1016/j.cageo.2011.12.015.
N <- 1000 # number of time series points J <- 4 # decomposition level X <- matrix(rnorm(N),N,1) W <- atrous_dwt(X,'coif1',J) plot.ts(W) # plot wavelet and scaling coefficients
N <- 1000 # number of time series points J <- 4 # decomposition level X <- matrix(rnorm(N),N,1) W <- atrous_dwt(X,'coif1',J) plot.ts(W) # plot wavelet and scaling coefficients
Perform a circular convolution between a filter and a time series.
circular_convolution(a, b)
circular_convolution(a, b)
a |
Filter (typically, the wavelet or scaling filter) |
b |
A vector |
The convolution theorem tells us that the discrete Fourier transform can be leveraged to compute a circular convolution, which is what this function does.
Result of circular convolution, length is the same as length(b)
Equivalent Wavelet and Scaling Filters
equivalent_filters(filter, J, modwt = FALSE)
equivalent_filters(filter, J, modwt = FALSE)
filter |
Filter name (string) |
J |
Decomposition level (integer) |
modwt |
Do you want the MODWT version?, Default: FALSE |
Equivalent wavelet and scaling filters are useful for obtaining MODWT wavelet and scaling coefficients for a given filter name and decomposition level.
A list containing the equivalent wavelet and scaling filter and their lengths.
Maximal Overlap Discrete Wavelet Transform (MODWT)
mo_dwt(X, filter, J, remove_boundary_coefs = FALSE)
mo_dwt(X, filter, J, remove_boundary_coefs = FALSE)
X |
An (N x 1) matrix or a vector |
filter |
Filter name (see Details below) (string) |
J |
Decomposition level (integer, 1 < J < N/2) |
remove_boundary_coefs |
Remove boundary affected coefficients? |
The argument filter
can take one of the following values:
c('bl7', 'bl9', 'bl10', 'beyl', 'coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12', 'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23', 'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33', 'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22', 'han2_3', 'han3_3', 'han4_5', 'han5_5', 'dmey', 'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3', 'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14', 'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27', 'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40', 'sym41', 'sym42', 'sym43', 'sym44', 'sym45', 'vaid', 'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
Percival, D. B. and A. T. Walden (2000) Wavelet Methods for Time Series Analysis, Cambridge University Press.
Maximal Overlap Discrete Wavelet Transform
modwt(X, filter, J)
modwt(X, filter, J)
X |
An (N x 1) matrix or a vector |
filter |
Filter name (see Details below) (string) |
J |
Decomposition level (integer, 1 < J < N/2) |
The argument filter
can take one of the following values:
c('bl7', 'bl9', 'bl10', 'beyl', 'coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12', 'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23', 'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33', 'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22', 'han2_3', 'han3_3', 'han4_5', 'han5_5', 'dmey', 'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3', 'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14', 'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27', 'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40', 'sym41', 'sym42', 'sym43', 'sym44', 'sym45', 'vaid', 'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
Percival, D. B. and A. T. Walden (2000) Wavelet Methods for Time Series Analysis, Cambridge University Press.
Compute MODWT wavelet coefficients for a specified filter and
decomposition level. This function only gives the MODWT wavelet coefficients
for the user specified level. To get all MODWT wavelet coefficients up to and
including the user specified decomposition level (as well as the MODWT scaling
coefficient corresponding to the user specified decomposition level) all in one nice
matrix, please use mo_dwt()
.
Compute MODWT scaling coefficients for a specified filter and decomposition level. This function only gives the MODWT scaling coefficients for the user specified level.
modwt_wavelet_coefs(X, filter, j) modwt_scaling_coefs(X, filter, j)
modwt_wavelet_coefs(X, filter, j) modwt_scaling_coefs(X, filter, j)
X |
A vector |
filter |
Filter name (string) |
j |
Decomposition level (integer) |
This function implements the first equation in equation 169a (page 169) of Wavelet Methods for Time Series Analysis by Percival and Walden.
This function implements the second equation in equation 169a (page 169) of Wavelet Methods for Time Series Analysis by Percival and Walden.
MODWT wavelet coefficients for specified decomposition level (vector)
MODWT scaling coefficients for specified decomposition level (vector)
This function calculates the number of boundary coefficients for a particular wavelet/scaling filter and decomposition level.
n_boundary_coefs(filter, J)
n_boundary_coefs(filter, J)
filter |
Filter name (see Details below) [string] |
J |
Decomposition level [integer] |
The argument filter
can take one of the following values:
c('bl7', 'bl9', 'bl10', 'beyl', 'coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12', 'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23', 'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33', 'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22', 'han2_3', 'han3_3', 'han4_5', 'han5_5', 'dmey', 'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3', 'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14', 'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27', 'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40', 'sym41', 'sym42', 'sym43', 'sym44', 'sym45', 'vaid', 'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
Number of boundary coefficients [integer]
M. Basta (2014),Additive Decomposition and Boundary Conditions in Wavelet-Based Forecasting Approaches, Acta Oeconomica Pragensia, 2, pp. 48-70.
Quilty, J., & Adamowski, J. (2018). Addressing the incorrect usage of wavelet-based hydrological and water resources forecasting models for real-world applications with best practices and a new forecasting framework. Journal of Hydrology, 563, 336–353. https://doi.org/10.1016/j.jhydrol.2018.05.003
Percival, D. B. and A. T. Walden (2000) Wavelet Methods for Time Series Analysis, Cambridge University Press.
J <- 4 # decomposition level nbc <- n_boundary_coefs('db1', J) # number of boundary-effected coefficients at decomp_level J
J <- 4 # decomposition level nbc <- n_boundary_coefs('db1', J) # number of boundary-effected coefficients at decomp_level J
Periodize a filter
periodize_filter(filter_vector, periodize_to)
periodize_filter(filter_vector, periodize_to)
filter_vector |
The filter vector that is outputted from r_wavelet_filter or r_scaling_filter |
periodize_to |
The length of the time series that is to be decomposed |
Output of the function is a zero padded version of the original filter, padded at the end.
Periodized filter
This function returns the user specified scaling filter.
r_scaling_filter(filter, modwt = FALSE)
r_scaling_filter(filter, modwt = FALSE)
filter |
Name of the scaling filter desired [string] |
modwt |
Should the elements of the returned filter be scaled by |
See equation 75a (page 75) of Wavelet Methods for Time Series Analysis by Percival and Walden to see how to convert a wavelet filter into a scaling filter.
The argument filter
can take one of the following values:
c('bl7', 'bl9', 'bl10', 'beyl', 'coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12', 'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23', 'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33', 'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22', 'han2_3', 'han3_3', 'han4_5', 'han5_5', 'dmey', 'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3', 'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14', 'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27', 'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40', 'sym41', 'sym42', 'sym43', 'sym44', 'sym45', 'vaid', 'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
A scaling filter vector
## Not run: if(interactive()){ r_scaling_filter("db1") } ## End(Not run)
## Not run: if(interactive()){ r_scaling_filter("db1") } ## End(Not run)
This function returns the user specified wavelet filter.
r_wavelet_filter(filter, modwt = FALSE)
r_wavelet_filter(filter, modwt = FALSE)
filter |
Name of the wavelet filter desired [string] |
modwt |
Should the elements of the returned filter be scaled by |
See section 4.2 (page 68) of Wavelet Methods for Time Series Analysis by Percival and Walden for a detailed discussion of the wavelet filter.
The argument filter
can take one of the following values:
c('bl7', 'bl9', 'bl10', 'beyl', 'coif1', 'coif2', 'coif3', 'coif4', 'coif5', 'db1', 'db2', 'db3', 'db4', 'db5', 'db6', 'db7', 'db8', 'db9', 'db10', 'db11', 'db12', 'db13', 'db14', 'db15', 'db16', 'db17', 'db18', 'db19', 'db20', 'db21', 'db22', 'db23', 'db24', 'db25', 'db26', 'db27', 'db28', 'db29', 'db30', 'db31', 'db32', 'db33', 'db34', 'db35', 'db36', 'db37', 'db38', 'db39', 'db40', 'db41', 'db42', 'db43', 'db44', 'db45', 'fk4', 'fk6', 'fk8', 'fk14', 'fk18', 'fk22', 'han2_3', 'han3_3', 'han4_5', 'han5_5', 'dmey', 'mb4_2', 'mb8_2', 'mb8_3', 'mb8_4', 'mb10_3', 'mb12_3', 'mb14_3', 'mb16_3', 'mb18_3', 'mb24_3', 'mb32_3', 'sym2', 'sym3', 'sym4', 'sym5', 'sym6', 'sym7', 'sym8', 'sym9', 'sym10', 'sym11', 'sym12', 'sym13', 'sym14', 'sym15', 'sym16', 'sym17', 'sym18', 'sym19', 'sym20', 'sym21', 'sym22', 'sym23', 'sym24', 'sym25', 'sym26', 'sym27', 'sym28', 'sym29', 'sym30', 'sym31', 'sym32', 'sym33', 'sym34', 'sym35', 'sym36', 'sym37', 'sym38', 'sym39', 'sym40', 'sym41', 'sym42', 'sym43', 'sym44', 'sym45', 'vaid', 'la8', 'la10', 'la12', 'la14', 'la16', 'la18', 'la20')
A wavelet filter vector
## Not run: if(interactive()){ r_wavelet_filter("coif1") } ## End(Not run)
## Not run: if(interactive()){ r_wavelet_filter("coif1") } ## End(Not run)