def Denoise(raw_sig, level = 7, low = 1, high = 1):
    '''Denoise with wavelet.'''
    # sig = raw_sig[:]
    len_sig = len(raw_sig)
    raw_sig = crop_data_for_swt(raw_sig)
    coeflist = pywt.swt(raw_sig, 'db2', level)
    cAlist, cDlist = zip(*coeflist)

    cAlist = list(cAlist)
    cDlist = list(cDlist)

    # denoise
    for ind in xrange(0, low):
        cAlist[ind] = np.zeros(len(cAlist[ind]))
    for ind in xrange(len(cDlist) - high, len(cDlist)):
        cDlist[ind] = np.zeros(len(cDlist[ind]))
    
    coeflist = zip(cAlist, cDlist)
    denoised_sig = pywt.iswt(coeflist, 'db2')
    
    # plt.figure(1)
    # plt.plot(denoised_sig)
    # plt.plot(sig, 'r')
    # plt.show()

    raw_sig = denoised_sig[:len_sig]
    return raw_sig
Ejemplo n.º 2
0
def denoiseBySWT(signal):
    level = 1
    wave = 'db6'
    mode = 'soft'
    sample = signal
    coef = pywt.swt(sample, wave, level=level)
    sigmaHat1 = np.median(np.abs(coef[0][1]) / 0.6745)
    #sigmaHat2 = np.median(np.abs(coef[1][1])/0.6745)
    #sigmaHat3 = np.median(np.abs(coef[2][1])/0.6745)

    cap1 = sigmaHat1 * np.sqrt(2 * np.log(len(coef[0][1])))
    #cap2 = sigmaHat2 * np.sqrt(2*np.log(len(coef[1][1])))
    #cap3 = sigmaHat3 * np.sqrt(2*np.log(len(coef[2][1])))

    coef[0] = list(coef[0])
    #coef[1] = list(coef[1])
    #coef[2] = list(coef[2])

    coef[0][1] = pywt.threshold(coef[0][1], cap1, mode=mode)
    #coef[1][1] = pywt.threshold(coef[1][1], cap2, mode=mode)
    #coef[2][1] = pywt.threshold(coef[2][1], cap3, mode=mode)

    coef[0] = tuple(coef[0])
    #coef[1] = tuple(coef[1])
    #coef[2] = tuple(coef[2])

    sampleRec = pywt.iswt(coef, wave)
    return sampleRec
Ejemplo n.º 3
0
 def iwave(cA, cD):
     iwave = list()
     for i in range(cA.shape[0]):
         # wave = pywt.idwt(cA[i,:],cD[i,:], 'db4')
         wave = pywt.iswt((cA[i, :], cD[i, :]), 'db4')
         iwave.append(wave)
     return np.array(iwave)
Ejemplo n.º 4
0
def test_iswt_mixed_dtypes():
    # Mixed precision inputs give double precision output
    x_real = np.arange(16).astype(np.float64)
    x_complex = x_real + 1j*x_real
    wav = 'sym2'
    for dtype1, dtype2 in [(np.float64, np.float32),
                           (np.float32, np.float64),
                           (np.float16, np.float64),
                           (np.complex128, np.complex64),
                           (np.complex64, np.complex128)]:

        if dtype1 in [np.complex64, np.complex128]:
            x = x_complex
            output_dtype = np.complex128
        else:
            x = x_real
            output_dtype = np.float64

        coeffs = pywt.swt(x, wav, 2)
        # different precision for the approximation coefficients
        coeffs[0] = [coeffs[0][0].astype(dtype1),
                     coeffs[0][1].astype(dtype2)]
        y = pywt.iswt(coeffs, wav)
        assert_equal(output_dtype, y.dtype)
        assert_allclose(y, x, rtol=1e-3, atol=1e-3)
Ejemplo n.º 5
0
def swt_process_uc_signal(sig,
                          exclude_detail_level=0,
                          exclude_before=2,
                          total_levels=11,
                          fs=1,
                          wavelet='db4',
                          should_clip=True):

    len_orig = len(sig)
    sig, n_pad_l, n_pad_r = swt_align(sig, total_levels)
    coeffs = pywt.swt(sig, wavelet, level=total_levels)
    coeffs = [[cA, cD] for cA, cD in coeffs]

    for j in range(exclude_before):
        coeffs[j][0] = coeffs[j][0] * 0
        coeffs[j][1] = coeffs[j][1] * 0

    for j in range(exclude_detail_level, len(coeffs)):
        coeffs[j][0] = coeffs[j][0] * 0
        coeffs[j][1] = coeffs[j][1] * 0

    sig_f = pywt.iswt(coeffs, wavelet)

    if n_pad_r > 0:
        sig_f = sig_f[n_pad_l:-n_pad_r]
    elif n_pad_l > 0:
        sig_f = sig_f[n_pad_l:]

    if should_clip:
        sig_f[sig_f < 0] = 0

    ts = np.arange(len(sig_f)) / fs
    return sig_f, ts
