示例#1
0
def feature_plot(M,
                 normalize=False,
                 dbscale=False,
                 norm=False,
                 title_string=None,
                 interp='nearest',
                 bels=False,
                 nofig=False,
                 **kwargs):
    """
    ::

        static method for plotting a matrix as a time-frequency distribution (audio features)
    """
    X = feature_scale(M, normalize, dbscale, norm, bels)
    if not nofig: P.figure()
    clip = -100.
    if dbscale or bels:
        if bels: clip /= 10.
        P.imshow(P.clip(X, clip, 0),
                 origin='lower',
                 aspect='auto',
                 interpolation=interp,
                 **kwargs)
    else:
        P.imshow(X,
                 origin='lower',
                 aspect='auto',
                 interpolation=interp,
                 **kwargs)
    if title_string:
        P.title(title_string)
    P.colorbar()
示例#2
0
def scale_mtx(M, normalize=False, dbscale=False, norm=False, bels=False):
    """
    ::

        Perform mutually-orthogonal scaling operations, otherwise return identity:
          normalize [False]
          dbscale  [False]
          norm      [False]        
    """
    if not (normalize or dbscale or norm or bels):
        return M
    else:
        X = M.copy()  # don't alter the original
        if norm:
            nz_idx = (X * X).sum(1) > 0
            X[nz_idx] = (X[nz_idx].T / np.sqrt(
                (X[nz_idx] * X[nz_idx]).sum(1))).T
        if normalize:
            X = X - np.min(X)
            X = X / np.max(X)
        if dbscale or bels:
            X = P.log10(P.clip(X, 0.0001, X.max()))
            if dbscale:
                X = 20 * X
    return X
示例#3
0
 def log_p(self, theta, resp):
     strokes = self._strokes
     s = len(strokes)
     A = self._params[:(s - 1)]
     B = self._params[(s - 1):]
     make_tens = T.Tensor in map(type, [A, B, theta, resp])
     if make_tens:
         theta = to_tens(theta)
     d = {stroke: i for i, stroke in enumerate(strokes)}
     resp = P.clip(resp, strokes[0], strokes[-1])
     temp = P.vectorize(d.get)(resp)
     if make_tens:
         resp = to_tens(temp)
     else:
         resp = temp
     lo = [0.0 * theta] * s  # log odds vs par
     I = P.searchsorted(strokes, self._par)
     for i in range(I + 1, s):
         lo[i] = lo[i - 1] - A[i - 1] * (theta - B[i - 1])
     for i in range(I - 1, -1, -1):
         lo[i] = lo[i + 1] + A[i] * (theta - B[i])
     if make_tens:
         lo = T.stack(lo)
         lpp = lo - T.logsumexp(lo, dim=0, keepdim=True)
         lp = sum([lpp[i] * to_tens(resp == i) for i in range(s)])
     else:
         lo = P.stack(lo)
         lpp = lo - lse(lo, 0, keepdims=True)
         lp = sum([lpp[i] * (resp == i) for i in range(s)])
     return lp
示例#4
0
def plot_mtx(mtx=None, title=None, newfig=False, cbar=True, **kwargs):
    """
    ::

        static method for plotting a matrix as a time-frequency distribution (audio features)
    """
    if mtx is None or type(mtx) != np.ndarray:
        raise ValueError('First argument, mtx, must be a array')
    if newfig: P.figure()
    dbscale = kwargs.pop('dbscale', False)
    bels = kwargs.pop('bels', False)
    norm = kwargs.pop('norm', False)
    normalize = kwargs.pop('normalize', False)
    origin = kwargs.pop('origin', 'lower')
    aspect = kwargs.pop('aspect', 'auto')
    interpolation = kwargs.pop('interpolation', 'nearest')
    cmap = kwargs.pop('cmap', P.cm.gray_r)
    clip = -100.
    X = scale_mtx(mtx,
                  normalize=normalize,
                  dbscale=dbscale,
                  norm=norm,
                  bels=bels)
    i_min, i_max = np.where(X.mean(1))[0][[0, -1]]
    X = X[i_min:i_max + 1].copy()
    if dbscale or bels:
        if bels: clip /= 10.
        P.imshow(P.clip(X, clip, 0),
                 origin=origin,
                 aspect=aspect,
                 interpolation=interpolation,
                 cmap=cmap,
                 **kwargs)
    else:
        P.imshow(X,
                 origin=origin,
                 aspect=aspect,
                 interpolation=interpolation,
                 cmap=cmap,
                 **kwargs)
    if title:
        P.title(title, fontsize=16)
    if cbar:
        P.colorbar()
    P.yticks(np.arange(0, i_max + 1 - i_min, 3),
             pc_labels[i_min:i_max + 1:3],
             fontsize=14)
    P.xlabel('Tactus', fontsize=14)
    P.ylabel('MIDI Pitch', fontsize=14)
    P.grid()
