def plotDisplacedResponseVsBesselFunctions(azimuths, delays, ordersToShow, polarPattern) :
		for order in ordersToShow :
			print order
			ocolor=colors[order%len(colors)]
			pattern = [ polarPattern(azimuth, order) for azimuth in azimuths]
			spectrum = headDistortion.delayAmplitudeToSpectrum(delays, pattern, w)
			besselN = numpy.array([float(sympy.mpmath.besselj(order, aw*R/c)) for aw in w ])
			pylab.plot(numpy.real(spectrum), ocolor+'-', label="R"+str(order))
			pylab.plot(numpy.imag(spectrum), ocolor+'--', label="I"+str(order))
			pylab.plot(besselN+0.01, ocolor+':', label="B"+str(order))
		pylab.ylim(-1,1)
		pylab.grid(.3)
		pylab.legend()
		pylab.show()
Example #2
0
	plot.inDb()
	#plot.showPhase()
	plot.ylim(-40,5)
	delays = [
		(bmaudio.sphericalHeadDelay(azimuth, R, r)-(r-R))/c
		for azimuth in angles
		]
	for no in ordersToShow[:-1] :
		print no
		decoding = headDistortion.decoding3dMaxRe(no) / (no+1)
		decoding = headDistortion.decoding3dInPhase(no) 
		amplitudes = [ sum(
				(decoding[l] * float(sh_normalization2(l,0)) * float(sympy.legendre(l,cosTheta)) * math.sin(azimuth) / nSamples
				for l in xrange(0,no+1) ) )
			for azimuth, cosTheta in zip(angles, numpy.cos(numpy.pi/2-angles)) ]
		plot.addSpectrumData(headDistortion.delayAmplitudeToSpectrum(delays,amplitudes,w),spectralRange,"Order %i"%no)
	plot.show()

def deviated3dAmbisonics(pattern, planeWaveAzimuth, ringAzimuth, slices=72) :
	"""
	Discretely integrates a ring perpendicular to the Y axis of the decoding of a plane wave
	planeWaveAzimuth: angle that forms the incoming wave direction and the left ear (azimuth 90)
	ringAzimuth: azimuth at which we are integrating the ring
	"""
	return sum(
		( float(pattern(cosTheta))
			for cosTheta in 
				+math.sin(ringAzimuth)*math.sin(planeWaveAzimuth)
				-math.cos(ringAzimuth)*math.cos(planeWaveAzimuth)*numpy.cos(numpy.arange(0,2*pi,2*pi/slices))
			)) / slices  # TODO: I think that that should be cos but i get zeros.
def numericalComponent(order, w, delays) :
		polarPattern = polarPatternY if order&1 else polarPatternX
		pattern = [ polarPattern(azimuth, order) for azimuth in azimuths]
		return headDistortion.delayAmplitudeToSpectrum(delays, pattern, w)*2
	The plot shows the difference between the numerical integration and 
	the analytic expression of the direct sound component. It should be zero.
	"""
	azimuths = directAzimuths
	delays = numpy.array([headDelaySimplified(a) for a in azimuths])
	off=0
#	ordersToShow = xrange(0,6,1)
	for order in ordersToShow :
		print order
		ocolor=colors[order%len(colors)]
		oddOrder = order&1

		polarPattern = polarPatternY if oddOrder else polarPatternX
		pattern = [ polarPattern(azimuth, order) for azimuth in azimuths]
		spectrum = headDistortion.delayAmplitudeToSpectrum(delays, pattern, w)

		phase = 1j**((1-(-1)**order)/2) # 1, j, 1, j...
		phase = 1j if order&1 else 1
		besselN = numpy.array([
			float(sympy.mpmath.besselj(order, aw*R/c))
			for aw in w ])
		otherN = sum([
			numpy.sin(w*R/c*numpy.sin(a)-order*a)
			for a in directAzimuths ])/len(directAzimuths) # per and divided by pi
		hypothesis = phase*(besselN + 1j*otherN)

		remainder = spectrum - hypothesis

		pylab.plot(hypothesis+.01, label="H"+str(order))
#		pylab.plot(numpy.real(remainder)+off, ocolor+':', label="R"+str(order)) # should be zero