Ejemplo n.º 6
0
def test_iswt_mixed_dtypes():
    # Mixed precision inputs give double precision output
    x_real = np.arange(16).astype(np.float64)
    x_complex = x_real + 1j*x_real
    wav = 'sym2'
    for dtype1, dtype2 in [(np.float64, np.float32),
                           (np.float32, np.float64),
                           (np.float16, np.float64),
                           (np.complex128, np.complex64),
                           (np.complex64, np.complex128)]:

        if dtype1 in [np.complex64, np.complex128]:
            x = x_complex
            output_dtype = np.complex128
        else:
            x = x_real
            output_dtype = np.float64

        coeffs = pywt.swt(x, wav, 2)
        # different precision for the approximation coefficients
        coeffs[0] = [coeffs[0][0].astype(dtype1),
                     coeffs[0][1].astype(dtype2)]
        y = pywt.iswt(coeffs, wav)
        assert_equal(output_dtype, y.dtype)
        assert_allclose(y, x, rtol=1e-3, atol=1e-3)
Ejemplo n.º 7
0
def backward_UWT_pad(rec_d_f, rec_d, rec_a, axis=1):

    if axis:
        (m, t3, maxlev) = np.shape(rec_d)
        t = t3 / 3
        rec = np.zeros((m, t))
        rec_d[:, t:-t, :] = rec_d_f
        for l in range(m):
            coeffs = zip(rec_a[l, :, :].T, rec_d[l, :, :].T)
            rec[l, :] = pywt.iswt(coeffs, 'haar')[t:-t]
    else:
        t = np.shape(rec_d_f)[0]
        rec_d[t:-t, :] = rec_d_f
        coeffs = zip(rec_a.T, rec_d.T)
        rec = pywt.iswt(coeffs, 'haar')[t:-t]
    return (rec)
Ejemplo n.º 8
0
def swt_filtration(window, mod, wname='db6'):
    decomposition = pywt.swt(window, wname)
    for i in range(min(len(mod), len(decomposition))):
        if mod[i] == 0:
            decomposition[i][0].fill(0)
            decomposition[i][1].fill(0)
    return pywt.iswt(decomposition, wname)
Ejemplo n.º 9
0
def test_swt_iswt_integration():
    # This function performs a round-trip swt/iswt transform test on
    # all available types of wavelets in PyWavelets - except the
    # 'dmey' wavelet. The latter has been excluded because it does not
    # produce very precise results. This is likely due to the fact
    # that the 'dmey' wavelet is a discrete approximation of a
    # continuous wavelet. All wavelets are tested up to 3 levels. The
    # test validates neither swt or iswt as such, but it does ensure
    # that they are each other's inverse.

    max_level = 3
    wavelets = pywt.wavelist(kind='discrete')
    if 'dmey' in wavelets:
        # The 'dmey' wavelet seems to be a bit special - disregard it for now
        wavelets.remove('dmey')
    for current_wavelet_str in wavelets:
        current_wavelet = pywt.Wavelet(current_wavelet_str)
        input_length_power = int(np.ceil(np.log2(max(
            current_wavelet.dec_len,
            current_wavelet.rec_len))))
        input_length = 2**(input_length_power + max_level - 1)
        X = np.arange(input_length)
        coeffs = pywt.swt(X, current_wavelet, max_level)
        Y = pywt.iswt(coeffs, current_wavelet)
        assert_allclose(Y, X, rtol=1e-5, atol=1e-7)
