### some R basics (see also Appendix A of `An Introduction to R') ### ### create 2 vectors, each containing 50 random deviates ### from a standard normal distribution x <- rnorm(64) y <- rnorm(64) ### examine contents of x x ### create 2 more vectors containing sums and products a <- x + y b <- x * y ### plot y versus x plot(x,y) ### plot b versus a plot(a,b) ### set up window to hold 2 plots at a time, ### one on top of the other par(mfrow=c(2,1)) plot(x,y) plot(a,b) ### 2 plots at a time, one next to the other par(mfrow=c(1,2)) plot(x,y) plot(a,b) ### back to just one plot per window par(mfrow=c(1,1)) plot(x,y) ### list all active plotting devices dev.list() ### create a new plotting device (window) quartz() ### works on a Mac - need to adjust for Windows etc plot(a,b) dev.list() ### go back to plotting on first window (device 2) dev.set(2) plot(a,b) ### load `waveslim' module library(waveslim) ### look at contents of module objects(2) ### get documentation for function called wavelet.filter ?wavelet.filter ### look at definition for wavelet.filter wavelet.filter ### create impulse response sequence for LA(8) wavelet ### filter of unit level and for equivalent wavelet filters ### of levels j = 2, 3 and 4 irs.la8w <- wavelet.filter("la8","H") irs.la8w.2 <- wavelet.filter("la8","HL") irs.la8w.3 <- wavelet.filter("la8","HLL") irs.la8w.4 <- wavelet.filter("la8","HLLL") ### look at values making up basic filter (unit level) irs.la8w ### plot the filters par(mfrow=c(4,1)) plot(irs.la8w) plot(irs.la8w.2) plot(irs.la8w.3) plot(irs.la8w.4) ### check that filters sum to zero ... sum(irs.la8w) sum(irs.la8w.2) sum(irs.la8w.3) sum(irs.la8w.4) ### ... and have unit energy sum(irs.la8w^2) sum(irs.la8w.2^2) sum(irs.la8w.3^2) sum(irs.la8w.4^2) ### create vectors with 106 zeros filter.1 <- rep(0,106) filter.2 <- rep(0,106) filter.3 <- rep(0,106) filter.4 <- rep(0,106) ### define function that returns width of ### equivalent filter of level j for ### wavelet filter of width L at level 1 Lj <- function(L,j) (2^j - 1) * (L - 1) + 1 Lj(8,1) Lj(8,2) Lj(8,3) Lj(8,4) ### store filters in lower part of vectors filter.1[1:8] <- irs.la8w filter.2[1:Lj(8,2)] <- irs.la8w.2 filter.3[1:Lj(8,3)] <- irs.la8w.3 filter.4[1:Lj(8,4)] <- irs.la8w.4 stack.plot(data.frame(cbind(filter.1,filter.2,filter.3,filter.4))) ### create a simliar plot for the scaling filter irs.la8s <- wavelet.filter("la8","L") irs.la8s.2 <- wavelet.filter("la8","LL") irs.la8s.3 <- wavelet.filter("la8","LLL") irs.la8s.4 <- wavelet.filter("la8","LLLL") filter.1[1:8] <- irs.la8s filter.2[1:Lj(8,2)] <- irs.la8s.2 filter.3[1:Lj(8,3)] <- irs.la8s.3 filter.4[1:Lj(8,4)] <- irs.la8s.4 stack.plot(data.frame(cbind(filter.1,filter.2,filter.3,filter.4)))