Ejemplo n.º 1
0
 def matched_spectrogram(self, signal, Fs):
     """
     Calculate a spectrogram of a signal using the same parameters
     as the template.  Returns spectrogram, time grid, and freq grid.
     """
     options = self.options
     spec = libtfr.tfr_spec(signal, options['nfft'], options['shift'], options['winsize'],
                            options['tfr_order'], options['tfr_tm'], options['tfr_flock'],
                            options['tfr_tlock'], fgrid=self.template.fgrid)
     return spec, libtfr.tgrid(spec, Fs, options['shift']), self.template.fgrid * Fs
Ejemplo n.º 2
0
def test_tfr():
    nfft = 256
    Np = 201
    shift = 10
    K = 6
    tm = 6.0
    flock = 0.01
    tlock = 5
    Z = libtfr.tfr_spec(sig, nfft, shift, Np, K, tm, flock, tlock)
    assert_tuple_equal(Z.shape, (nfft//2 + 1, (sig.size - Np + 1)// shift))
    assert_equal(Z.dtype, libtfr.DTYPE)
Ejemplo n.º 3
0
def test_tfr():
    nfft = 256
    Np = 201
    shift = 10
    K = 6
    tm = 6.0
    flock = 0.01
    tlock = 5
    Z = libtfr.tfr_spec(sig, nfft, shift, Np, K, tm, flock, tlock)
    assert_tuple_equal(Z.shape, (nfft // 2 + 1, (sig.size - Np) // shift + 1))
    assert_equal(Z.dtype, libtfr.DTYPE)
Ejemplo n.º 4
0
 def linspect(self, signal, Fs, nfft=None):
     """ Calculate the spectrogram on a linear power scale.  """
     import numpy as nx
     from libtfr import stft, tfr_spec, tgrid
     shift = int(self.options['window_shift'] * Fs)
     if not nfft:
         Np = int(Fs * self.options['window_len'])
         nfft = int(2 ** nx.ceil(nx.log2(Np)))
     else:
         Np = nfft
     if self.options['spec_method'] == 'tfr':
         S = tfr_spec(signal, nfft, shift, Np,
                      K=self.options['tfr_order'], tm=self.options['tfr_tm'],
                      flock=self.options['tfr_flock'], tlock=self.options['tfr_tlock'])
     else:
         try:
             wfun = getattr(nx, self.options['spec_method'])
             w = wfun(Np)
         except Exception, e:
             raise Error("invalid window function {}: {}".format(self.options['spec_method'], e))
         S = stft(signal, w, shift, nfft)
Ejemplo n.º 5
0
def mgram(signal):
	mt = tfr.tfr_spec(signal,NF,T_STEP,NF)
	mt[mt==0] = np.amin(mt[mt>0])
	return mt