Пример #1
0
def draw_3D_scalogram(signal, name, draw_contours=False):
    # Perform a wavelet transform on the input signal.
    print "Transforming '%s' using a Morlet wavelet..." % name
    transformed = Morlet(
        signal,
        largestscale=4,
        notes=16,
        scaling='log')
    power_matrix = transformed.getpower()

    # Downsample the image.
    matrix_dimensions = numpy.shape(power_matrix)
    mat_size = (matrix_dimensions[0], 1000)
    power = scipy.misc.imresize(power_matrix, mat_size)

    # Display the power matrix generated during the wavelet transform.
    fig = pyplot.figure(name)
    pyplot.title(name)
    axis = fig.gca(projection='3d')

    # Setup each axis' data.
    f = numpy.arange(mat_size[0])
    t = numpy.arange(mat_size[1])
    f_major, t_major = numpy.meshgrid(f, t)

    # Plot everything.
    axis.plot_surface(t_major, f_major, power.transpose(), rstride=8, cstride=8, alpha=0.3)
    if draw_contours:
        axis.contour(t_major, f_major, power.transpose(), zdir='z', offset=0, cmap=cm.coolwarm)
        axis.contour(t_major, f_major, power.transpose(), zdir='x', offset=0, cmap=cm.coolwarm)
        axis.contour(t_major, f_major, power.transpose(), zdir='y', offset=0, cmap=cm.coolwarm)
    axis.set_xlabel('t')
    axis.set_ylabel('f')
    axis.set_zlabel('amplitude')
Пример #2
0
def draw_scalogram(signal, name):
    # Perform a wavelet transform on the input signal.
    print "Transforming '%s' using a Morlet wavelet..." % name
    transformed = Morlet(
        signal,
        largestscale=4,
        notes=16,
        scaling='log')
    power_matrix = transformed.getpower()

    # Display the power matrix generated during the wavelet transform.
    pylab.imshow(
        power_matrix,
        cmap=pylab.cm.jet,
        aspect='auto')