# sensingDictionary

Sensing dictionary for sparse signal recovery

## Description

Use sensingDictionary to create a sensing dictionary object for sparse approximations of 1-D signals. The sensingDictionary function provides built-in support for a variety of frames, including wavelet, discrete cosine transform (DCT), Fourier, and Gaussian and Bernoulli random distributions. You can also create and use custom dictionaries. You can apply your dictionary for signal sparse recovery using matching pursuit or basis pursuit. Additionally, the basis pursuit algorithm supports custom dictionaries created using tall arrays. You can apply these custom dictionaries to tall array inputs.

## Creation

### Description

A = sensingDictionary creates a sensing dictionary that corresponds to the 100-by-100 identity matrix.

example

A = sensingDictionary(Name=Value) creates a sensing dictionary with properties specified by name-value arguments. For example, A = sensingDictionary(Type={'dct'}) creates a sensing dictionary corresponding to the dct basis type. You can specify multiple name-value arguments.

## Properties

expand all

Sensing dictionary size, specified as a positive integer or two-element vector of positive integers. If you specify the size as [m,n], the number of rows in the sensing dictionary is m, and the number of columns is n. If you specify the size as a scalar m, the number of rows in the dictionary is m, and the number of columns depends on the type of dictionary. For random dictionaries, you must specify the size as a two-element vector.

Note

You cannot change the size of an existing sensing dictionary. For example, if the size of the sensing dictionary A is [100 100], you cannot assign a different Size to A.

Example: A = sensingDictionary(Size=[50 50],Type={'dct','poly'}) creates a sensing dictionary A consisting of the basis types 'dct' and 'poly'. The size of the matrix of each type is 50-by-50 and A.Size = [50 100].

Data Types: double

Dictionary basis type, specified as a cell array of character vectors. Each character vector specifies a basis type in the sensing dictionary A. For each basis type, the basis elements are arranged columnwise in the matrix. Each basis element is length N, where N = A.Size(1). The sensingDictionary object supports the following basis types:

• 'eye' (default) — Dictionary corresponds to an identity matrix.

• 'dct' — Dictionary corresponds to the discrete cosine transform-II basis. The DCT-II orthonormal basis is:

${\varphi }_{k}\left(n\right)=\left\{\begin{array}{ll}\frac{1}{\sqrt{N}}\hfill & k=0\hfill \\ \sqrt{\frac{2}{N}}\mathrm{cos}\left(\frac{\pi }{N}\left(n+\frac{1}{2}\right)k\right)\hfill & k=1,2,\dots ,N-1.\hfill \end{array}$

• 'dwt' — Dictionary corresponds to a specific wavelet basis from a certain level of decomposition.

• 'fourier' — Dictionary corresponds to the Fourier basis. The Fourier basis is ${\varphi }_{k}\left(t\right)=\frac{{e}^{2\pi ikt/N}}{\sqrt{N}}$, where k = 0, …, N-1, and t = 0, …, N-1.

• 'poly' — The kth column of the dictionary matrix corresponds to monomials of the form t.^(k-1), where t is the time interval specified by linspace(0,1,N) and k = 1,...,N.

• 'rand' — Dictionary matrix entries are either an independent identically distributed (IID) Gaussian matrix (default) or a Bernoulli matrix.

• 'walsh' — Dictionary matrix entries are generated from Walsh code.

Example: A = sensingDictionary('Type',{'eye','dct'}) creates a sensing dictionary with basis types 'eye' and 'dct'.

Data Types: char | string

Basis name, specified as a cell array of character vectors. Name is supported only for the following basis types.

• 'dwt' — Character vectors are the names of orthogonal wavelets supported by the modwt function:

• 'haar' or 'db1' (default) — Haar wavelet.

• 'dbN' — Extremal phase Daubechies wavelet with N vanishing moments, where N is a positive integer from 2 to 45.

• 'symN' — Symlets wavelet with N vanishing moments, where N is a positive integer from 2 to 45.

• 'coifN' — Coiflets wavelet with N vanishing moments, where N is a positive integer from 1 to 5.

• 'fkN' — Fejér-Korovkin wavelet with N coefficients, where N = 4, 6, 8, 14, 18 and 22.

• 'rand' — Character vectors are the names of random matrices:

• 'Gaussian' (default) — IID Gaussian matrix.

• 'Bernoulli' — Bernoulli matrix.

If not all basis types specified in Type support Name, insert an empty character vector in the corresponding positions in Name.

CommandResult
A = sensingDictionary(Size=[50 50],...
Type={'dwt','rand'},...
Name={'coif4','Bernoulli'});
Creates a sensing dictionary that corresponds to the coif4 wavelet basis and a random Bernoulli matrix.

A = sensingDictionary(Size=[50 50],...
Type={'dwt','dct','rand'},...
Name={'coif4','','Bernoulli'});

Creates a sensing dictionary that corresponds to the coif4 wavelet basis, DCT basis, and a random Bernoulli matrix.

Data Types: char | string

Decomposition level of the wavelet basis, specified as an integer or vector of positive integers. You can specify Level only if you specify at least one wavelet basis in Type. If you specify wavelet and other basis types in Type, you can either set the level of the other basis to 0, or omit it. The number of nonzero elements you specify must be less than or equal to the number of 'dwt' types.

CommandResult
A = sensingDictionary(Type={'dwt'},...
Name={'db2'},...
Level=[3]);
Creates a sensing dictionary that corresponds to the level 3 db2 wavelet details.

A = sensingDictionary(Type={'dwt','fourier'},...
Name={'db2'},...
Level=[3 0]);
or
A = sensingDictionary(Type={'dwt','fourier'},...
Name={'db2'},...
Level=[3]);

Creates a sensing dictionary that corresponds to the level 3 db2 wavelet details and the Fourier basis.

Data Types: double

Custom sensing dictionary matrix, specified as a matrix. You cannot simultaneously specify CustomDictionary and any other property.

Example: A = sensingDictionary(CustomDictionary=xmat) creates a sensing dictionary using the custom matrix xmat.

Data Types: single | double
Complex Number Support: Yes

## Object Functions

 matchingPursuit Recover sparse signal using matching pursuit algorithm basisPursuit Recover sparse signal using the basis pursuit algorithm horzcat Horizontal concatenation of two sensing dictionaries subdict Extract submatrix from a sensing dictionary

## Examples

collapse all

Create the sensing dictionary that is a concatenation of the level 2 db1 wavelet and DCT bases.

A = sensingDictionary(Size=100,Type={'dwt','dct'},...
Name={'db1'},...
Level=[2 0])
A =
sensingDictionary with properties:

Type: {'dwt'  'dct'}
Name: {'db1'  ''}
Level: [2 0]
CustomDictionary: []
Size: [100 200]

Create a sensing dictionary consisting of basis types eye and poly. The size of each basis type is 150-by-150.

A = sensingDictionary(Size=150,Type={'eye','poly'});

Use the subdict object function to extract one basis vector from each basis type. Create a signal by multiplying the sum of the vectors by 2.

indA = 20;        % basis vector in 'eye'
indB = 160;       % basis vector in 'poly'
btv = subdict(A,1:150,[indA indB]);
sig = 2*sum(btv,2);

Obtain the best fit of the signal using the sensing dictionary A and matching pursuit algorithm with default settings.

[Xr,YI,I,R] = matchingPursuit(A,sig);
norm(sig-YI)
ans = 6.1693e-09

Inspect the indices.

I
I = 1×2

20   160

Inspect the coefficients.

Xr(I)
ans = 2×1

2.0000
2.0000

## Version History

Introduced in R2022a