Пример #1
0
path = sys.path[0] + '/'
fileNameOnly = generalUtility.getFileNameOnly(fName)

# calculate the Intensity data using Praat
dataT, dataI = praatUtil.calculateIntensity(path + fName)

# normalize the dB data, since it's not calibrated
dataI -= dataI.max()

# generate the graph
graph = matplotlibUtil.CGraph(width = 8, height = 3)
graph.createFigure()
ax = graph.getArrAx()[0]
ax.plot(dataT, dataI, linewidth = 2)
ax.set_xlabel("Time [s]")
ax.set_ylabel("SPL [dB]")
ax.set_title(fileNameOnly)
graph.padding = 0.1
graph.adjustPadding(bottom = 2, right = 0.5)
ax.grid()

# It is not aesthetically pleasing when graph data goes to all the way to the 
# upper and lower edges of the graph. I prefer to have a little space.
matplotlibUtil.setLimit(ax, dataI, 'y', rangeMultiplier = 0.1)

# every doubling of sound pressure level (SPL) results in an increase of SPL by
# 6 dB. Therefore, we need to change the y-axis ticks
matplotlibUtil.formatAxisTicks(ax, 'y', 6, '%d')

# finally, save the graph to a file
plt.savefig(fileNameOnly + "_intensity.png")
Пример #2
0
n = int(round(duration * float(fs)))
arrData = numpy.zeros(n)
arrT = numpy.zeros(n)
for i in range(n):
    A = 1.0 - float(i) / n # amplitude [0..1] - create a decaying sinusoid
    t = float(i) / float(fs)
    arrT[i] = t
    arrData[i] = A * numpy.sin(numpy.pi * 2.0 * t * float(f0))
    
# plot the data in the top panel
ax = arrAx[0]
ax.plot(arrT, arrData, linewidth = graph.lineWidth)
ax.grid()
ax.set_xlabel("Time [s]")
ax.set_ylabel("Amplitude")
matplotlibUtil.formatAxisTicks(ax, 'y', 1) # adapt the x axis ticks

##############################
# ----- PANELS 2 and 3 ----- #
##############################

# extract parts of the data and plot in next row
n = len(arrData)
for i in range(2):
    idx1 = (n / 2) * i
    idx2 = idx1 + n / 4
    ax = arrAx[i + 1]
    ax.plot(arrT[idx1:idx2], arrData[idx1:idx2], linewidth = graph.lineWidth)
    ax.grid()
    ax.set_xlabel("Time [s]")
    ax.set_ylabel("Amplitude")