Denoising

Shrinking Types and Constructors

Public API

WaveletsExt.Denoising.RelErrorShrinkType
RelErrorShrink(th, t) <: DNFT

Relative Error Shrink method used in their paper "Efficient Approximation and Denoising of Graph Signals using the Multiscale Basis Dictionary" for IEEE Transactions on Signal and Information Processing over Networks, Vol 0, No. 0, 2016.

Attributes

  • th::Wavelets.Threshold.THType: (Default: Wavelets.HardTH()) Threshold type.
  • t::AbstractFloat: (Default: 1.0) Threshold size.

Examples

using Wavelets, WaveletsExt

RelErrorShrink()                    # Using default th and t values
RelErrorShrink(SoftTH())            # Using default t value
RelErrorShrink(HardTH(), 0.5)       # Using user input th and t values

See also: SureShrink, VisuShrink

source
WaveletsExt.Denoising.SureShrinkMethod
SureShrink(xw[, redundant, tree, th])

Struct constructor for SureShrink based on the signal coefficients xw.

Arguments

  • xw::AbstractArray{T} where T<:Number: Decomposed signal.
  • redundant::Bool: (Default: false) Whether the transform type of xw is a redundant transform. Autocorrelation and stationary wavelet transforms are examples of redundant transforms.
  • tree::Union{BitVector, Nothing}: (Default: nothing) The basis tree for decomposing xw. Must be provided if xw is decomposed using wpt, swpd, or acwpd.
  • th::Wavelets.Threshold.THType: (Default: HardTH()) Threshold type.

Returns

::SureShrink: SUREShrink object.

Examples

SureShrink(xw)                  # `xw` is output of dwt, wpt
SureShrink(xw, true)            # `xw` is output of sdwt, acdwt, swpt, acwpd
SureShrink(xw, true, tree)      # `xw` is output of swpd, acwpd

See also: SureShrink, surethreshold

source
Wavelets.Threshold.VisuShrinkType
VisuShrink(n, th)

Extension to the VisuShrink struct constructor from Wavelets.jl.

Arguments

  • n::Integer: Signal length.
  • th::Wavelets.Threshold.THType: Threshold type.

Returns

::Wavelets.Threshold.VisuShrink: VisuShrink object.

Examples

using Wavelets, WaveletsExt

VisuShrink(128, SoftTH())
source

Threshold Determination and Noise Estimation

Public API

Wavelets.Threshold.noisestFunction
noisest(x, redundant[, tree])

Extension to the noisest function from Wavelets.jl. Estimates the standard deviation of a signal's noise assuming that the noise is distributed normally. This function is generally used in combination with VisuShrink and SureShrink in the denoise/denoiseall functions.

Arguments

  • x::AbstractArray{T}: Decomposed signal.
  • redundant::Bool: Whether the transform type of xw is a redundant transform. Autocorrelation and stationary wavelet transforms are examples of redundant transforms.
  • tree::Union{BitVector, Nothing}: (Default: nothing) The basis tree for decomposing xw. Must be provided if xw is decomposed using wpt, swpd, or acwpd.

Returns

::AbstractFloat: Estimated standard deviation of the noise of the signal.

Examples

using Wavelets, WaveletsExt

x = randn(128)
wt = wavelet(WT.haar)

# noise estimate for dwt transformation
y = dwt(x, wt)
noise = noisest(y, false)

# noise estimate for wpt transformation
tree = maketree(x, :full)
y = wpt(x, wt, tree)
noise = noisest(y, false, tree)

# noise estimate for sdwt transformation
y = sdwt(x, wt)
noise = noisest(y, true)

# noise estimate for swpd transformation
y = swpd(x, wt)
noise = noisest(y, true, tree)

See also: relerrorthreshold, VisuShrink, SureShrink

source
WaveletsExt.Denoising.relerrorthresholdFunction
relerrorthreshold(coef, [redundant, tree, elbows; makeplot])

Takes in a set of expansion coefficients, 'plot' the threshold vs relative error curve and select the best threshold value based on the elbow method. If one wants to see the resulting plot from this computation, simply set makeplot=true.

Arguments

  • coef::AbstractArray{T} where T<:Number: Decomposed signal.
  • redundant::Bool: (Default: false) Whether the transform type of xw is a redundant transform. Autocorrelation and stationary wavelet transforms are examples of redundant transforms.
  • tree::Union{BitVector, Nothing}: (Default: nothing) The basis tree for decomposing xw. Must be provided if xw is decomposed using swpd or acwpd.
  • elbows::Integer: (Default: 2) Number of elbows used to determine the best threshold value.

