예제 #1
0
 def PCD(self,
         x,
         Hs,
         A,
         mud=math.inf,
         lambd=0.0,
         nu=math.inf,
         returnMu=False):
     B = Hs - A.dot(x)
     if mud == math.inf:
         try:
             mu = B.T.dot(B) / B.T.dot(A).dot(B)
         except:
             mu = .5
     else:
         mu = mud
     if nu == math.inf:
         u = Utiliters()
         nu = u.getPcdConst(A)
     temp = (x + B) - (nu * lambd)
     temp = np.where(temp < 0, 0, temp)
     d = temp - x
     x = x + (d.dot(mu))
     if returnMu:
         return x, mu
     return x
예제 #2
0
    def getRMSfloat(self, const, opt=None):
        if opt is None:
            opt = {}
        gerador = Signal()
        util = Utiliters()
        matrizes = Matrizes()
        iterations = const['iterations']
        occupancy = const['occupancy']
        pattern = const['pattern']
        signalT = const['signalT']
        signalN = const['signalN']
        metodo = const['metodo']
        if 'FDIP' in metodo:
            try:
                if 'order' in opt:
                    order = opt['order']
                else:
                    order = 26
                signalA = self.FDIP(order, const['signalNf'],
                                    const['signalTf'], signalN)
                result = {
                    'rms': gerador.rms(signalA - signalT),
                    'signal': signalA
                }
                return result
            except:
                return None

        if 'lambda' in opt:
            lamb = opt['lambda']
        else:
            lamb = 0
        if 'mi' in opt:
            mi = opt['mi']
        else:
            mi = math.inf
        if 'samples' in opt:
            samples = opt['samples']
        else:
            samples = 1820
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        bwindow = b + 6
        window = b + e
        halfA = e - int(math.ceil(e / 2))
        halfCd = int(math.ceil((bwindow - window) / 2))
        halfCe = int(bwindow - window - halfCd)
        if halfCd > 0:
            fillCd = np.zeros(halfCd)
        else:
            fillCd = np.arange(0)
        if halfCe > 0:
            fillCe = np.zeros(halfCe)
        else:
            fillCe = np.arange(0)
        if 'maxB' in opt:
            maxB = opt['maxB']
        else:
            maxB = None
        H, A, B = matrizes.generate(b, maxB)
        if 'DS' in metodo:
            AA = np.vstack((np.hstack(
                (A, np.negative(A))), np.hstack((np.negative(A), A))))
            uns = np.ones(b)

        if 'MF' in metodo:
            fillAd = np.zeros(halfA)
            fillAe = np.zeros(e - halfA)
            fill = [fillAd, fillAe, fillCd, fillCe]
            matrix = matrizes.matrix()
            h = matrix[0:7, 5]
            if 'threshold' in opt:
                threshold = opt['threshold']
            else:
                threshold = util.getBestThreshold(metodo, occupancy)
            signalA = self.MatchedFw(signalN, h, threshold, samples, b, e,
                                     fill)
            result = {'rms': gerador.rms(signalA - signalT), 'signal': signalA}
            return result

        if 'constPCD' in opt:
            constPCD = opt['constPCD']
        else:
            constPCD = util.getPcdConst(A)
        if 'nu' in opt:
            nu = opt['nu']
        else:
            nu = util.getNuConst(occupancy)
        signalA = np.zeros(window * samples)
        for ite in range(samples):
            step = (ite * window)
            paso = step + window
            if (e > 6):
                paso = paso - (e - 6)
            signalS = np.concatenate((fillCd, signalN[step:paso], fillCe))
            step += halfA
            paso = step + b
            if 'DS' in metodo:
                signalA[step:paso] = self.DantzigSelec(signalS, b, H, AA, uns)
                continue

            if 'LS-OMP' in metodo:
                if 'threshold' in opt:
                    threshold = opt['threshold']
                else:
                    threshold = util.getBestThreshold(metodo, occupancy)
                signalA[step:paso] = self.LS_OMP(threshold, signalS, b, H)
                continue

            if 'OMP' in metodo:
                if 'threshold' in opt:
                    threshold = opt['threshold']
                else:
                    threshold = util.getBestThreshold(metodo, occupancy)
                signalA[step:paso] = self.OMP(threshold, signalS, b, H)
                continue

            if 'MP' in metodo:
                if 'threshold' in opt:
                    threshold = opt['threshold']
                else:
                    threshold = util.getBestThreshold(metodo, occupancy)
                signalA[step:paso] = self.MP(threshold, signalS, b, H)
                continue

            Hs = H.T.dot(signalS)

            if 'i' in metodo:
                x = B.dot(signalS)
            else:
                x = signalS[3:b + 3]
            for i in range(iterations):
                if 'GDP' in metodo:
                    x = self.GDP(x, Hs, A, mi)
                elif 'GD' in metodo:
                    x = self.GD(x, Hs, A, mi)
                elif 'SSFlsc' in metodo:
                    x = self.SSFlsc(x, Hs, A, mi, lamb, nu)
                elif 'SSFls' in metodo:
                    x = self.SSFls(x, Hs, A, mi, lamb, constPCD)
                elif 'SSF' in metodo:
                    x = self.SSF(x, Hs, A, mi, lamb)
                elif 'PCD' in metodo:
                    x = self.PCD(x, Hs, A, mi, lamb, constPCD)
            x = np.where(x < 0, 0, x)
            signalA[step:paso] = x
        result = {
            'rms': '%.6g' % gerador.rms(signalA - signalT),
            'signal': signalA
        }
        return result
