[1]
W = (Wu_{1}) u_{1}
+ (Wu_{2}) u_{2}
+ ... + (Wu_{n}) u_{n}
= Σ(Wu_{j}) u_{j}
The n numbers (Wu_{j}) (with j going from 1 to n)
are the coefficients in the expansion of W in terms of the orthonormal basis.
>And that's interesting ... to you?
NOW comes the interesting part:
The guy we're calling W could be a function of time, W(t).
If we're careful we can choose
an "orthonormal basis" which will be a collection of functions and we can express W(t) as a sum of these basis functions u_{j}(t).
W(t) = a_{1} u_{1}(t) + a_{2} u_{2}(t) + a_{3} u_{3}(t) + ......
Wellknown examples include the Fourier Series expansion of a function.
The function W shown in Figure 2 is a sum: W(t) = u_{1}(t)  (0.5)u_{2}(t)  (0.1)u_{3}(t)
... where u_{1}(t) = sin(t), u_{2}(t) = sin(2t) and u_{3}(t) = sin(3t).
The collection of functions sin(t), sin(2t), sin(3t) etc. etc. can be used as a basis to generate (almost) any function defined on 0 ≤ t ≤ 2π.
Note that W must have an average value of 0 since all the sinefunctions do.
Indeed, if W(t) is a periodic function (like a note played on a violin) then the components u_{1}, u_{2}, u_{3} etc.
are the harmonics (or overtones) associated with that note and ...
>Yeah, I remember listening to the Beatles and ...
Pay attention!
A more "complete" basis would be: 1, cos(t), sint(t), cos(2t), sin(2t), cos(3t), sin(3t), etc.
For example, if W(0) weren't 0 and/or W(t) weren't the negative of W(t)
then using only sine functions wouldn't work.
 Figure 2 
Indeed, sin(0) = 0 and sin(t) =  sin(t) and, of course, all sine and cosine functions have an average value of 0 over an interval such as (π, π) or (0, 2π)
... which explains the need to include that first constant function: 1 (in case W has an average different than 0).
For example, here W(t) = 1 + sin(t)  (0.5)cos(2t)  (0.1)sin(3t).
Our objective is to show that, for our Stock Prices, we can use Haar Wavelets as our basis functions.
Alfréd Haar (1885  1933), a Hungarian mathematician, mentioned these guys in an appendix to his doctoral thesis.
>You said you needed some dot product, or scalar or inner producat ... or whatever you call it.
Oh, yes, I almost forget.
For our sines and cosines we'd use:
[2]
uv= _{∫} u_{j}(t) v_{k}(t) dt
where u_{j}(t) and v_{k}(t) are sin(jt) or cos(jt) or sin(kt) or cos(kt) and the integration is over, say 0 ≤ t ≤ 2π 
In fact, _{∫} sin(jt) sin(kt) dt
= _{∫} sin(jt) cos(kt) dt = _{∫} cos(jt) cos(kt) dt = 0 if j ≠ k.
>So they're orthonormal?
Uh ... not exactly. They're orthogonal, to be sure, but the scalar product of a basis with itself isn't "1", because
_{∫} sin^{2}(jt) dt = _{∫} cos^{2}(jt) dt = π.
>So divide each by π^{1/2} and they'd be orthonormal, right?
Yes, but it's messy having that π^{1/2} hanging around. We'll stick it in when we need it.
>But what about that very first basis function ... the "1"?
Aah, yes. If we let u_{0}(t) = 1, then
_{∫} u_{0}(t) u_{k}(t) dt = 0 if k ≠ 0
since _{∫}sin(kt) dt = _{∫}cos(kt) dt = 0
and
_{∫} u_{0}^{2}(t)dt = 2π.
Anyway, we can now write for (almost) any function f(t):
f(t) = a_{0} + a_{1}cos(t) + b_{1}sin(t) + a_{2}cos(2t) + b_{2}sin(2t) + a_{3}cos(3t) + b_{3}sin(3t) + ...
To find the constants a_{0}, a_{1}, b_{1}, etc. we use [1]
(with an infinite number of basis functions) and the scalar product defined by [2].
Now, with Haar Wavelets ...
>How about an example ... a Fourier series with some sexy f(t)?
Okay, let's try f(t) a square wave, like so:
Our f(t) is an "odd" function (meaning that f(t) =  f(t)) so we only need the sine functions in our basis.
We write f(t) = Σb_{k} sin(kt).
Multiply each side by sin(mt) (for an arbitrary integer m) and integrate from t = 0 to t = 2π.
Then _{∫}f(t) sin(mt) dt = Σb_{k} sin(mt) sin(kt) dt.
That's equivalent to taking the scalar product, eh?
 
All the terms on the right side integrate to 0 except the one where k = m.
That integration (of the right side) gives Σb_{k} sin^{2}(mt) dt = π b_{m}.
For the left side, we split the integral into two parts:
_{∫}_{1}sin(mt) f(t) dt + _{∫}_{2} sin(mt) f(t) dt
The first integration is from t = 0 to t = π (where f(t) = 1) and the second is from t = π to t = 2π (where f(t) = 1).
That gives: _{∫}_{1} sin(mt) dt
 _{∫}_{2} sin(mt) dt
= (1/m) [cos(mπ)  cos(0)]  (1/m) [cos(2mπ)  cos(mπ)] = (1/m) ( 2  2cos(mπ) ) = 0 unless m is an odd integer
(which makes cos(mπ) = 1).
When m is an odd integer, we get: 4/m.
Finally, then, we have 4/m = π b_{m} when m =1, 3, 5, etc., otherwise we get b_{m} = 0 (for m an even integer).
That makes b_{m} = 4/(mπ) for m = 1, 3, 5 etc. and our square wave is then represented as the Fourier Series:
f(t) = 4/(π)[ sin(t) + (1/3) sin(3t) + (1/5) sin(5t) + (1/7) sin(7t) + ... ]
If we take just ten terms of the Fourier Series, namely
4/π[ sin(t) + (1/3) sin(3t) + (1/5) sin(5t) + (1/7) sin(7t) + ... + sin(19t)]
... we'd get Figure 3.
>The Fourier Series is periodic, but what if f(t) isn't?
Aah, if you use a series with these sines and/or cosines, you're going to get a periodic representation.
Of course, with Haar Wavelets ...
>Maybe it's time to switch to Haar, eh?
Good idea!
 Figure 3 
to continue
P.S.
There's a spreadsheet to play with which lets you gaze in awe at the sum of terms in a Fourier Series (up to 10 terms).
It looks like this (Click on the picture to download):