Ejemplo n.º 10
0
def test_swt_iswt_integration():
    # This function performs a round-trip swt/iswt transform test on
    # all available types of wavelets in PyWavelets - except the
    # 'dmey' wavelet. The latter has been excluded because it does not
    # produce very precise results. This is likely due to the fact
    # that the 'dmey' wavelet is a discrete approximation of a
    # continuous wavelet. All wavelets are tested up to 3 levels. The
    # test validates neither swt or iswt as such, but it does ensure
    # that they are each other's inverse.

    max_level = 3
    wavelets = pywt.wavelist()
    if 'dmey' in wavelets:
        # The 'dmey' wavelet seems to be a bit special - disregard it for now
        wavelets.remove('dmey')
    for current_wavelet_str in wavelets:
        current_wavelet = pywt.Wavelet(current_wavelet_str)
        input_length_power = int(np.ceil(np.log2(max(
            current_wavelet.dec_len,
            current_wavelet.rec_len))))
        input_length = 2**(input_length_power + max_level - 1)
        X = np.arange(input_length)
        coeffs = pywt.swt(X, current_wavelet, max_level)
        Y = pywt.iswt(coeffs, current_wavelet)
        assert_allclose(Y, X, rtol=1e-5, atol=1e-7)
Ejemplo n.º 11
0
def inverse_stationary_wavelet(data: [float],
                               detail: [float] = [],
                               style: str = 'haar'):
    print('a', data)
    print('d', detail)
    if len(detail) == 0:
        detail = [0 for _ in data]
    return pywt.iswt(coeffs=list(zip(data, detail)), wavelet=style)
Ejemplo n.º 12
0
def inverse_WT(coeffs_list):
    """
    coeffs = [cA4,cD4,cD3....cD1]
    """
    wav = list()
    for i in range(coeffs_list[0].shape[0]):
        iwave = pywt.iswt([coeff[i, :] for coeff in coeffs_list], 'db4')
        wav.append(iwave)
    return np.array(wav)
Ejemplo n.º 13
0
def gen_surrogates(x,method="Wavelet"):
    if method=='Wavelet2' :
        z=pywt.swt(x,wavelet='haar')
        rand=coef_iaaft(z)
        series=pywt.iswt(rand,wavelet='haar')
        return series
    elif method== 'Wavelet':
        z=pywt.swt(x,wavelet='haar')
        rand=coef_aaft(z)
        series=pywt.iswt(rand,wavelet='haar')
        return series
    elif method=='FT':
        series=ft(x)
        return series
    elif method== 'AAFT':
        series=aaft(x)
        return series
    elif method == 'IAAFT':
        series=iaaft(x)
        return series
Ejemplo n.º 14
0
 def filter_noise(record):
     coeffs = pywt.swt(record.filtered_signal, 'db6', trim_approx=True)
     std = 1.483 * np.median(coeffs[-1])
     tsh = std * math.sqrt(2 * math.log(record.signal_len))
     for i, swt_coeff in enumerate(coeffs[1:], 1):
         coeffs[i] = [
             np.sign(CD) * (abs(CD) - tsh) if abs(CD) >= tsh else 0
             for CD in swt_coeff
         ]
     record.noisefiltered_signal = pywt.iswt(coeffs, wavelet='db6')
     record.filtered_signal = record.noisefiltered_signal[:]
Ejemplo n.º 15
0
def Denoise(raw_sig, level=7, low=1, high=1):
    '''Denoise with wavelet.'''
    def crop_data_for_swt(rawsig):
        '''Padding zeros to make the length of the signal to 2^N.'''
        import numpy as np
        if isinstance(rawsig, np.ndarray):
            rawsig = rawsig.tolist()
        # crop rawsig
        base2 = 1
        N_data = len(rawsig)
        if len(rawsig) <= 1:
            raise Exception('len(rawsig)={}, not enough for swt!', len(rawsig))
        crop_len = base2
        while base2 < N_data:
            if base2 * 2 >= N_data:
                crop_len = base2 * 2
                break
            base2 *= 2
        # Extending this signal input with its tail element.
        if N_data < crop_len:
            rawsig += [
                rawsig[-1],
            ] * (crop_len - N_data)
        return rawsig

    import pywt
    len_sig = len(raw_sig)
    raw_sig = crop_data_for_swt(raw_sig)
    coeflist = pywt.swt(raw_sig, 'db2', level)
    cAlist, cDlist = zip(*coeflist)

    cAlist = list(cAlist)
    cDlist = list(cDlist)

    # denoise
    for ind in xrange(0, low):
        cAlist[ind] = np.zeros(len(cAlist[ind]))
    for ind in xrange(len(cDlist) - high, len(cDlist)):
        cDlist[ind] = np.zeros(len(cDlist[ind]))

    coeflist = zip(cAlist, cDlist)
    denoised_sig = pywt.iswt(coeflist, 'db2')

    # plt.figure(1)
    # plt.plot(denoised_sig)
    # plt.plot(sig, 'r')
    # plt.show()

    raw_sig = denoised_sig[:len_sig]
    print len_sig
    return raw_sig
