Haar 1-D wavelet transform
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; plot(times,HR) xlabel('Hours') 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 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.
figure; plot(times,HaarHR) xlabel('Hours') ylabel('Heart Rate') title('Haar Approximation of Heart Rate')
x— Input signal
Input signal, specified as vector or matrix of real values.
If x is a vector, it must be even length. If
a matrix, each column must be even length, and
on each column of
level— Maximum level
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,
If the length of
x is a power
of two, the Haar transform is obtained down to level
If the length of
x is even, but
not a power of two, the Haar transform is obtained down to level
level is 1, the detail coefficients,
are returned as a vector or matrix, depending on whether the input
is a vector or matrix, respectively.
integerflag— Integer-valued data handling
Integer-valued data handling, specified as either
'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
returns integer-valued wavelet coefficients. For
'integer', however, the Haar
transform algorithm uses floating-point
arithmetic. The data type of outputs
a— Approximation coefficients
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.
d— Detail coefficients
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.