예제 #1
0
 def thprocess(self, coeffs, ths=None, thf='soft', thp=None):
     ncoeffs = [coeffs[0]]
     for i in range(1, len(coeffs)):
         if not ths:
             th = ThSelect(coeffs[i]).DonohoThEx2(len(coeffs) - i)
         elif len(ths) == len(coeffs) - 1:
             th = ths[i - 1]
         else:
             raise ValueError(
                 'number of th in ths[] must match levels of coeffs')
         if thf == 'soft':
             ncf = ThFuction(coeffs[i]).thsoft(th)
         elif thf == 'hard':
             ncf = ThFuction(coeffs[i]).thhard(th)
         elif thf == 'thsemisf':
             ncf = ThFuction(coeffs[i]).thsemisf(th, thp)
         elif thf == 'thf1':
             ncf = ThFuction(coeffs[i]).thf1(th, thp)
         elif thf == 'thf2':
             ncf = ThFuction(coeffs[i]).thf2(th, thp)
         elif thf == 'thf3':
             ncf = ThFuction(coeffs[i]).thf1(th, thp)
         else:
             raise ValueError(
                 'thf must be "soft","hard","thsemisf","thf1","thf2","thf3"'
             )
         ncoeffs.append(np.asarray(ncf))
     return ncoeffs
예제 #2
0
def thprocess(coeffs, thf='soft'):
    ncoeffs = [coeffs[0]]
    for i in range(1, len(coeffs)):
        th = ThSelect(coeffs[i]).DonohoThEx()
        if thf == 'soft':
            ncf = ThFuction(coeffs[i]).thsoft(th)
        elif thf == 'hard':
            ncf = ThFuction(coeffs[i]).thhard(th)
        ncoeffs.append(np.asarray(ncf))
    return ncoeffs
 def spcoThf2(self):
     Ecors = self.nlEcors()
     ncoeffs = []
     for i in range(1, len(self.coeffs) - 1):
         W = self.coeffs[-i]
         nW = []
         ec = Ecors[i - 1]
         th = ThSelect(W).DonohoThEx()
         for k in range(len(W)):
             thn = abs(W[k]) / abs(ec[k]) * th
             if abs(W[k]) < thn:
                 w = 0
             else:
                 w = W[k]
             nW.append(w)
         ncoeffs.insert(0, np.asarray(nW))
     ncoeffs.insert(0, self.coeffs[1])
     ncoeffs.insert(0, self.coeffs[0])
     return ncoeffs
예제 #4
0
        nce2s = spta.spcoThf2()
        sf1pd = swt.swtrec(nce1s, wtname='sym6')
        sf2pd = swt.swtrec(nce2s, wtname='sym6')
        sf1pds.append(sf1pd)
        sf2pds.append(sf2pd)

    for od in ods:
        swt = SWTP(od)
        coeffs = swt.swtdec(wtname='sym6', delevel=4)
        spta2 = SpCoThALG(coeffs)
        sfp1ths = []
        sfp2ths = []
        P = spta2.spcoCors()
        for i in range(1, len(coeffs)-1):
            spta2.BTHassitIndex(i, pk=0.1, pa=4, mode='srmse')
            gpth = ThSelect(P[i-1]).DonohoThEx()
            sfp1th = ThSearchAlgorithm().FibonacciSearch(spta2.BTHspcothfwp1, [0, 1.5*gpth], 0.001)
            sfp2th = ThSearchAlgorithm().FibonacciSearch(spta2.BTHspcothfwp2, [0, 1.5*gpth], 0.001)
            sfp1ths.append(sfp1th)
            sfp2ths.append(sfp2th)
        npce1s = spta2.spcoThfwp1(sfp1ths, 0.05)
        npce2s = spta2.spcoThfwp2(sfp2ths, 4)
        sfp1pd = swt.swtrec(npce1s, wtname='sym6')
        sfp2pd = swt.swtrec(npce2s, wtname='sym6')
        sfp1pds.append(sfp1pd)
        sfp2pds.append(sfp2pd)

    sf1snrs = []
    sf2snrs = []
    sfwp1snrs = []
    sfwp2snrs = []
    ods = [od1, od2, od3]
    dnames = ['Sine', 'Pulse', 'Spike']
    gthss = []
    bsthss = []
    gthpds = []
    bsthpds = []
    dl = 4
    for od in ods:
        dwd = DWTP(od)
        coeffs = dwd.dwtdec(wtname='db4', delevel=dl)
        gths = []
        bsths = []
        for i in range(1, len(coeffs)):
            bthe = BestThEstimate(coeffs[i], thfunction='thf3', thp=2 + 2 * i)
            thsa = ThSearchAlgorithm()
            gth = ThSelect(coeffs[i]).DonohoThEx()
            bsth = thsa.FibonacciSearch(bthe.msesurefuction, [0, 1.5 * gth],
                                        0.001)
            gths.append(gth)
            bsths.append(bsth)
        gthss.append(gths)
        bsthss.append(bsths)

    for i in range(len(ods)):
        dwd = DWTP(ods[i])
        coeffs = dwd.dwtdec(wtname='db4', delevel=dl)
        gths = gthss[i]
        bsths = gthss[i]
        ncoeffs1 = dwd.thprocess2(coeffs,
                                  ths=gths,
                                  thf='thf3',
예제 #6
0
    for k in range(ln):
        od1 = od[k * 1024:k * 1024 + 1024]
        swt = SWTP(od1)
        dwt = DWTP(od1)
        coeffs = swt.swtdec(wtname='db2', delevel=dl)
        dcoeffs = dwt.dwtdec(wtname='db2', delevel=dl)
        n1coeffs = swt.thprocess(coeffs, thf='soft')
        n2coeffs = swt.thprocess(coeffs, thf='hard')
        spd1 = swt.swtrec(n1coeffs, wtname='db2')
        hpd1 = swt.swtrec(n2coeffs, wtname='db2')

        shes = NoiseDetection(od1, 'db2').Entropymethod1(4)
        gth2s = []
        gth3s = []
        for i in range(1, len(coeffs)):
            gth = ThSelect(coeffs[i]).DonohoThEx()
            gth3 = ThSelect(dcoeffs[i]).EntropyTh2()
            if shes[i - 1] > 1.5:
                shes[i - 1] = 1.5
            elif shes[i - 1] < 0.8:
                shes[i - 1] = 0.8
            else:
                pass
            gth2 = gth * shes[i - 1]
            gth2s.append(gth2)
            gth3s.append(gth3)
        ncoeffs3 = swt.thprocess2(coeffs,
                                  ths=gth2s,
                                  thf='thf3',
                                  thps=[2 + 2 * k for k in range(dl)])
        npd1 = swt.swtrec(ncoeffs3, wtname='db2')