예제 #3
0
    halfCe = int(bwindow - window - halfCd)
    fillAd = np.zeros(halfA)
    fillAe = np.zeros(e - halfA)
    if halfCd > 0:
        fillCd = np.zeros(halfCd)
    else:
        fillCd = np.arange(0)
    if halfCe > 0:
        fillCe = np.zeros(halfCe)
    else:
        fillCe = np.arange(0)
    fill = [fillAd, fillAe, fillCd, fillCe]
    H, A, B = matrizes.generate(b)
    matrix = matrizes.matrix()
    h = matrix[0:7, 5]
    constPCD = util.getPcdConst(A)
    constTAS = util.getTasConst(30)
    iterations = 108
    threshold = 0

    path = '../tests/signals/'

    bunch = pattern.rsplit('b', 1)
    empty = bunch[1].rsplit('e', 1)
    b = int(bunch[0])
    e = int(empty[0])
    bwindow = b + 6
    window = b + e
    halfA = e - int(math.ceil(e / 2))
    halfCd = int(math.ceil((bwindow - window) / 2))
    halfCe = int(bwindow - window - halfCd)
예제 #4
0
    def getRMSfix(self, const, opt):
        if opt is None:
            opt = {}
        gerador = Signal()
        matrizes = Matrizes()
        util = Utiliters()
        iterations = const['iterations']
        occupancy = const['occupancy']
        pattern = const['pattern']
        signalT = const['signalT']
        signalN = const['signalN']
        metodo = const['metodo']
        if 'lambda' in opt:
            lamb = opt['lambda']
        else:
            lamb = 0
        if 'mi' in opt:
            mi = opt['mi']
        else:
            mi = math.inf
        if 'samples' in opt:
            samples = opt['samples']
        else:
            samples = 1820
        if 'gain' in opt:
            gain = opt['gain']
        else:
            gain = 0
        if 'bitsH' in opt:
            bitsH = opt['bitsH']
        else:
            bitsH = 5
        if 'bitsB' in opt:
            bitsB = opt['bitsB']
        else:
            bitsB = None
        bits = gain + 10
        bitsA = bitsH + 5
        align = bitsA
        bunch = pattern.rsplit('b', 1)
        empty = bunch[1].rsplit('e', 1)
        b = int(bunch[0])
        e = int(empty[0])
        bwindow = b + 6
        window = b + e
        halfA = e - int(math.ceil(e / 2))
        halfCd = int(math.ceil((bwindow - window) / 2))
        halfCe = int(bwindow - window - halfCd)
        if halfCd > 0:
            fillCd = np.zeros(halfCd)
        else:
            fillCd = np.arange(0)
        if halfCe > 0:
            fillCe = np.zeros(halfCe)
        else:
            fillCe = np.arange(0)
        mh, ma, mb = matrizes.generateFix(bitsH, bitsA, bitsB)
        H, A, B = matrizes.generate(b)
        if 'constPCD' in opt:
            constPCDv = opt['constPCD']
        else:
            constPCD = util.getPcdConst(A)
            constPCDv = int(np.round(constPCD * math.pow(2, gain)))
        if 'nu' in opt:
            nuV = opt['nu']
        else:
            nu = util.getNuConst(occupancy)
            nuV = int(np.round(nu * math.pow(2, gain)))
        signalA = np.zeros(window * samples)
        for ite in range(samples):
            step = (ite * window)
            paso = step + window
            if (e > 6):
                paso = paso - (e - 6)
            signalS = np.concatenate((fillCd, signalN[step:paso], fillCe))
            step += halfA
            paso = step + b

            Hs, x = self.sipo(signalS, gain, mh, mb, bitsB)
            if 'GDP' in metodo:
                x = self.GDP([x, Hs, ma, iterations, bits, align, mi])
            elif 'GD' in metodo:
                x = self.GD([x, Hs, ma, iterations, bits, align, mi])
            elif 'SSFlsc' in metodo:
                x = self.TAS([x, Hs, ma, iterations, bits, align, mi, lamb, gain, nuV])
            elif 'SSFls' in metodo:
                x = self.TAS([x, Hs, ma, iterations, bits, align, mi, lamb, gain, nuV])
            elif 'SSF' in metodo:
                x = self.SSF([x, Hs, ma, iterations, bits, align, mi, lamb])
            elif 'PCD' in metodo:
                x = self.PCD([x, Hs, ma, iterations, bits, align, mi, lamb, gain, constPCDv])
            x = np.where(x < 0, 0, x)
            signalA[step:paso] = np.fix(np.divide(x, pow(2, gain)))
        result = {'rms': '%.6g' % gerador.rms(signalA - signalT), 'signal': signalA}
        return result