# mswthresh

Perform multisignal 1-D thresholding

## Syntax

``Y = mswthresh(X,sorh,T)``
``Y = mswthresh(X,sorh,T,'c')``

## Description

````Y = mswthresh(X,sorh,T)` returns the soft or hard `T`-thresholding of the matrix `X`. `T` can be a single value, a matrix the same size as `X`, or a vector. If `T` is a vector, thresholding is performed row-wise, and `LT = length(T)` must be such that `size(X,1) ≤ LT`. Only the first `size(X,1)` values of `T` are used.```

example

````Y = mswthresh(X,sorh,T,'c')` performs thresholding column-wise, and `LT = length(T)` must be such that `size(X,2) ≤ LT`. Only the first `size(X,2)` values of `T` are used.```

## Examples

collapse all

Create a 3-by-3 matrix and a 1-by-3 vector of threshold values.

`mat = [1 1 3; 1 1 3; 2 2 3]`
```mat = 3×3 1 1 3 1 1 3 2 2 3 ```
`thr = [1 2 3]`
```thr = 1×3 1 2 3 ```

Apply soft thresholding to the matrix row-wise. The kth threshold in `thr` is applied to the kth row of `mat`.

`mswthresh(mat,'s',thr)`
```ans = 3×3 0 0 2 0 0 1 0 0 0 ```

Apply soft thresholding to the matrix column-wise. The kth threshold in `thr` is applied to the kth column of `mat`.

`mswthresh(mat,'s',thr,'c')`
```ans = 3×3 0 0 0 0 0 0 1 0 0 ```

Apply hard thresholding to the matrix row-wise.

`mswthresh(mat,'h',thr)`
```ans = 3×3 0 0 3 0 0 3 0 0 0 ```

Apply hard thresholding to the matrix column-wise.

`mswthresh(mat,'h',thr,'c')`
```ans = 3×3 0 0 0 0 0 0 2 0 0 ```

## Input Arguments

collapse all

Input data to threshold, specified as a real-valued matrix.

Data Types: `double`

Type of thresholding to perform, specified as:

• `'s'` — Soft thresholding

• `'h'` — Hard thresholding

Threshold value, specified as a real-valued scalar or vector.

Data Types: `double`

## Output Arguments

collapse all

Thresholded data, returned as a real-valued 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. 