示例#5
0
    def _mfcc(self):
        """
        ::

            DCT of the Log magnitude CQFT
        """
        fp = self._check_feature_params()
        if not self._cqft():
            return False
        self._make_dct()
        AA = P.log10(P.clip(self.CQFT, 0.0001, self.CQFT.max()))
        self.MFCC = P.dot(self.DCT, AA)
        self._have_mfcc = True
        if self.verbosity:
            print("Extracted MFCC: lcoef=%d, ncoef=%d, intensified=%d" %
                  (self.lcoef, self.ncoef, self.intensify))
        n = self.ncoef
        l = self.lcoef
        self.X = self.MFCC[l:l + n, :]
        return True
示例#6
0
def feature_scale(M, normalize=False, dbscale=False, norm=False, bels=False):
    """
    ::

        Perform mutually-orthogonal scaling operations, otherwise return identity:
          normalize [False]
          dbscale  [False]
          norm      [False]
    """
    if not (normalize or dbscale or norm or bels):
        return M
    else:
        X = M.copy()  # don't alter the original
        if norm:
            X = X / P.tile(P.sqrt((X * X).sum(0)), (X.shape[0], 1))
        if normalize:
            X = _normalize(X)
        if dbscale or bels:
            X = P.log10(P.clip(X, 0.0001, X.max()))
            if dbscale:
                X = 20 * X
    return X
    lines=file1.readlines()
    z=[]
    m=[]
    for i in range(0,180):
        linearray=lines[i].split(',')
        for j in range(126):
            for k in range(1):
                p=float(linearray[j])
                z.append(p)
        for k in range(1):
                p=float(linearray[126][1:7].rstrip('\n'))
                z.append(p)
    z=array(z).reshape(180,127)
    m=z.T
    print z.shape
##    print z
##    pylab.xticks(arange(20),'0','5','10','15','20')
##    pylab.xticks(arange(180),'7.30','8.00','8.30','9.00','9.30','10.00','11.30')
    pylab.subplot(111)
    pylab.ylabel('Cell Number')
    pylab.xlabel('Time')
##    pylab.xmajorLocator=fig.MultipleLocator(10)
##    pylab.ylim(0,100)
    pylab.title('2004.Nov.3(Wen.), 7:30-10:30')
    pylab.pcolor(m,vmin= 10,vmax= 110)
    b=pylab.colorbar(shrink=0.76)
    pylab.imshow(pylab.clip(m,10,110))
##    b.shrink(0.8)
    pylab.savefig('yokohane_a_11032t.png',dpi=150)
    print 'over'
示例#8
0
y1 = y1[y1_st:y1_end]
y2 = y2[y2_st:y2_end]
wp[:, 0] = wp[:, 0] - wp[0, 0]
wp[:, 1] = wp[:, 1] - wp[0, 1]
wp_s = P.asarray(wp) * hop_size / fs
i, I = P.argsort(wp_s[-1, :])
x, y = close_points(P.array(
    [wp_s[:, i] / wp_s[-1, i], wp_s[:, I] / wp_s[-1, I]]),
                    s=1)
f = mono_interp(x, y, extrapolate=True)
yc, yo = (y1, y2) if i == 1 else (y2, y1)
l_hop = 64
stft = librosa.stft(yc, n_fft=512, hop_length=l_hop)
z = len(yo) // l_hop + 1
t = P.arange(0, 1, 1 / z)
time_steps = P.clip(f(t) * stft.shape[1], 0, None)
print "Beginning vocoder warping..."
warped_stft = variable_phase_vocoder(stft, time_steps, hop_length=l_hop)
y_warp = librosa.istft(warped_stft, hop_length=l_hop)
# print "Writing warped signal to file..."
# librosa.output.write_wav("warped.wav", y_warp, fs, norm=True)
# P.plot(wp_s[:,1]/wp_s[-1,1], wp_s[:,0]/wp_s[-1,1], 'o')
# x, y = close_points(
#   P.array([wp_s[:,1]/wp_s[-1,1], wp_s[:,0]/wp_s[-1,1]]), s=1)
# f = mono_interp(x, y, extrapolate=True)
# t = P.linspace(0, 1, 500)
# P.plot(t, f(t))
# # f_smooth = US(wp_s[:,1]/wp_s[-1,1], wp_s[:,0]/wp_s[-1,1], s=.008)
# # P.plot(t, f_smooth(t))
# # P.plot(x, y, 'x')
# P.show()