Wavelet Tresholding on R

79 views Asked by At

One way to remove noise from a signal is applying the discrete wavelet transform, apply a threshold (soft or hard) and then run the inverse discrete wavelet transform to retrieve the original signal without noise.

R language has dwt and idwt functions (package wavelets) to perform the discrete wavelet transform and inverse discrete wavelet transform. The output of dwt is W (wavelet coefficient) and V (scale coefficient).

My question is: The threshold should be applied on W, on V or both? And why? I'm missing something here because for me should be on W, but it didnt work.

Example:

library(wavelets)
w <- dwt(series_with_noise, filter="la16")
w@W$W1 <- treshold_function(w@W$W1, lambda) # Should I do this?
w@V$V1 <- treshold_function(w@V$V1, lambda) # Should I do this?
series_denoised <- idwt(w)
plot(series_denoised)

If I nullify all w@W but maintaining V the idwt doesnt change. Don't know why =/.

1

There are 1 answers

0
user2554330 On

You should modify the W values if you want to do smoothing. For example:

set.seed(123)
t <- seq(0, 2*pi, len = 512)
x <- sin(t) + rnorm(512)
plot(t, x)

library(wavelets)
wt <- dwt(x, filter = "la16")

names(wt@W)
#> [1] "W1" "W2" "W3" "W4" "W5"
wt@W$W1 <- 0*wt@W$W1
wt@W$W2 <- 0*wt@W$W2
wt@W$W3 <- 0*wt@W$W3
wt@W$W4 <- 0*wt@W$W4
wt@W$W5 <- 0*wt@W$W5

y <- idwt(wt)
lines(t, y, lwd=3)

Created on 2023-12-30 with reprex v2.0.2