# wthresh

Soft or hard thresholding

## Syntax

``Y = wthresh(X,sorh,T)``

## 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")```

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")```

## 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`: $\text{Y}=\text{sign(X)}·{\left(|\text{X}|-\text{T}\right)}_{+}$ where

`${\left(x\right)}_{+}=\left\{\begin{array}{ccc}x& \text{if}& x\ge 0\\ 0& \text{otherwise}& \end{array}$`

Soft thresholding is wavelet shrinkage.

If `sorh` is `"h"`, `Y` is the hard thresholding of `X`: $\text{Y}=\text{X}·{1}_{\left(|\text{X}|\text{ }\text{ }>\text{ }\text{ }\text{T}\text{ }\text{ }\right)}$ where

`${1}_{\left(|\text{X}|\text{ }\text{ }>\text{ }\text{ }\text{T}\text{ }\text{ }\right)}=\left\{\begin{array}{ccc}1& \text{if}& |\text{X}|>\text{T}\\ 0& \text{otherwise}& \end{array}$`

Hard thresholding is cruder than soft thresholding.

## Version History

Introduced before R2006a

expand all