Example #1
0
def idwt1(cA, cD, wname):
    [lpd1, hpd1, lpr1, hpr1] = filter.filtcoef(wname)

    len_lpfilt = int(len(lpr1))
    len_hpfilt = int(len(hpr1))
    len_avg = int(len_lpfilt / 2 + len_hpfilt / 2)
    N = 2 * len(cD)
    U = 2

    cA_up = sample.upsamp(cA, U)
    cA_up = misc.per_ext(cA_up, int(len_avg / 2))
    X_lp = np.real(convol.convfft(cA_up, lpr1))

    cD_up = sample.upsamp(cD, U)
    cD_up = misc.per_ext(cD_up, int(len_avg / 2))
    X_hp = np.real(convol.convfft(cD_up, hpr1))

    X_lp = X_lp[0 : N + len_avg - 1]
    X_lp = X_lp[len_avg - 1 :]

    X_hp = X_hp[0 : N + len_avg - 1]
    X_hp = X_hp[len_avg - 1 :]

    X = X_lp + X_hp
    return X
Example #2
0
def idwt1(cA,cD,wname):
    [lpd1,hpd1,lpr1,hpr1]=filter.filtcoef(wname)

    len_lpfilt=int(len(lpr1))
    len_hpfilt=int(len(hpr1))
    len_avg=int(len_lpfilt/2 + len_hpfilt/2)
    N= 2 * len(cD)
    U=2

    cA_up=sample.upsamp(cA,U)
    cA_up=misc.per_ext(cA_up,int(len_avg/2))
    X_lp=np.real(convol.convfft(cA_up,lpr1))

    cD_up=sample.upsamp(cD,U)
    cD_up=misc.per_ext(cD_up,int(len_avg/2))
    X_hp=np.real(convol.convfft(cD_up,hpr1))
    
    X_lp=X_lp[0:N+len_avg-1]
    X_lp=X_lp[len_avg-1:]

    X_hp=X_hp[0:N+len_avg-1]
    X_hp=X_hp[len_avg-1:]
    
    X=X_lp+X_hp
    return X
Example #3
0
def dwt1(signal,wname):
    [lpd,hpd,lpr,hpr]=filter.filtcoef(wname)
    len_lpfilt=int(len(lpd))
    len_hpfilt=int(len(hpd))
    len_avg=int(len_lpfilt/2 + len_hpfilt/2)
    len_sig = int( 2 *(np.ceil(len(signal) * 1.0/2.0)))
    D=int(2)

    signal=misc.per_ext(signal,int(len_avg/2))
   

    cA_undec=np.real(convol.convfft(signal,lpd))
    cA_undec=cA_undec[len_avg-1:]
    cA_undec=cA_undec[:len(cA_undec)-len_avg+1]
    cA_undec=cA_undec[1:len_sig]
    cA=sample.downsamp(cA_undec,D)


    cD_undec=np.real(convol.convfft(signal,hpd))
    cD_undec=cD_undec[len_avg-1:]
    cD_undec=cD_undec[:len(cD_undec)-len_avg+1]
    cD_undec=cD_undec[1:len_sig]
    cD=sample.downsamp(cD_undec,D)

    return cA,cD
Example #4
0
def swt(sig, J, nm):
    swtop = np.array([])
    N = int(len(sig))
    length = N

    [lpd, hpd, lpr, hpr] = filter.filtcoef(nm)

    for iter in range(J):
        if iter > 0:
            M = int(2 ** iter)
            low_pass = sample.upsamp(lpd, M)
            high_pass = sample.upsamp(hpd, M)
        else:
            low_pass = lpd
            high_pass = hpd

        len_filt = int(len(low_pass))
        sig = misc.per_ext(sig, int(len_filt / 2))
        cA = np.real(convol.convfft(sig, low_pass))
        cD = np.real(convol.convfft(sig, high_pass))

        cA = cA[len_filt:]
        cA = cA[0:N]

        cD = cD[len_filt:]
        cD = cD[0:N]

        sig = cA
        if iter == J - 1:
            swtop = np.append(cD, swtop)
            swtop = np.append(cA, swtop)
        else:
            swtop = np.append(cD, swtop)

    return swtop, length
Example #5
0
def dwt1(signal, wname):
    [lpd, hpd, lpr, hpr] = filter.filtcoef(wname)
    len_lpfilt = int(len(lpd))
    len_hpfilt = int(len(hpd))
    len_avg = int(len_lpfilt / 2 + len_hpfilt / 2)
    len_sig = int(2 * (np.ceil(len(signal) * 1.0 / 2.0)))
    D = int(2)

    signal = misc.per_ext(signal, int(len_avg / 2))

    cA_undec = np.real(convol.convfft(signal, lpd))
    cA_undec = cA_undec[len_avg - 1 :]
    cA_undec = cA_undec[: len(cA_undec) - len_avg + 1]
    cA_undec = cA_undec[1:len_sig]
    cA = sample.downsamp(cA_undec, D)

    cD_undec = np.real(convol.convfft(signal, hpd))
    cD_undec = cD_undec[len_avg - 1 :]
    cD_undec = cD_undec[: len(cD_undec) - len_avg + 1]
    cD_undec = cD_undec[1:len_sig]
    cD = sample.downsamp(cD_undec, D)

    return cA, cD
