Wavelet Filters for Smoothing Functionals

Step 1. Inititalize Libraries

library(wavelets)

Step 2. Create normal random variable

xNorm <- rnorm(2048)

Step 3. Examine the different wavelet filters:

Examine the squared gain function for a wavelet filter.

filter <- wt.filter("la8")
squaredgain.wt.filter(filter)

plot of chunk unnamed-chunk-3

# Adding an 'made up' filter (represented by c(1,-1,1,-1)
figure108.wt.filter(list("la8", "d4", c(1, -1, 1, -1)))

plot of chunk unnamed-chunk-4

Step 4. Perform the wavelet transform

dwtobj <- dwt(xNorm, filter = "la8")
dwtobj1 <- dwt(xNorm, filter = "d4")
# Create list of dwt objects
dwtlist <- list(dwtobj, dwtobj1)

Step 5. Plot the wavelet coefficients

# Plotting wavelet coefficients of levels 1, 3, 5, and scaling
# coefficients of levels 4 and 5, and green boundary coefficient lines.
plot.dwt(dwtobj, levels = list(c(1, 3, 5), c(4, 5)), draw.boundary = TRUE, col.boundary = "green")

plot of chunk unnamed-chunk-6

Step 6. Plot the comparison based on filters

plot.dwt.multiple(dwtlist, levels = list(c(1, 3, 5), c(2, 4)))

plot of chunk unnamed-chunk-7

Step 7. Compute the Original Series with level one coefficients

wt.dwt <- dwt.forward(xNorm, filter)
newX.dwt <- dwt.backward(wt.dwt$W, wt.dwt$V, filter)

Step 8. Plot the transformed series with the original one

waveDat <- as.data.frame(cbind(xNorm, newX.dwt))
matplot(waveDat, type = "l", col = c("red", "blue"))
legend("bottom", legend = c("Raw", "Transformed"), fill = c("red", "blue"))

plot of chunk unnamed-chunk-9

Work in development at The Cromwell Workshop - www.cromwellworkshop.com by Jeff B. Cromwell, PhD