def plotAllAngles(name, polarPattern, order, degreesResolution=5) :
		levels=30
		azimuths = xrange(-90,90,degreesResolution)
		spectralBinPositions = numpy.arange(0,spectralRange, spectralRange/spectrumBins)
		spectrums = numpy.zeros((len(azimuths), spectrumBins))
		pylab.rcParams['figure.figsize']=(15,7)
		pylab.rcParams['figure.subplot.left'] = 0.08
		pylab.rcParams['figure.subplot.right'] = 1.0
		for i,azimuth in enumerate(azimuths) :
			spectrums[i,:] = 20*numpy.log(numpy.abs(headDistortion.sphericHeadSimulation(
					bmaudio.sphericalHeadDelay, azimuth, N, polarPattern, [order]).values()[0]))
		pylab.contourf(spectralBinPositions, azimuths, spectrums,levels,cmap=pylab.cm.Greys_r)
		pylab.colorbar().set_label("Magnitude (dB)")
		pylab.contour(spectralBinPositions, azimuths, spectrums,levels,cmap=pylab.cm.Greys)
		pylab.xlabel("Frequency (Hz)")
		pylab.ylabel("Azimuth (degrees)")
		pylab.savefig('figures/'+os.path.basename(os.path.splitext(__file__)[0])+"-"+name+".pdf", format="pdf")
		pylab.show()
		pylab.close()
示例#2
0
	print "Please specify one decoding:", ", ".join(decodings.keys())
	sys.exit()
decodingName=sys.argv[1]
useLog = '--log' in sys.argv
showPhase = '--phase' in sys.argv

polarPattern = decoding=decodings[decodingName]

plot = bmaudio.SpectrumDisplay()
plot.inDb()
if showPhase : plot.showPhase()
if useLog : plot.setLogFrequency()
plot.ylim(-25,5)
#plot.flim(0,20000)
#ordersToShow = [1,3,5,7,9,15,17]
#ordersToShow = numpy.arange(7)+32

cases = [
	("analytical", headDistortion.sphericHeadSimulation(bmaudio.sphericalHeadDelay, sourceAzimuth, N, polarPattern, ordersToShow)),
]
for legend, filters in cases :
	for order in ordersToShow :
		plot.addSpectrumData(
			filters[order], 22050, "Order %i"%(order))
plot.flim(0,spectralRange)
plot.hardcopy('figures/'+os.path.basename(os.path.splitext(__file__)[0])+"-"+decodingName+".pdf", "pdf")




示例#3
0
import bmaudio
import pylab

from parameters import *

import headDistortion

def polarPatternX(azimuth, order) :
	return [ math.cos(order * azimuth) ]
def polarPatternY(azimuth, order) :
	return [ math.sin(order * azimuth) ]
N=721
evenOrdersToShow = 0,2,4#,6#,8,#22,24,34
oddOrdersToShow = 1,3,#5#,7,9,#23,25,35
filters = dict()
filters.update(headDistortion.sphericHeadSimulation(
	bmaudio.sphericalHeadDelay, 0, N, polarPatternX, evenOrdersToShow))
filters.update(headDistortion.sphericHeadSimulation(
	bmaudio.sphericalHeadDelay, 0, N, polarPatternY, oddOrdersToShow))
if True :
	plot = bmaudio.SpectrumDisplay()
	plot.inDb()
#	plot.showPhase()
	plot.ylim(-30,0)
	plot.flim(0,spectralRange)
	plot.setStylePreference(["lines","colors"])
#	plot.setStyleVariation("lines", ["-", "--"]) # even, odd
	plot.setStyleVariation("colors", ["k"])
	for order in sorted(filters.keys()) :
		print order,"\t",(abs(filters[order]).argmax())*spectralRange/nBins*R/c
	#	print order, filters[order].argmax()*spectralRange/nBins*R/c
		legend = "$\\mathrm{H_{%%s,%s}}$"% ('-' if order&1 else '+')
polarPattern = headDistortion.maxrePolarPattern
plot = bmaudio.SpectrumDisplay()
plot.inDb()
#plot.showPhase()
plot.ylim(-15,15)
plot.flim(0,spectralRange)
plot.setStylePreference(["lines","colors"])
plot.setStyleVariation("colors",["k"])
plot.setLogFrequency()
plot.legendPosition("lower left")
#plot.flim(0,20000)
#ordersToShow = [1,3,5,7,9,15,17]
#ordersToShow = numpy.arange(7)+32
ordersToShow = 1,
Ncontinuous = 720
continuousFilter = headDistortion.sphericHeadSimulation(bmaudio.sphericalHeadDelay, sourceAzimuth, Ncontinuous, polarPattern, ordersToShow)
Ns = 12, 24, 36, 72,
for N in Ns :
	filters = headDistortion.sphericHeadSimulation(bmaudio.sphericalHeadDelay, sourceAzimuth, N, polarPattern, ordersToShow)
	for order in ordersToShow :
		print numpy.sum(numpy.abs(filters[order])**2), numpy.sum(numpy.abs(filters[order]**2))*math.sqrt(N)
		plot.addSpectrumData(
			filters[order]/continuousFilter[order], 22050, "%i speakers"%(N))
#			filters[order], 22050, "%i speakers"%(N))

plot.hardcopy('figures/'+os.path.basename(os.path.splitext(__file__)[0])+".pdf", "pdf")