File: test_wavelet.pro

package info (click to toggle)
gnudatalanguage 1.1.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 80,368 kB
  • sloc: cpp: 189,797; ansic: 46,721; sh: 677; python: 474; makefile: 146; xml: 69; f90: 28
file content (67 lines) | stat: -rw-r--r-- 2,133 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
; by Sylwester Arabas <slayoo@igf.fuw.edu.pl>
pro test_wavelet, plot=plot

  p = keyword_set(plot)

  n = 16     ; signal length / number of wavelets (1D case)
  nn = 8     ; dimension length (2D case)
  eps = 1e-6 ; a small number
  maxc = 20  ; GSL max: 20

  for kw_column = 0, 1 do for kw_double = 0, 1 do for kw_over = 0, 1 do $
  for dim = 1, 2 do begin

    if p then begin
      if dim eq 1 then !P.MULTI = [0, 4, n / 4] $
      else !P.MULTI = [0, nn, nn]
    endif

    for c = 4, maxc, 2 do begin
      for i = 0, (dim eq 1 ? n : nn * nn) - 1 do begin

        ; inverse-transforming a unit vector
        x1 = dim eq 1 ? fltarr(n) : fltarr(nn, nn) & x1[i] = 1
        v1 = x1
        v1 = wtn(v1, c, /inverse, double=kw_double, column=kw_column, over=kw_over)
  
        ; plotting if desired
        if p then begin
          if dim eq 1 then plot, v1 else surface, v1
        endif

        ; testing if the transform of the inverse transform equals the unit vector
        wh = where(abs(x1 - wtn(v1, c, double=kw_double, column=kw_column)) gt eps, cnt)
        if cnt gt 0 then begin
          message, 'wtn(wtn(a, /inv)) != a', /conti
          exit, status=1 
        endif

        ; testing if every wavelet (not the mother) has a zero mean
        if i gt 0 and abs(mean(v1)) gt eps then begin
          message, 'abs(mean(v1)) > eps', /conti
          exit, status=1
        endif

        ; testing if every other member of the basis is orthogonal to this one
        for j = 0, (dim eq 1 ? n : nn * nn) - 1 do begin
          x2 = dim eq 1 ? fltarr(n) : fltarr(nn, nn) & x2[j] = 1
          v2 = x2
          v2 = wtn(v2, c, /inverse, double=kw_double, column=kw_column, over=kw_over)
          v1v2 = total(v1 * v2)
          if i eq j and v1v2 lt 1 - eps then begin
            message, 'i eq j and v1v2 < 1 - eps !!!', /conti
            exit, status=1 
          endif
          if i ne j and v1v2 gt 0 + eps then begin
            message, 'i ne j and v1v2 > 0 + eps !!!', /conti
            exit, status=1
          endif
        endfor ; j

      endfor ; i 

    endfor ; c

  endfor ; dim

end ; pro