wavelet,
                        len(data),
                        rms_rec,
                    )
                    over += 1
                else:
                    ok += 1
            if not over:
                print "- RMSE for all %d cases was under %s" % (len(data_size),
                                                                epsilon)


if __name__ == '__main__':

    families = ('db', 'sym', 'coif', 'bior', 'rbio')
    wavelets = sum([pywt.wavelist(name) for name in families], [])
    # list of mode names in pywt and matalb
    modes = [('zpd', 'zpd'), ('cpd', 'sp0'), ('sym', 'sym'), ('ppd', 'ppd'),
             ('sp1', 'sp1'), ('per', 'per')]

    print "Testing perfect reconstruction".upper()
    for dtype, name, epsilon in [(float32, "float32", 1.0e-7),
                                 (float64, "float64", 0.5e-10)][::-1]:
        print "#" * 80 + "\nPrecision: %s, max RMSE: %s\n" % (
            name, epsilon) + "#" * 80 + "\n"
        test_perfect_reconstruction(families,
                                    wavelets,
                                    modes,
                                    epsilon=epsilon,
                                    dtype=dtype)
        print
示例#2
0
# Plot scaling and wavelet functions for db, sym, coif, bior and rbio families

from supreme.lib import pywt
import pylab
import itertools

iterations = 5

for family, (rows,cols) in [('db', (4,3)), ('sym', (4,3)), ('coif', (3, 2))]:

    f = pylab.figure()
    f.subplots_adjust(hspace=0.2, wspace=0.2, bottom=.02, left=.06, right=.97, top=.94)
    colors = itertools.cycle('bgrcmyk')
    
    wnames = pywt.wavelist(family)
    print wnames
    i = iter(wnames)
    for col in xrange(cols):
        for row in xrange(rows):
            try:
                wavelet = pywt.Wavelet(i.next())
            except StopIteration:
                break
            phi, psi, x = wavelet.wavefun(iterations)
    
            color = colors.next()
            ax = pylab.subplot(rows, 2*cols, 1 + 2*(col + row*cols))
            pylab.title(wavelet.name + " phi")
            pylab.plot(x, phi, color)
            pylab.xlim(min(x), max(x))
                rec = pywt.idwt(pa, pd, wavelet, pmode)

                if len(data) % 2:
                    rec = rec[:len(data)]

                rms_rec = rms(data, rec)
                if rms_rec > epsilon:
                    if not over:
                        print
                    print '[RMS_REC > EPSILON] for Mode: %s, Wavelet: %s, Length: %d, rms=%.3g' % (pmode, wavelet, len(data), rms_rec, )
                    over += 1
                else:
                    ok += 1
            if not over:
                print "- RMSE for all %d cases was under %s" % (len(data_size), epsilon)

if __name__ == '__main__':

    families = ('db', 'sym', 'coif', 'bior', 'rbio')
    wavelets = sum([pywt.wavelist(name) for name in families], [])
    # list of mode names in pywt and matalb
    modes = [('zpd', 'zpd'), ('cpd', 'sp0'), ('sym', 'sym'),
             ('ppd', 'ppd'), ('sp1', 'sp1'), ('per', 'per')]

    print "Testing perfect reconstruction".upper()
    for dtype, name, epsilon in [(float32, "float32", 1.0e-7), (float64, "float64", 0.5e-10)][::-1]:
        print "#"*80 + "\nPrecision: %s, max RMSE: %s\n" % (name, epsilon) + "#"*80 + "\n"
        test_perfect_reconstruction(families, wavelets, modes, epsilon=epsilon, dtype=dtype)
        print

示例#4
0
iterations = 5

for family, (rows, cols) in [('db', (4, 3)), ('sym', (4, 3)),
                             ('coif', (3, 2))]:

    f = pylab.figure()
    f.subplots_adjust(hspace=0.2,
                      wspace=0.2,
                      bottom=.02,
                      left=.06,
                      right=.97,
                      top=.94)
    colors = itertools.cycle('bgrcmyk')

    wnames = pywt.wavelist(family)
    print wnames
    i = iter(wnames)
    for col in xrange(cols):
        for row in xrange(rows):
            try:
                wavelet = pywt.Wavelet(i.next())
            except StopIteration:
                break
            phi, psi, x = wavelet.wavefun(iterations)

            color = colors.next()
            ax = pylab.subplot(rows, 2 * cols, 1 + 2 * (col + row * cols))
            pylab.title(wavelet.name + " phi")
            pylab.plot(x, phi, color)
            pylab.xlim(min(x), max(x))