Пример #1
0
def test_tgrid():
    nfft = 256
    shift = 10
    ntapers = 5
    D = libtfr.mfft_dpss(nfft, 3, ntapers, nfft)
    Z = D.mtstft(sig, shift)
    tgrid1 = libtfr.tgrid(sig.size, 1, shift)
    tgrid2 = libtfr.tgrid(Z, 1, shift)
Пример #2
0
def test_tgrid():
    nfft = 256
    shift = 10
    ntapers = 5
    D = libtfr.mfft_dpss(nfft, 3, ntapers, nfft)
    Z = D.mtstft(sig, shift)
    tgrid1 = libtfr.tgrid(sig.size, 1, shift)
    tgrid2 = libtfr.tgrid(Z, 1, shift)
Пример #3
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
Пример #4
0
def specgram(x, NFFT=256, shift=128, Fs=1.0, drange=60,
             ax=None, cmap=mplt.cm.gray_r, **kwargs):
    from numpy import hanning
    from libtfr import stft, fgrid, tgrid, dynamic_range
    w = hanning(NFFT)
    S = stft(x, w, shift)
    F,ind = fgrid(Fs,NFFT,(0,Fs/2))
    T = tgrid(x.size, Fs, shift)
    S = nx.log10(dynamic_range(S, drange))
    if ax is None: ax = mplt.gca()
    ax.imshow(S, extent = (T[0],T[-1],F[0]-0.01,F[-1]), cmap=cmap, **kwargs)
    return S
Пример #5
0
def specgram(x, NFFT=256, shift=128, Fs=1.0, drange=60,
             ax=None, cmap=mplt.cm.gray_r, **kwargs):
    from numpy import hanning
    from libtfr import stft, fgrid, tgrid, dynamic_range
    w = hanning(NFFT)
    S = stft(x, w, shift)
    F,ind = fgrid(Fs,NFFT,(0,Fs/2))
    T = tgrid(x.size, Fs, shift)
    S = nx.log10(dynamic_range(S, drange))
    if ax is None: ax = mplt.gca()
    ax.imshow(S, extent = (T[0],T[-1],F[0]-0.01,F[-1]), cmap=cmap, **kwargs)
    return S
Пример #6
0
def specgram(signal, sampling_rate, nfft=256, shift=128, compress=1):
    """
    Calculate a spectrogram of signal.

    Parameters:
    signal - the input signal (needs to be a 1D array)
    nfft   - the window size, in points
    shift  - how much to shift the window in each frame, in points
    sampling_rate - the number of samples per second in the signal
    compress - how much to compress the spectrogram. Effectively sets the floor of the
               spectrogram at log10(compress)

    Returns: the spectrogram, the frequency grid, and the time grid

    """
    from numpy import log10
    import libtfr
    # generate a transform object
    D = libtfr.mfft_dpss(nfft, 3, 5, nfft)
    # calculate the power spectrogram
    P = D.mtspec(signal, shift)
    freq, find = libtfr.fgrid(sampling_rate, nfft)
    bins = libtfr.tgrid(P, sampling_rate, shift)
    return (log10(P + compress) - log10(compress), freq, bins)