File: 1dtransform.rst

package info (click to toggle)
python-dtcwt 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 8,404 kB
  • sloc: python: 6,253; sh: 29; makefile: 13
file content (52 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download | duplicates (3)
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
1D transform
------------

This example generates two 1D random walks and demonstrates reconstructing them
using the forward and inverse 1D transforms. Note that
:py:func`dtcwt.Transform1d.forward` and :py:func:`dtcwt.Transform1d.inverse`
will transform columns of an input array independently

.. plot::
    :include-source: true

    from matplotlib.pylab import *
    import dtcwt

    # Generate a 300x2 array of a random walk
    vecs = np.cumsum(np.random.rand(300,2) - 0.5, 0)

    # Show input
    figure()
    plot(vecs)
    title('Input')

    # 1D transform, 5 levels
    transform = dtcwt.Transform1d()
    vecs_t = transform.forward(vecs, nlevels=5)

    # Show level 2 highpass coefficient magnitudes
    figure()
    plot(np.abs(vecs_t.highpasses[1]))
    title('Level 2 wavelet coefficient magnitudes')

    # Show last level lowpass image
    figure()
    plot(vecs_t.lowpass)
    title('Lowpass signals')

    # Inverse
    vecs_recon = transform.inverse(vecs_t)

    # Show output
    figure()
    plot(vecs_recon)
    title('Output')

    # Show error
    figure()
    plot(vecs_recon - vecs)
    title('Reconstruction error')

    print('Maximum reconstruction error: {0}'.format(np.max(np.abs(vecs - vecs_recon))))