Keyword Arguments

  • makeplot::Bool: (Default: false) Whether to return the plot that was used to determine the best threshold value.

Returns

  • ::AbstractFloat: Best threshold value.
  • ::GR.Plot: Plot that was used to determine the best threshold value. Only returned if makeplot = true.

Examples

x = randn(128)
wt = wavelet(WT.haar)

# noise estimate for dwt transformation
y = dwt(x, wt)
noise = relerrorthreshold(y, false)

# noise estimate for wpt transformation
tree = maketree(x, :full)
y = wpt(x, wt, tree)
noise = relerrorthreshold(y, false, tree)

# noise estimate for sdwt transformation
y = sdwt(x, wt)
noise = relerrorthreshold(y, true)

# noise estimate for swpd transformation
y = swpd(x, wt)
noise = relerrorthreshold(y, true, tree)

See also: noisest, RelErrorShrink

source

Denoising Functions

Public API

Wavelets.Threshold.denoiseFunction
denoise(x, inputtype, wt[; L=maxtransformlevels(size(x,1)),
    tree=maketree(size(x,1), L, :dwt), dnt=VisuShrink(size(x,1)),
    estnoise=noisest, smooth=:regular])

Extension of the denoise function from Wavelets.jl. Denoise a signal of input type inputtype.

Arguments:

  • x::AbstractArray{<:Number}: input signals/coefficients.
  • inputtype::Symbol: input type of x. Current accepted types of inputs are
    • :sig: original signals; x should be a 2-D array with each column representing a signal.
    • :dwt: dwt-transformed signal coefficients; x should be a 1-D array with each column representing the coefficients of a signal.
    • :wpt: wpt-transformed signal coefficients; x should be a 1-D array with each column representing the coefficients of a signal.
    • :sdwt: sdwt-transformed signal coefficients; x should be a 2-D array with each column representing the coefficients of a node.
    • :swpd: swpd-transformed signal coefficients; x should be a 2-D array with each column representing the coefficients of a node.
    • :acdwt: acdwt-transformed signal coefficients from AutocorrelationShell.jl; x should be a 2-D array with each column representing the coefficients of a node.
    • :acwpd: acwpd-transformed signal coefficients from AutocorrelationShell.jl; x should be a 2-D array with each column representing the coefficients of a node.
  • wt::Union{DiscreteWavelet, Nothing}: the discrete wavelet to be used for decomposition (for input type :sig) and reconstruction. nothing can be supplied if no reconstruction is necessary.
  • L::Integer: the number of decomposition levels. Necessary for input types :sig, :dwt, and :sdwt. Default value is set to be maxtransformlevels(size(x,1)).
  • tree::BitVector: the decomposition tree of the signals. Necessary for input types :wpt and :swpd. Default value is set to be maketree(size(x,1), L, :dwt).
  • dnt::DNFT: denoise type. Default type is set to be VisuShrink(size(x,1)).
  • estnoise::Union{Function, Vector{<:Number}}: noise estimation. Input can be provided as a function to estimate noise in signal, or a vector of estimated noise. Default is set to be the noisest function.
  • smooth::Symbol: the smoothing method used. :regular smoothing thresholds all given coefficients, whereas :undersmooth smoothing does not threshold the lowest frequency subspace node of the wavelet transform. Default is set to be :regular.

See also: denoiseall, noisest, relerrorthreshold

source
WaveletsExt.Denoising.denoiseallFunction
denoiseall(x, inputtype, wt[; L=maxtransformlevels(size(x,1)),
    tree=maketree(size(x,1), L, :dwt), dnt=VisuShrink(size(x,1)),
    estnoise=noisest, bestTH=nothing, smooth=:regular])

Denoise multiple signals of input type inputtype.

