Exemplo n.º 1
0
def mkgraphs(wname, prefix):
    print wname

    wav, wp = utilities.get_wav(wname)
    sp = 1.0 / wp[2]
    timevals = numpy.arange(0, wp[3] * sp, sp)

    part = 4000
    pylab.close()
    pylab.plot(timevals[:part], wav[:part])
    pylab.xlabel('Time (s)')
    pylab.ylabel('Relative amplitude')
    pylab.savefig('%stime.png' % prefix)

    PSD_NFFT = 2**17
    (pxx, fxx) = utilities.get_psd(wav, wp[2], PSD_NFFT)

    part = 1700
    lxx = 10 * numpy.log10(pxx)
    pylab.close()
    pylab.plot(fxx[:part], lxx[:part])
    pylab.xlabel('Frequency (Hz)')
    pylab.ylabel('Power (dB)')
    pylab.savefig('%spsd.png' % prefix)

    n = 5  # num peaks

    p, c = utilities.get_peaks(pxx, n)

    peak_freqs = [fxx[i] for i in p]
    peak_db = [lxx[i] for i in p]
    print peak_freqs
    pylab.plot(peak_freqs, peak_db, 'ro', ms=4)
    for i in range(n):
        pylab.text(peak_freqs[i],
                   peak_db[i],
                   '%5.1fHz' % peak_freqs[i],
                   ha='center',
                   position=(peak_freqs[i], peak_db[i] + 1))
    pylab.xlabel('Frequency (Hz)')
    pylab.ylabel('Power (dB)')
    pylab.savefig('%speaks.png' % prefix)
Exemplo n.º 2
0
def mkgraphs(wname, prefix):
	print wname

	wav, wp = utilities.get_wav(wname)
	sp = 1.0 / wp[2]
	timevals = numpy.arange(0, wp[3] * sp, sp)

	part = 4000
	pylab.close()
	pylab.plot(timevals[:part], wav[:part])
	pylab.xlabel('Time (s)')
	pylab.ylabel('Relative amplitude')
	pylab.savefig('%stime.png' %prefix)

	PSD_NFFT = 2**17
	(pxx, fxx) = utilities.get_psd(wav, wp[2], PSD_NFFT)

	part = 1700
	lxx = 10 * numpy.log10(pxx)
	pylab.close()
	pylab.plot(fxx[:part], lxx[:part])
	pylab.xlabel('Frequency (Hz)')
	pylab.ylabel('Power (dB)')
	pylab.savefig('%spsd.png' %prefix)

	n = 5 # num peaks

	p, c = utilities.get_peaks(pxx, n)

	peak_freqs = [ fxx[i] for i in p ]
	peak_db = [ lxx[i] for i in p ]
	print peak_freqs
	pylab.plot(peak_freqs, peak_db, 'ro', ms=4)
	for i in range(n):
		pylab.text(peak_freqs[i], peak_db[i], '%5.1fHz' %peak_freqs[i], ha='center', position=(peak_freqs[i], peak_db[i] + 1))
	pylab.xlabel('Frequency (Hz)')
	pylab.ylabel('Power (dB)')
	pylab.savefig('%speaks.png' %prefix)
Exemplo n.º 3
0
	def __init__(self, fname, numpeaks, base=0):
		print '\t%s' %fname
		self.fname = fname
		self.wav, self.wp = utilities.get_wav(fname)
		self.psd, self.psd_freqs = utilities.get_psd(self.wav, self.wp[2])
		self.peaks, self.peaks_energy = utilities.get_peaks(self.psd, numpeaks)
		self.peaks_freqs = numpy.array([self.psd_freqs[i] for i in self.peaks])
		self.percs = self.peaks_energy / self.psd.sum()
		self.peaks_notes = utilities.get_note(self.peaks_freqs)

		if base:
			bi = None
			diff = 100

			for i in self.peaks_freqs:
				d = abs(base - i)
				if d < diff:
					diff = d
					bi = i

			self.base = bi
		else:
			self.base = self.psd_freqs[self.peaks[0]]
Exemplo n.º 4
0
def f(fname):
	wav, wp = utilities.get_wav(fname)
	pxx, fxx = utilities.get_psd(wav, wp[2])
	p, c = utilities.get_peaks(pxx, n)
	pf = [ fxx[i] for i in p ]
	return wav, wp, pxx, fxx, p, c, pf
Exemplo n.º 5
0
def f(fname):
    wav, wp = utilities.get_wav(fname)
    pxx, fxx = utilities.get_psd(wav, wp[2])
    p, c = utilities.get_peaks(pxx, n)
    pf = [fxx[i] for i in p]
    return wav, wp, pxx, fxx, p, c, pf