Ejemplo n.º 16
0
    def denoise(self):
        """denoise the data using the 2stage kurtosis denoising"""

        #make sure the data has a len dividible by 2^2
        self.len_swt = self.len
        while not (self.len_swt / 4).is_integer():
            self.len_swt -= 1

        inp = self.input_nobase[:self.len_swt]
        self.wave = pywt.Wavelet(self.wave_type)
        nLevel = pywt.swt_max_level(self.len_swt)
        self.coeffs = pywt.swt(inp, self.wave, level=2)

        print(" \t Denoise STW coefficients \t %1.2f %1.2f" %
              (self.TK, self.TT))
        (cA2, cD2), (cA1, cD1) = self.coeffs

        # rolling kurtosis
        k2 = self._rolling_kts(cD2, self.nwin)
        k1 = self._rolling_kts(cD1, self.nwin)

        # thresholding
        cD2[k2 < self.TK] = 0
        cD1[k1 < self.TK] = 0

        cA2[k2 < self.TK] = 0
        cA1[k1 < self.TK] = 0

        # universal threshold
        sigma_roll_1 = mad(cD1[cD1 != 0]) * np.ones(self.len_swt)
        uthresh_roll_1 = self.TT * sigma_roll_1 * np.sqrt(
            2 * np.log(self.len_swt))
        cD1[abs(cD1) < uthresh_roll_1] = 0

        # universal threshold
        sigma_roll_2 = mad(cD2[cD2 != 0]) * np.ones(self.len_swt)
        uthresh_roll_2 = self.TT * sigma_roll_2 * np.sqrt(
            2 * np.log(self.len_swt))
        cD2[abs(cD2) < uthresh_roll_2] = 0

        # final threshold
        cA1[cD1 == 0] = 0
        cA2[cD2 == 0] = 0
        self.denoised_coeffs = [(cA1, cD1), (cA2, cD2)]

        # denoise the data
        #self.input_denoised = self._iswt(self.denoised_coeffs,self.wave)
        self.input_denoised = pywt.iswt(self.denoised_coeffs, self.wave)
Ejemplo n.º 17
0
def test_swt_roundtrip_dtypes():
    # verify perfect reconstruction for all dtypes
    rstate = np.random.RandomState(5)
    wavelet = pywt.Wavelet('haar')
    for dt_in, dt_out in zip(dtypes_in, dtypes_out):
        # swt, iswt
        x = rstate.standard_normal((8, )).astype(dt_in)
        c = pywt.swt(x, wavelet, level=2)
        xr = pywt.iswt(c, wavelet)
        assert_allclose(x, xr, rtol=1e-6, atol=1e-7)

        # swt2, iswt2
        x = rstate.standard_normal((8, 8)).astype(dt_in)
        c = pywt.swt2(x, wavelet, level=2)
        xr = pywt.iswt2(c, wavelet)
        assert_allclose(x, xr, rtol=1e-6, atol=1e-7)
Ejemplo n.º 18
0
def test_swt_roundtrip_dtypes():
    # verify perfect reconstruction for all dtypes
    rstate = np.random.RandomState(5)
    wavelet = pywt.Wavelet('haar')
    for dt_in, dt_out in zip(dtypes_in, dtypes_out):
        # swt, iswt
        x = rstate.standard_normal((8, )).astype(dt_in)
        c = pywt.swt(x, wavelet, level=2)
        xr = pywt.iswt(c, wavelet)
        assert_allclose(x, xr, rtol=1e-6, atol=1e-7)

        # swt2, iswt2
        x = rstate.standard_normal((8, 8)).astype(dt_in)
        c = pywt.swt2(x, wavelet, level=2)
        xr = pywt.iswt2(c, wavelet)
        assert_allclose(x, xr, rtol=1e-6, atol=1e-7)
