About alternatives to Matlab

Filip Wasilewski filipwasilewski at gmail.com
Sun Nov 19 15:33:27 EST 2006


sturlamolden wrote:
>
> Actually, there was a typo in the original code. I used d1[l-1] where I
> should have used d1[l+1]. Arrgh. Here is the corrected version, the
> Matlab code must be changed similarly. It has no relevance for the
> performance timings though.
>
>
> def D4_Transform(x, s1=None, d1=None, d2=None):
>     """
>     D4 Wavelet transform in NumPy
>     (C) Sturla Molden
>     """
>     C1 = 1.7320508075688772
>     C2 = 0.4330127018922193
>     C3 = -0.066987298107780702
>     C4 = 0.51763809020504137
>     C5 = 1.9318516525781364
>     if d1 == None:
>        d1 = numpy.zeros(x.size/2)
>        s1 = numpy.zeros(x.size/2)
>        d2 = numpy.zeros(x.size/2)
>     odd = x[1::2]
>     even = x[:-1:2]
>     d1[:] = odd[:] - C1*even[:]
>     s1[:-1] = even[:-1] + C2*d1[:-1] + C3*d1[1:]
>     s1[-1] = even[-1] + C2*d1[-1] + C3*d1[0]
>     d2[0] = d1[0] + s1[-1]
>     d2[1:] = d1[1:] + s1[:-1]
>     even[:] = C4 * s1[:]
>     odd[:] = C5 * d2[:]

If you swap C4 with C5 then our solutions give identical results and
both match the classic dwt approach:

    even[:] = C5 * s1[:]
    odd[:] = C4 * d2[:]

>     if x.size > 2:
>     D4_Transform(even,s1[0:even.size/2],
>             d1[0:even.size/2],d2[0:even.size/2])

cheers,
fw




More information about the Python-list mailing list