Main Content


Haar 1-D wavelet transform



[a,d] = haart(x) returns the approximation coefficients, a, and detail coefficients, d, of a 1-D Haar discrete wavelet transform. The input x can be univariate or multivariate data. The default level depends on the length of x.


[a,d] = haart(x,level) obtains the Haar transform down to the specified level.


[a,d] = haart(___,integerflag) specifies how the Haar transform handles integer-valued data, using any of the previous syntaxes.


collapse all

Obtain the Haar transform down to the default maximum level.

load wecg;
[a,d] = haart(wecg);

Obtain the Haar transform of a multivariate time series dataset of electricity consumption data down to level 4. The signals data is transposed so that each time series is in a column, rather than a row.

load elec35_nor;
signals = signals';
[a,d] = haart(signals,4);

Obtain the Haar transform and inverse Haar transform of ECG heart rate data. The data is made up of integers only.

Load and plot the ECG data.

load BabyECGData;
ylabel('Heart Rate')
title('ECG Data')

Obtain the Haar transform. Then, obtain the inverse Haar transform approximated at level 5. The scale for this level is 512 seconds, which is 25 times the sampling interval (16 seconds).

[a,d] = haart(HR,'integer');
HaarHR = ihaart(a,d,5,'integer');

Compare the reconstructed data to the original data.

ylabel('Heart Rate')
title('Haar Approximation of Heart Rate')

Input Arguments

collapse all

Input signal, specified as vector or matrix of real values. If x is a vector, it must be even length. If x is a matrix, each column must be even length, and haart operates on each column of x.

Data Types: double

Maximum level to which to perform the Haar transform, specified as a positive integer. The default value depends on the length of the input signal, x.

  • If the length of x is a power of two, the Haar transform is obtained down to level log2(length(x)).

  • If the length of x is even, but not a power of two, the Haar transform is obtained down to level floor(log2(length(x)/2)).

If level is 1, the detail coefficients, d, are returned as a vector or matrix, depending on whether the input is a vector or matrix, respectively.

Integer-valued data handling, specified as either 'noninteger' or 'integer'. 'noninteger' does not preserve integer-valued data in the Haar transform, and 'integer' preserves it. The 'integer' option applies only if all elements of the input, x, are integers. For integer-valued input, haart returns integer-valued wavelet coefficients. For both 'noninteger' and 'integer', however, the Haar transform algorithm uses floating-point arithmetic. The data type of outputs a and d, is always double.

Output Arguments

collapse all

Approximation coefficients, returned as a scalar, vector, or matrix of coefficients, depending on the level to which the transform is calculated. Approximation, or scaling, coefficients are a lowpass representation of the input. At each level, the approximation coefficients are divided into coarser approximation and detail coefficients.

Data Types: double

Detail coefficients, returned as a scalar, vector, matrix, or cell array. Detail coefficients are generally referred to as wavelet coefficients. The number of detail coefficients depends on the selected level and the length of the input. If d is a cell array, the elements of d are ordered from finest to coarsest resolution.

Note: Generated C and C++ code always returns the wavelet coefficients d in a cell array.

Data Types: double

Extended Capabilities

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

Introduced in R2016b