Wavelet Decomposition of Time Signal (River Discharge)

Wavelet decomposition of a time-series, in this case Tomikawa River, for which we downloaded data from the online data in another tutorial.

Preparation and process

THis section transforms the data we downloaded from character to double for numerical analysis, and then we load the two library necessary. The WV library needs to be installed the first time you use it on your computer (install.packages(“wv”)). We then display the summary of the wavelet decomposition, which provides the different wavelet coefficients.

dataset <- read.csv2('dataset.csv')

dataset <- as.numeric(unlist(dataset)) 

dataset <- as.double(dataset) #transform the character to double
dataset[is.na(dataset)] <- 0 # replace NaN by 0s

library(wv)
## Warning: package 'wv' was built under R version 4.0.3
library(simts)
## Warning: package 'simts' was built under R version 4.0.3
## 
## Attaching package: 'simts'
## The following object is masked from 'package:wv':
## 
##     unitConversion
#Maximum Overlap Discrete Wavelet Transform

data.modwt <- modwt(dataset)

summary(data.modwt)
## 
## Results of MODWT using haar filter with 16 levels:
## Displaying only the first 6 coefficients...
## Level 1 Wavelet Coefficients
##  0 0 0 0 0 0 ...
## Level 2 Wavelet Coefficients
##  0 0 0 0 0 0 ...
## Level 3 Wavelet Coefficients
##  0 0 0 0 0 0 ...
## Level 4 Wavelet Coefficients
##  0 0 0 0 0 0 ...
## Level 5 Wavelet Coefficients
##  0 0 0 0 0 0 ...
## Level 6 Wavelet Coefficients
##  0.2 0.2125 0.225 0.2375 0.25 0.2625 ...
## Level 7 Wavelet Coefficients
##  0.7411719 0.7686719 0.7891406 0.8027344 0.8163281 0.823125 ...
## Level 8 Wavelet Coefficients
##  0.4164453 0.3795703 0.3497266 0.3267578 0.3037891 0.2876172 ...
## Level 9 Wavelet Coefficients
##  -1.094277 -1.100449 -1.106621 -1.112793 -1.118965 -1.125137 ...
## Level 10 Wavelet Coefficients
##  -0.2894043 -0.2878809 -0.2863574 -0.284834 -0.2833105 -0.2817871 ...
## Level 11 Wavelet Coefficients
##  8.444453 8.458037 8.471621 8.482817 8.494014 8.506987 ...
## Level 12 Wavelet Coefficients
##  51.6642 51.66079 51.65773 51.65705 51.65638 51.65392 ...
## Level 13 Wavelet Coefficients
##  3.342725 3.342198 3.341326 3.339562 3.337626 3.33569 ...
## Level 14 Wavelet Coefficients
##  -5.953115 -5.960712 -5.968362 -5.975172 -5.981859 -5.988547 ...
## Level 15 Wavelet Coefficients
##  -10.67983 -10.67788 -10.67554 -10.67316 -10.67126 -10.66951 ...
## Level 16 Wavelet Coefficients
##  -3.78892 -3.790744 -3.792895 -3.795113 -3.796842 -3.798388 ...

Plot of the original time series (Tomikawa River Discharge)

plot(dataset, col="white")
lines(dataset)

Graphic of the Wavelet Decomposition

This is a plot of all the different levels, there is another with less levels, and more readable underneath.

plot(data.modwt, index = "all")

plot (data.modwt, index = c(1:6))

plot (data.modwt, index = c(7:13))