Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.

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
share|improve this question
    
What if your vector length is odd? –  Phonon Feb 7 '13 at 11:26
    
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. –  Pavel Shchegolevatykh Feb 7 '13 at 11:56
    
How about multiplying the relevant part of code with max(x)-min(x) –  Dennis Jaheruddin Feb 7 '13 at 12:14
5  
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);. –  Jason R Feb 7 '13 at 13:29
    
This formula produces different results on [0..1] interval. –  Pavel Shchegolevatykh Feb 8 '13 at 10:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.