示例#1
0
文件: cq.py 项目: toshiemon18/nsgt
    def __init__(self, scale, fs, Ls, real=True, matrixform=False, reducedform=0, multichannel=False, measurefft=False, multithreading=False, dtype=float):
        assert fs > 0
        assert Ls > 0
        assert 0 <= reducedform <= 2
        
        self.scale = scale
        self.fs = fs
        self.Ls = Ls
        self.real = real
        self.measurefft = measurefft
        self.multithreading = multithreading
        self.reducedform = reducedform
        
        self.frqs,self.q = scale()

        # calculate transform parameters
        self.g,rfbas,self.M = nsgfwin(self.frqs, self.q, self.fs, self.Ls, sliced=False, dtype=dtype)

        if real:
            assert 0 <= reducedform <= 2
            sl = slice(reducedform,len(self.g)//2+1-reducedform)
        else:
            sl = slice(0,None)

        # coefficients per slice
        self.ncoefs = max(int(ceil(float(len(gii))/mii))*mii for mii,gii in zip(self.M[sl],self.g[sl]))        

        if matrixform:
            if self.reducedform:
                rm = self.M[self.reducedform:len(self.M)//2+1-self.reducedform]
                self.M[:] = rm.max()
            else:
                self.M[:] = self.M.max()
    
        if multichannel:
            self.channelize = lambda s: s
            self.unchannelize = lambda s: s
        else:
            self.channelize = lambda s: (s,)
            self.unchannelize = lambda s: s[0]

        # calculate shifts
        self.wins,self.nn = calcwinrange(self.g, rfbas, self.Ls)
        # calculate dual windows
        self.gd = nsdual(self.g, self.wins, self.nn, self.M)
        
        self.fwd = lambda s: nsgtf(s, self.g, self.wins, self.nn, self.M, real=self.real, reducedform=self.reducedform, measurefft=self.measurefft, multithreading=self.multithreading)
        self.bwd = lambda c: nsigtf(c, self.gd, self.wins, self.nn, self.Ls, real=self.real, reducedform=self.reducedform, measurefft=self.measurefft, multithreading=self.multithreading)
示例#2
0
    def __init__(self,scale,sl_len,tr_area,fs,min_win=16,Qvar=1,real=False,recwnd=False,matrixform=False,reducedform=0,multichannel=False,measurefft=False):
        assert fs > 0
        assert sl_len > 0
        assert tr_area >= 0
        assert sl_len > tr_area*2
        assert min_win > 0
        assert 0 <= reducedform <= 2

        assert sl_len%2 == 0

        self.sl_len = sl_len
        self.tr_area = tr_area
        self.fs = fs
        self.real = real
        self.measurefft = measurefft
        self.userecwnd = recwnd
        self.reducedform = reducedform

        self.scale = scale
        self.frqs,self.q = self.scale()

        self.g,self.rfbas,self.M = nsgfwin(self.frqs,self.q,self.fs,self.sl_len,sliced=True,min_win=min_win,Qvar=Qvar)
        
#        print "rfbas",self.rfbas/float(self.sl_len)*self.fs
        
        if matrixform:
            if self.reducedform:
                rm = self.M[self.reducedform:len(self.M)//2+1-self.reducedform]
                self.M[:] = rm.max()
            else:
                self.M[:] = self.M.max()
                
        if multichannel:
            self.channelize = lambda seq: seq
            self.unchannelize = lambda seq: seq
        else:
            self.channelize = lambda seq: ((it,) for it in seq)
            self.unchannelize = lambda seq: (it[0] for it in seq)

        self.wins,self.nn = calcwinrange(self.g,self.rfbas,self.sl_len)
        
        self.gd = nsdual(self.g,self.wins,self.nn,self.M)
        
        self.fwd = lambda fc: nsgtf_sl(fc,self.g,self.wins,self.nn,self.M,real=self.real,reducedform=self.reducedform,measurefft=self.measurefft)
        self.bwd = lambda cc: nsigtf_sl(cc,self.gd,self.wins,self.nn,self.sl_len,real=self.real,reducedform=self.reducedform,measurefft=self.measurefft)
示例#3
0
    def __init__(self,scale,fs,Ls,real=True,measurefft=False,matrixform=False,reducedform=0,multichannel=False):
        assert fs > 0
        assert Ls > 0
        assert 0 <= reducedform <= 2
        
        self.scale = scale
        self.fs = fs
        self.Ls = Ls
        self.real = real
        self.measurefft = measurefft
        self.reducedform = reducedform
        
        self.frqs,self.q = scale()

        # calculate transform parameters
        self.g,rfbas,self.M = nsgfwin(self.frqs,self.q,self.fs,self.Ls,sliced=False)

        if matrixform:
            if self.reducedform:
                rm = self.M[self.reducedform:len(self.M)//2+1-self.reducedform]
                self.M[:] = rm.max()
            else:
                self.M[:] = self.M.max()
    
        if multichannel:
            self.channelize = lambda s: s
            self.unchannelize = lambda s: s
        else:
            self.channelize = lambda s: (s,)
            self.unchannelize = lambda s: s[0]
            
        # calculate shifts
        self.wins,self.nn = calcwinrange(self.g,rfbas,self.Ls)
        # calculate dual windows
        self.gd = nsdual(self.g,self.wins,self.nn,self.M)
        
        self.fwd = lambda s: nsgtf(s,self.g,self.wins,self.nn,self.M,real=self.real,reducedform=self.reducedform,measurefft=self.measurefft)
        self.bwd = lambda c: nsigtf(c,self.gd,self.wins,self.nn,self.Ls,real=self.real,reducedform=self.reducedform,measurefft=self.measurefft)
示例#4
0
    def __init__(self,
                 scale,
                 sl_len,
                 tr_area,
                 fs,
                 min_win=16,
                 Qvar=1,
                 real=False,
                 recwnd=False,
                 matrixform=False,
                 reducedform=0,
                 multichannel=False,
                 measurefft=False):
        assert fs > 0
        assert sl_len > 0
        assert tr_area >= 0
        assert sl_len > tr_area * 2
        assert min_win > 0
        assert 0 <= reducedform <= 2

        assert sl_len % 2 == 0

        self.sl_len = sl_len
        self.tr_area = tr_area
        self.fs = fs
        self.real = real
        self.measurefft = measurefft
        self.userecwnd = recwnd
        self.reducedform = reducedform

        self.scale = scale
        self.frqs, self.q = self.scale()

        self.g, self.rfbas, self.M = nsgfwin(self.frqs,
                                             self.q,
                                             self.fs,
                                             self.sl_len,
                                             sliced=True,
                                             min_win=min_win,
                                             Qvar=Qvar)

        #        print "rfbas",self.rfbas/float(self.sl_len)*self.fs

        if matrixform:
            if self.reducedform:
                rm = self.M[self.reducedform:len(self.M) // 2 + 1 -
                            self.reducedform]
                self.M[:] = rm.max()
            else:
                self.M[:] = self.M.max()

        if multichannel:
            self.channelize = lambda seq: seq
            self.unchannelize = lambda seq: seq
        else:
            self.channelize = lambda seq: ((it, ) for it in seq)
            self.unchannelize = lambda seq: (it[0] for it in seq)

        self.wins, self.nn = calcwinrange(self.g, self.rfbas, self.sl_len)

        self.gd = nsdual(self.g, self.wins, self.nn, self.M)

        self.fwd = lambda fc: nsgtf_sl(fc,
                                       self.g,
                                       self.wins,
                                       self.nn,
                                       self.M,
                                       real=self.real,
                                       reducedform=self.reducedform,
                                       measurefft=self.measurefft)
        self.bwd = lambda cc: nsigtf_sl(cc,
                                        self.gd,
                                        self.wins,
                                        self.nn,
                                        self.sl_len,
                                        real=self.real,
                                        reducedform=self.reducedform,
                                        measurefft=self.measurefft)
示例#5
0
文件: slicq.py 项目: toshiemon18/nsgt
    def __init__(self,
                 scale,
                 sl_len,
                 tr_area,
                 fs,
                 min_win=16,
                 Qvar=1,
                 real=False,
                 recwnd=False,
                 matrixform=False,
                 reducedform=0,
                 multichannel=False,
                 measurefft=False,
                 multithreading=False,
                 dtype=float):
        assert fs > 0
        assert sl_len > 0
        assert tr_area >= 0
        assert sl_len > tr_area * 2
        assert min_win > 0
        assert 0 <= reducedform <= 2

        assert sl_len % 4 == 0
        assert tr_area % 2 == 0

        self.sl_len = sl_len
        self.tr_area = tr_area
        self.fs = fs
        self.real = real
        self.measurefft = measurefft
        self.multithreading = multithreading
        self.userecwnd = recwnd
        self.reducedform = reducedform

        self.scale = scale
        self.frqs, self.q = self.scale()

        self.g, self.rfbas, self.M = nsgfwin(self.frqs,
                                             self.q,
                                             self.fs,
                                             self.sl_len,
                                             sliced=True,
                                             min_win=min_win,
                                             Qvar=Qvar,
                                             dtype=dtype)

        #        print "rfbas",self.rfbas/float(self.sl_len)*self.fs
        if real:
            assert 0 <= reducedform <= 2
            sl = slice(reducedform, len(self.g) // 2 + 1 - reducedform)
        else:
            sl = slice(0, None)

        # coefficients per slice
        self.ncoefs = max(
            int(ceil(float(len(gii)) / mii)) * mii
            for mii, gii in zip(self.M[sl], self.g[sl]))

        if matrixform:
            if self.reducedform:
                rm = self.M[self.reducedform:len(self.M) // 2 + 1 -
                            self.reducedform]
                self.M[:] = rm.max()
            else:
                self.M[:] = self.M.max()

        if multichannel:
            self.channelize = lambda seq: seq
            self.unchannelize = lambda seq: seq
        else:
            self.channelize = lambda seq: ((it, ) for it in seq)
            self.unchannelize = lambda seq: (it[0] for it in seq)

        self.wins, self.nn = calcwinrange(self.g, self.rfbas, self.sl_len)

        self.gd = nsdual(self.g, self.wins, self.nn, self.M)

        self.fwd = lambda fc: nsgtf_sl(fc,
                                       self.g,
                                       self.wins,
                                       self.nn,
                                       self.M,
                                       real=self.real,
                                       reducedform=self.reducedform,
                                       measurefft=self.measurefft,
                                       multithreading=self.multithreading)
        self.bwd = lambda cc: nsigtf_sl(cc,
                                        self.gd,
                                        self.wins,
                                        self.nn,
                                        self.sl_len,
                                        real=self.real,
                                        reducedform=self.reducedform,
                                        measurefft=self.measurefft,
                                        multithreading=self.multithreading)
示例#6
0
    def __init__(
        self,
        scale,
        sl_len,
        tr_area,
        fs,
        min_win=16,
        Qvar=1,
        real=False,
        recwnd=False,
        matrixform=False,
        reducedform=0,
        multichannel=False,
        measurefft=False,
        multithreading=False,
        dtype=float,
    ):
        assert fs > 0
        assert sl_len > 0
        assert tr_area >= 0
        assert sl_len > tr_area * 2
        assert min_win > 0
        assert 0 <= reducedform <= 2

        assert sl_len % 4 == 0
        assert tr_area % 2 == 0

        self.sl_len = sl_len
        self.tr_area = tr_area
        self.fs = fs
        self.real = real
        self.measurefft = measurefft
        self.multithreading = multithreading
        self.userecwnd = recwnd
        self.reducedform = reducedform

        self.scale = scale
        self.frqs, self.q = self.scale()

        self.g, self.rfbas, self.M = nsgfwin(
            self.frqs, self.q, self.fs, self.sl_len, sliced=True, min_win=min_win, Qvar=Qvar, dtype=dtype
        )

        #        print "rfbas",self.rfbas/float(self.sl_len)*self.fs
        if real:
            assert 0 <= reducedform <= 2
            sl = slice(reducedform, len(self.g) // 2 + 1 - reducedform)
        else:
            sl = slice(0, None)

        # coefficients per slice
        self.ncoefs = max(int(ceil(float(len(gii)) / mii)) * mii for mii, gii in zip(self.M[sl], self.g[sl]))

        if matrixform:
            if self.reducedform:
                rm = self.M[self.reducedform : len(self.M) // 2 + 1 - self.reducedform]
                self.M[:] = rm.max()
            else:
                self.M[:] = self.M.max()

        if multichannel:
            self.channelize = lambda seq: seq
            self.unchannelize = lambda seq: seq
        else:
            self.channelize = lambda seq: ((it,) for it in seq)
            self.unchannelize = lambda seq: (it[0] for it in seq)

        self.wins, self.nn = calcwinrange(self.g, self.rfbas, self.sl_len)

        self.gd = nsdual(self.g, self.wins, self.nn, self.M)

        self.fwd = lambda fc: nsgtf_sl(
            fc,
            self.g,
            self.wins,
            self.nn,
            self.M,
            real=self.real,
            reducedform=self.reducedform,
            measurefft=self.measurefft,
            multithreading=self.multithreading,
        )
        self.bwd = lambda cc: nsigtf_sl(
            cc,
            self.gd,
            self.wins,
            self.nn,
            self.sl_len,
            real=self.real,
            reducedform=self.reducedform,
            measurefft=self.measurefft,
            multithreading=self.multithreading,
        )