Arguments:

  • x::AbstractArray{<:Number}: input signals/coefficients.
  • inputtype::Symbol: input type of x. Current accepted types of inputs are
    • :sig: original signals; x should be a 2-D array with each column representing a signal.
    • :dwt: dwt-transformed signal coefficients; x should be a 2-D array with each column representing the coefficients of a signal.
    • :wpt: wpt-transformed signal coefficients; x should be a 2-D array with each column representing the coefficients of a signal.
    • :sdwt: sdwt-transformed signal coefficients; x should be a 3-D array with each 2-D slice representing the coefficients of a signal.
    • :swpd: swpd-transformed signal coefficients; x should be a 3-D array with each 2-D slice representing the coefficients of a signal.
    • :acdwt: acdwt-transformed signal coefficients from AutocorrelationShell.jl; x should be a 3-D array with each 2-D slice representing the coefficients of a signal.
    • :acwpd: acwpd-transformed signal coefficients from AutocorrelationShell.jl; x should be a 3-D array with each 2-D slice representing the coefficients of a signal.
  • wt::Union{DiscreteWavelet, Nothing}: the discrete wavelet to be used for decomposition (for input type :sig) and reconstruction. nothing can be supplied if no reconstruction is necessary.
  • L::Integer: the number of decomposition levels. Necessary for input types :sig, :dwt, and :sdwt. Default value is set to be maxtransformlevels(size(x,1)).
  • tree::BitVector: the decomposition tree of the signals. Necessary for input types :wpt and :swpd. Default value is set to be maketree(size(x,1), L, :dwt).
  • dnt::DNFT: denoise type. Default type is set to be VisuShrink(size(x,1)).
  • estnoise::Union{Function, Vector{<:Number}}: noise estimation. Input can be provided as a function to estimate noise in signal, or a vector of estimated noise. Default is set to be the noisest function.
  • bestTH::Union{Function, Nothing}: method to determine the best threshold value for a group of signals. If nothing is given, then each signal will be denoised by its respective best threshold value determined from the parameters dnt and estnoise; otherwise some function can be passed to determine the best threshold value from a vector of threshold values, eg: mean and median. Default is set to be nothing.
  • smooth::Symbol: the smoothing method used. :regular smoothing thresholds all given coefficients, whereas :undersmooth smoothing does not threshold the lowest frequency subspace node of the wavelet transform. Default is set to be :regular.

See alse: denoise, noisest, relerrorthreshold

source

Helper Functions for Threshold Determination and Noise Estimation

Private API

WaveletsExt.Denoising.surethresholdFunction
surethreshold(coef, redundant[, tree])

Determination of the t value used for SureShrink. t is defined as the threshold value when the standard deviation of the noisy signal is 1.

Arguments

  • coef::AbstractArray{T} where T<:Number: Coefficients of decomposed signal.
  • redundant::Bool: Whether the transform type of xw is a redundant transform. Autocorrelation and stationary wavelet transforms are examples of redundant transforms.
  • tree::Union{BitVector, Nothing}: (Default: nothing) The basis tree for decomposing xw. Must be provided if xw is decomposed using wpt, swpd, or acwpd.

Returns

::AbstractFloat: t value used for SureShrink.

See also: SureShrink

source
WaveletsExt.Denoising.orth2relerrorFunction
orth2relerror(orth)

Given a vector 'orth' of orthonormal expansion coefficients, return a vector of relative approximation errors when retaining the 1,2,...,N largest coefficients in magnitude.

Arguments

  • orth::AbstractVector{T} where T<:Number: Vector of coefficients.

Returns

::Vector{T}: Relative errors.

See also: RelErrorShrink, relerrorthreshold, findelbow

source
WaveletsExt.Denoising.findelbowFunction
findelbow(x, y)

Given the x and y coordinates of a curve, return the elbow.

Arguments

  • x::AbstractVector{T} where T<:Number: x-coordinates.
  • y::AbstractVector{T} where T<:Number: y-coordinates.

Returns

  • ::Integer: Index of the elbow point.
  • ::Vector{T}: Length of adjacent sides.
  • ::Vector{T}: The y-coordinates going in the direction of (x₁, y₁) to (xₙ, yₙ)

See also: RelErrorShrink, relerrorthreshold, orth2relerror

source
WaveletsExt.Denoising.relerrorplotFunction
relerrorplot(x, y, ix, A, v)

Relative error plot used for threshold determination using the elbow rule.

Arguments

  • x::Vector{T} where T<:Number: x-coordinates.
  • y::Vector{T} where T<:Number: y-coordinates.
  • ix::Vector{<:Integer}: Indices for elbow points.
  • A::Vector{S} where {S<:Vector{T}, T<:Number}: Length of adjacent sides.
  • v::Vector{S} where {S<:Vector{T}, T<:Number}: The y-coordinates going in the direction of (x[1], y[1]) to (x[ix], y[ix])

Returns

::Plot: Relative error plot.

See also: relerrorthreshold, findelbow

source