Computing DWT
This is actually straightforward. Use dwt
to obtain the approximation and detail coefficients. For instance, a DWT using a daubechies 4-tap wavelet would be:
[cA, cD] = dwt(X, 'db4')
where X
is your data.
If each sample in X
has several fields, and you want to apply the DWT just on a certain field, say X.closing_price
, add square brackets:
[cA, cD] = dwt([X.closing_price], 'db4')
Note that this solution assumes that the data samples are taken at constant time intervals.
To plot the data, you need to prepare another vector, which corresponds to the day number:
t = 1:2:length(X);
The x-axis values skips every other day because the approximation and detail coefficients vectors each have half of the samples of X
.
Demo code
The following code generates random data and puts it into an array of structs, each element having two fields: date
and closing_price
:
%# Generate some random data
C = cell(31, 2);
C(:, 1) = arrayfun(@(z)[num2str(z), '-Oct-03'], 1:length(C), 'Un', 0);
C(:, 2) = num2cell(100 * randn(1, length(C)));
X = cell2struct(C, {'date', 'closing_price'}, 2);
Now, to business:
%# Apply DWT
[cA, cD] = dwt([X.closing_price], 'db4');
%# Prepare x-axis values
t = 1:2:length(X);
%# Plot result with respect to date
figure
subplot(2, 1, 1), plot(t, cA)
title('Approximation coefficients'), xlabel('day'), ylabel('C_A')
subplot(2, 1, 2), plot(t, cD)
title('Detail coefficients'), xlabel('day'), ylabel('C_D')
This is what you should get:

Hope that helps!