Signal Denoising
Wavelet denoising is an important step in signal analysis as it helps remove unnecessary high frequency noise while maintaining the most important features of the signal. Intuitively, signal denoising comes in the following simple steps:
- Decompose a signal or a group of signals. One can choose to decompose signals into its best basis tree for more optimal results.
- Find a suitable threshold value. There are many ways to do so, with VisuShrink (D. Donoho, I. Johnstone) being one of the most popular approaches. The VisuShrink implementation in Wavelets.jl, along with the RelErrorShrink and the SureShrink implementations in WaveletsExt.jl give users more threshold selection options.
- Threshold the wavelet coefficients. There are various thresholding methods implemented in Wavelets.jl for this purpose, with Hard and Soft thresholding being the usual go-to method due to its simplistic approach.
- Reconstruct the original signals using the thresholded coefficients.
For more information and examples on wavelet denoising using WaveletsExt.jl, visit Wavelets Denoising Experiment repository under UCD4IDS for a step-by-step tutorial in a Pluto notebook. The following is a simple guide on denoisng using WaveletsExt.jl.
Denoising a single signal
To denoise a single signal, one can use the denoise
function from WaveletsExt.jl as shown below. Note the following key parameters:
x
: Input signal.inputtype
: Type of input. One can input an original signal:sig
, or first transform the signal and type in one of:dwt
,:wpt
,:sdwt
,:swpd
,:acdwt
, and:acwpd
.wt
: Transform wavelet.L
: Number of decomposition levels. Necessary for input types:sig
,:dwt
, and:sdwt
.tree
: Decomposition tree of the signals. Necessary for input types:wpt
and:swpd
.dnt
: Denoise type. One should input either of VisuShrink, RelErrorShrink, or SureShrink.estnoise
: Noise estimation. Can be a function or a value.smooth
: Smoothing method used.
For more detailed information, visit the denoising API page.
using Wavelets, WaveletsExt, Random, Plots
# define function and wavelet
x₀ = generatesignals(:heavisine, 8)
x = x₀ + 0.8*randn(256)
wt = wavelet(WT.db4)
# best basis tree
xw = wpd(x, wt)
bt = bestbasistree(xw, BB())
y = getbasiscoef(xw, bt)
# denoise
x̂ = denoise(y, :wpt, wt, tree=bt)
# plot results
plot([x₀ x x̂], title="Denoising Example", label=["original" "noisy" "denoised"],
lw=[3 1 2], lc=[:black :grey :red])
Denoising a group of signals
Similar to the denoise
function we saw previously, for denoising a group of signals, one can use the denoiseall
function. The parameters used are the same, with the following addition:
bestTH
: Method to determine the best threshold value for a group of signals. One can choose each signal's individual best threshold value, or use a function such asmean
ormedian
to generalize an overall best threshold value.
For more detailed information, visit the denoising API page.
using Wavelets, WaveletsExt, Random, Plots
# define function and wavelet
x = generatesignals(:heavisine, 8)
X₀ = duplicatesignals(x, 6, 2, false)
X = duplicatesignals(x, 6, 2, true, 0.8)
wt = wavelet(WT.db4)
# decomposition
coef = wpdall(X, wt)
# best basis tree
bt = bestbasistree(coef, JBB())
Y = getbasiscoefall(coef, bt)
# denoise
X̂ = denoiseall(Y, :wpt, wt, tree=bt)
# plot results
wiggle(X₀, sc=0.7, FaceColor=:white, ZDir=:reverse)
wiggle!(X, sc=0.7, EdgeColor=:grey, FaceColor=:white, ZDir=:reverse)
wiggle!(X̂, sc=0.7, EdgeColor=:red, FaceColor=:white, ZDir=:reverse)
plot!(title="Group Denoising Example")