0
$\begingroup$

I have implemented Haar Function in MATLAB based on formulas stated here. However this formulas generate functions only between 0 and 1 (on [0..1] interval). I need to generate such functions periodically from -infinity to +infinity for instance with period = 1. It should depend on length of my time vector. For example if time vector on interval [0..10] I should generate Haar function vector on the same interval [0..10]. I hope you get a point. Here is my MATLAB code.

function [ f ] = haar(x)
%Haar function
%   x: time vector
vectorLength = length(x);
f = zeros(1, vectorLength);
for k = 1:vectorLength
    if (x(k) >= 0 && x(k) < 1/2)
        f(k) = 1;
    elseif (x(k) > 1/2 && x(k) <= 1)
        f(k) = -1;
    end;
end;
end
$\endgroup$
6
  • $\begingroup$ What if your vector length is odd? $\endgroup$
    – Phonon
    Feb 7, 2013 at 11:26
  • $\begingroup$ I don't see any hard dependencies on vector length. Basically the same function pattern from 0 to 1 should be repeated periodically with period = 1. If vector length is higher then more times this pattern will be repeated. $\endgroup$ Feb 7, 2013 at 11:56
  • $\begingroup$ How about multiplying the relevant part of code with max(x)-min(x) $\endgroup$ Feb 7, 2013 at 12:14
  • 5
    $\begingroup$ This is more of a programming question than anything, but I just wanted to point out that it looks like the periodic extension of this wavelet would be nothing more than a square wave. You could use something like f = 1 - 2 * (mod(x,1) >= 0.5);. $\endgroup$
    – Jason R
    Feb 7, 2013 at 13:29
  • $\begingroup$ This formula produces different results on [0..1] interval. $\endgroup$ Feb 8, 2013 at 10:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.