Main Content

wthresh

Soft or hard thresholding

Description

Y = wthresh(X,sorh,T) returns the soft or hard thresholding, indicated by sorh, of the vector or matrix X. T is the threshold value.

example

Examples

collapse all

Generate a signal and set a threshold.

y = linspace(-1,1,100);
thr = 0.4;

Perform hard and soft thresholding.

yhard = wthresh(y,"h",thr);
ysoft = wthresh(y,"s",thr);

Plot the results and compare with the original signal.

tiledlayout(1,3)
nexttile
plot(y,y)
ylim([-1 1])
title("Original Signal")
nexttile
plot(y,yhard)
ylim([-1 1])
title("Hard Threshold")
nexttile
plot(y,ysoft)
ylim([-1 1])
title("Soft Threshold")

Figure contains 3 axes objects. Axes object 1 with title Original Signal contains an object of type line. Axes object 2 with title Hard Threshold contains an object of type line. Axes object 3 with title Soft Threshold contains an object of type line.

Load the noisy Doppler signal. Obtain the nondecimated discrete wavelet transform of the signal down to level 4.

load noisdopp
wt = modwt(noisdopp,4);

Determine the Donoho-Johnstone universal threshold based on the finest-scale wavelet coefficients.

thr = median(abs(wt(1,:)-median(wt(1,:))))/0.6745;

Apply soft thresholding to the wavelet transform and invert the result to obtain a denoised signal.

wtthr = wthresh(wt,"s",thr);
xden = imodwt(wtthr);

Plot the original and denoised signals.

plot([noisdopp(:) xden(:)])
axis tight
legend("Original","Thresholded",Location="southeast")

Figure contains an axes object. The axes object contains 2 objects of type line. These objects represent Original, Thresholded.

Input Arguments

collapse all

Input data to threshold, specified as a vector or matrix.

Data Types: single | double
Complex Number Support: Yes

Type of thresholding to perform:

  • "s" — Soft thresholding

  • "h" — Hard thresholding

Threshold value, specified as a positive real number.

Data Types: single | double

Output Arguments

collapse all

Thresholded data, returned as a vector or matrix. Y has the same dimensions as X.

Algorithms

If sorh is "s", Y is the soft thresholding of X: Y=sign(X)·(|X|T)+ where

(x)+={xifx00otherwise

Soft thresholding is wavelet shrinkage.

If sorh is "h", Y is the hard thresholding of X: Y=X·1(|X|>T) where

1(|X|>T)={1if|X|>T0otherwise

Hard thresholding is cruder than soft thresholding.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a

expand all