Example #6
0
def swt(sig,J,nm):
    swtop=np.array([])
    N=int(len(sig))
    length=N
    
    [lpd,hpd,lpr,hpr]=filter.filtcoef(nm)
    
    for iter in range(J):
        if iter > 0:
            M=int(2**iter)
            low_pass=sample.upsamp(lpd,M)
            high_pass=sample.upsamp(hpd,M)
        else:
            low_pass=lpd
            high_pass=hpd
            
        len_filt=int(len(low_pass))    
        sig=misc.per_ext(sig,int(len_filt/2))
        cA=np.real(convol.convfft(sig,low_pass))
        cD=np.real(convol.convfft(sig,high_pass))
        
        cA=cA[len_filt:]
        cA=cA[0:N]
        
        cD=cD[len_filt:]
        cD=cD[0:N]
        
        sig=cA
        if iter==J-1:
            swtop=np.append(cD,swtop)
            swtop=np.append(cA,swtop)
        else:
            swtop=np.append(cD,swtop)
        
    
    return swtop,length
Example #7
0
def iswt(swtop,J,nm):
    N=int(len(swtop)/(J+1))
    [lpd,hpd,lpr,hpr]=filter.filtcoef(nm)
    low_pass=lpr
    high_pass=hpr
    lf=int(len(low_pass))
    
    for iter in range(J):
        iswt_output=np.zeros(N)
        
        if iter==0:
            appx_sig=swtop[0:N]
            det_sig=swtop[N:2*N]
        else:
            det_sig=swtop[(iter+1)*N:(iter+2)*N]
        
        value=int(2**(J-1-iter))
        for count in range(value):
            appx1=appx_sig[count:N:value]
            det1=det_sig[count:N:value]
            
            len1=len(appx1)
            
            appx2=appx1[0:len1:2]
            det2=det1[0:len1:2]
            
            U=int(2)
            
            cL0=sample.upsamp(appx2,U)
            cH0=sample.upsamp(det2,U)
            
            cL0=misc.per_ext(cL0,int(lf/2))
            cH0=misc.per_ext(cH0,int(lf/2))
            
            oup00L=np.real(convol.convfft(cL0,low_pass))
            oup00H=np.real(convol.convfft(cH0,high_pass))
            
            oup00L=oup00L[lf-1:]
            oup00L=oup00L[0:len1]
            
            oup00H=oup00H[lf-1:]
            oup00H=oup00H[0:len1]
            
            oup00=oup00L+oup00H
            
            appx3=appx1[1:len1:2]
            det3=det1[1:len1:2]
            
            cL1=sample.upsamp(appx3,U)
            cH1=sample.upsamp(det3,U)
            
            cL1=misc.per_ext(cL1,int(lf/2))
            cH1=misc.per_ext(cH1,int(lf/2))
            
            oup01L=np.real(convol.convfft(cL1,low_pass))
            oup01H=np.real(convol.convfft(cH1,high_pass))
            
            oup01L=oup01L[lf-1:]
            oup01L=oup01L[0:len1]
            
            oup01H=oup01H[lf-1:]
            oup01H=oup01H[0:len1]
            
            oup01=oup01L+oup01H
            
            oup01=misc.circshift(oup01,-1)
            index2=int(0)
            for index in xrange(count,N,value):
                temp=(oup00[index2]+oup01[index2])*1.0/2.0
                iswt_output[index]=temp
                index2+=1
            
        appx_sig=iswt_output
    
    return iswt_output
Example #8
0
def iswt(swtop, J, nm):
    N = int(len(swtop) / (J + 1))
    [lpd, hpd, lpr, hpr] = filter.filtcoef(nm)
    low_pass = lpr
    high_pass = hpr
    lf = int(len(low_pass))

    for iter in range(J):
        iswt_output = np.zeros(N)

        if iter == 0:
            appx_sig = swtop[0:N]
            det_sig = swtop[N : 2 * N]
        else:
            det_sig = swtop[(iter + 1) * N : (iter + 2) * N]

        value = int(2 ** (J - 1 - iter))
        for count in range(value):
            appx1 = appx_sig[count:N:value]
            det1 = det_sig[count:N:value]

            len1 = len(appx1)

            appx2 = appx1[0:len1:2]
            det2 = det1[0:len1:2]

            U = int(2)

            cL0 = sample.upsamp(appx2, U)
            cH0 = sample.upsamp(det2, U)

            cL0 = misc.per_ext(cL0, int(lf / 2))
            cH0 = misc.per_ext(cH0, int(lf / 2))

            oup00L = np.real(convol.convfft(cL0, low_pass))
            oup00H = np.real(convol.convfft(cH0, high_pass))

            oup00L = oup00L[lf - 1 :]
            oup00L = oup00L[0:len1]

            oup00H = oup00H[lf - 1 :]
            oup00H = oup00H[0:len1]

            oup00 = oup00L + oup00H

            appx3 = appx1[1:len1:2]
            det3 = det1[1:len1:2]

            cL1 = sample.upsamp(appx3, U)
            cH1 = sample.upsamp(det3, U)

            cL1 = misc.per_ext(cL1, int(lf / 2))
            cH1 = misc.per_ext(cH1, int(lf / 2))

            oup01L = np.real(convol.convfft(cL1, low_pass))
            oup01H = np.real(convol.convfft(cH1, high_pass))

            oup01L = oup01L[lf - 1 :]
            oup01L = oup01L[0:len1]

            oup01H = oup01H[lf - 1 :]
            oup01H = oup01H[0:len1]

            oup01 = oup01L + oup01H

            oup01 = misc.circshift(oup01, -1)
            index2 = int(0)
            for index in xrange(count, N, value):
                temp = (oup00[index2] + oup01[index2]) * 1.0 / 2.0
                iswt_output[index] = temp
                index2 += 1

        appx_sig = iswt_output

    return iswt_output