Ejemplo n.º 19
0
def swt_filter(coeffs, exclude_level=0, exclude_level_d=None, wavelet='db4'):

    if exclude_level_d is None:
        exclude_level_d = exclude_level

    coeffs = [[cA, cD] for cA, cD in coeffs]

    for j in range(exclude_level, len(coeffs)):
        coeffs[j][1] = coeffs[j][1] * 0

    for j in range(exclude_level_d, len(coeffs)):
        if j != 0:
            coeffs[j][0] = coeffs[j][0] * 0

    baseline = pywt.iswt(coeffs, wavelet)
    return baseline
    def master_algorithm(self):
        self.set_cwt_()
        self.set_dictionary()
        self.set_nMAX()
        self.S1 = self.nMAX[0]

        # Gather "master atoms" locations and fitted amplitudes.
        S1_atom_locs, S1_atom_amps = self.get_atoms(self.S1)
        self.set_J()

        # Collect detail bands for 1, ..., J
        detail_bands = self.get_detail_bands(S1_atom_locs)
        approximation = self.get_approximation(self.x, self.J)

        iswt_coeffs = self.get_iswt_coeffs(approximation, detail_bands)
        self.y = pywt.iswt(iswt_coeffs, self.swt_wavelet_type)

        # Remove padding.
        self.y = self.y[self.PAD_WIDTH:-(self.PAD_WIDTH +
                                         self.swt_buffer_length)]
Ejemplo n.º 21
0
def s_decomp(cA, wavelet, levels, omissions=([], False)): # stationary wavelet transform, AKA maximal overlap
    """
    1-dimensional stationary wavelet decompisition and reconstruction

    Parameters
    ----------
    ---Same as as decomp, not including mode---

    Returns
    -------
        1D array of reconstructed data.

    """

    if omissions[0] and max(omissions[0]) > levels:
        raise ValueError("Omission level %d is too high.  Maximum allowed is %d." % (max(omissions[0]), levels))
        
    coeffs = pywt.swt(cA, wavelet, level=levels, start_level=0)
    coeffs = omit(coeffs, omissions, stationary=True)
    
    return pywt.iswt(coeffs, wavelet)
Ejemplo n.º 22
0
def wavelet_filtering(data, wfun, max_level=8):
    #
    padsize = int((2**max_level) * np.ceil(data.shape[0] / (2**max_level)) -
                  data.shape[0])
    #
    data_padded = np.pad(data, (0, padsize),
                         'constant',
                         constant_values=(0, 0))
    #
    wave = pywt.swt(data_padded, wfun, level=max_level, start_level=0, axis=0)
    #
    wave_m = [[
        np.zeros((data_padded.shape[0], ), dtype=float) for j in range(2)
    ] for i in range(max_level)]  #list
    wave_m[-4][1] = wave[-4][1]
    wave_m[-5][1] = wave[-5][1]
    wave_m = [tuple(wave_m[i]) for i in range(max_level)]
    #
    data_const = pywt.iswt(wave_m, wfun)
    if padsize != 0:
        data_const = data_const[:-padsize]
    #
    return data_const
Ejemplo n.º 23
0
 def time_iswt(self, n, wavelet):
     pywt.iswt(self.coeffs, wavelet)
Ejemplo n.º 24
0

thresh = measure_threshold(output)


# Compute the threshold. Apply soft-thresholding
def apply_threshold(timefreq_coeffs, thresholds):
    for i, (cA, cD) in enumerate(timefreq_coeffs):
        cD = pywt.threshold(cD, thresholds[i], mode='hard')
        timefreq_coeffs[i] = cA, cD


apply_threshold(output, thresh)

# Revert back to the time-domain.
data0 = pywt.iswt(output, db1)

# Compute the Discrete-Time Short-Time Fourier Transform
# of the data. Equivalent to computing the DFT of every
# time delta of the audio file after applying a window
# function. Returns sample frequencies (f), list of sampled
# times (t), and the DTSTFT matrix.
f, t, Zxx = stft(data0, fs=rate, nfft=rate, noverlap=None)

# Compute the magnitude to turn each DFT bin into
# frequencies. Simplification by taking the largest
# frequency as *the* frequency.
magnitude = np.abs(Zxx)

frequencies = []
for dft_bin in magnitude.T:
Ejemplo n.º 25
0
 def swtrec(self, coffes, wtname='db4'):
     ndata = pywt.iswt(coffes, wtname)
     return ndata
Ejemplo n.º 26
0
from array import array

import pywt

# print(help(pywt.threshold))

coffes = pywt.swt([1, 2, 4, 5, 6, 8, 9, 4], 'db2', level=2, trim_approx=True)
print(coffes)
data = pywt.iswt(coffes, 'db2')
print(data)
coffes2 = pywt.wavedec([1, 2, 4, 5, 6, 8, 9, 4, 5, 7, 6, 8, 9, 10],
                       'db1',
                       level=2)
print(coffes2)
data2 = pywt.waverec(coffes2, 'db1')
print(data2)
# data3=pywt.waverec(coffes3,'db2')
# print(data3)
# coffes2 = pywt.wavedec([1,2,4,5,6,8,9,4,6],'db1', level=2)
# print(coffes2)
# coffes3 = pywt.wavedec([1,2,4,5,6,8,9,4,6],'db1', level=3)
# print(coffes3)
# w = pywt.Wavelet('db4')
# maxlev = pywt.dwt_max_level(16, w.dec_len)
# print(maxlev)
#
# coffes = pywt.wavedec([1,2,3,4,5],'db1',level=2)
# print(coffes)
# coffes2 = pywt.wavedec([1,2,3,4,5,6,7,8,9,10],'db1',level=3)
# print(coffes2)
# print(pywt.Wavelet('db1').dec_len)
Ejemplo n.º 27
0
def iswt_decom(data, wavefunc):

    lv = len(data) - 1
    if lv == 1:
        y = pywt.iswt([(data[0], data[1])], wavefunc)
        #[(cA1,cD1)] = pywt.swt(data,wavefunc,level=lv)
        return y

    elif lv == 2:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[-1])], wavefunc)

        return y2

    elif lv == 3:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)

        return y3

    elif lv == 4:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)

        return y4

    elif lv == 5:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y2, data[3])], wavefunc)
        y5 = pywt.iswt([(y2, data[3])], wavefunc)

        return y5

    elif lv == 6:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)

        return y6

    elif lv == 7:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)

        return y7

    elif lv == 8:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)

        return y8

    elif lv == 9:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)

        return y9

    elif lv == 10:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)

        return y10

    elif lv == 11:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)

        return y11

    elif lv == 12:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)

        return y12
    elif lv == 13:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)
        y13 = pywt.iswt([(y12, data[13])], wavefunc)

        return y13

    elif lv == 14:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)
        y13 = pywt.iswt([(y12, data[13])], wavefunc)
        y14 = pywt.iswt([(y13, data[14])], wavefunc)

        return y14

    elif lv == 15:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)
        y13 = pywt.iswt([(y12, data[13])], wavefunc)
        y14 = pywt.iswt([(y13, data[14])], wavefunc)
        y15 = pywt.iswt([(y14, data[15])], wavefunc)

        return y15

    elif lv == 16:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)
        y13 = pywt.iswt([(y12, data[13])], wavefunc)
        y14 = pywt.iswt([(y13, data[14])], wavefunc)
        y15 = pywt.iswt([(y14, data[15])], wavefunc)
        y16 = pywt.iswt([(y15, data[16])], wavefunc)

        return y16

    elif lv == 17:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)
        y13 = pywt.iswt([(y12, data[13])], wavefunc)
        y14 = pywt.iswt([(y13, data[14])], wavefunc)
        y15 = pywt.iswt([(y14, data[15])], wavefunc)
        y16 = pywt.iswt([(y15, data[16])], wavefunc)
        y17 = pywt.iswt([(y16, data[17])], wavefunc)

        return y17

    elif lv == 18:
        y1 = pywt.iswt([(data[0], data[1])], wavefunc)
        y2 = pywt.iswt([(y1, data[2])], wavefunc)
        y3 = pywt.iswt([(y2, data[3])], wavefunc)
        y4 = pywt.iswt([(y3, data[4])], wavefunc)
        y5 = pywt.iswt([(y4, data[5])], wavefunc)
        y6 = pywt.iswt([(y5, data[6])], wavefunc)
        y7 = pywt.iswt([(y6, data[7])], wavefunc)
        y8 = pywt.iswt([(y7, data[8])], wavefunc)
        y9 = pywt.iswt([(y8, data[9])], wavefunc)
        y10 = pywt.iswt([(y9, data[10])], wavefunc)
        y11 = pywt.iswt([(y10, data[11])], wavefunc)
        y12 = pywt.iswt([(y11, data[12])], wavefunc)
        y13 = pywt.iswt([(y12, data[13])], wavefunc)
        y14 = pywt.iswt([(y13, data[14])], wavefunc)
        y15 = pywt.iswt([(y14, data[15])], wavefunc)
        y16 = pywt.iswt([(y15, data[16])], wavefunc)
        y17 = pywt.iswt([(y16, data[17])], wavefunc)
        y18 = pywt.iswt([(y17, data[18])], wavefunc)

        return y18
Ejemplo n.º 28
0
def inv_swt(coeff):
    return pywt.iswt(coeff, wavelet=WAVELET_STYLE)