def fbeampreparation(): # Gradangaben von Theta im Intervall [0,180] statt wie bei DCASE [90,-90] M1 = spherical2cart(deg2rad(45),deg2rad(55),0.042) M2 = spherical2cart(deg2rad(315),deg2rad(125),0.042) M3 = spherical2cart(deg2rad(135),deg2rad(125),0.042) M4 = spherical2cart(deg2rad(225),deg2rad(55),0.042) mg = MicGeom() mg.mpos_tot = array([M1,M2,M3,M4]).T # add microphone positions to MicGeom object # define evaluation grid rg = SphericalGrid_Equiangular(NPOINTS_AZI, NPOINTS_ELE) st = SteeringVector(grid=rg, mics=mg) if DEBUG: firstframe = STARTFRAME lastframe = ENDFRAME else: firstframe = 0 lastframe = 600 return mg, rg, st, firstframe, lastframe
# only execute this example when script is not # imported as module but started explicitely: if __name__ == '__main__': ################################################################### ### Defining noise source ### from acoular import WNoiseGenerator, PointSource, PowerSpectra, MicGeom sfreq= 12800 n1 = WNoiseGenerator(sample_freq = sfreq, numsamples = 10*sfreq, seed = 1) m = MicGeom() m.mpos_tot = array([[0,0,0]]) t = PointSource(signal = n1, mpos = m, loc = (1, 0, 1)) f = PowerSpectra(time_data = t, window = 'Hanning', overlap = '50%', block_size = 4096) ################################################################### ### Plotting ### from pylab import figure,plot,show,xlim,ylim,xscale,xticks,xlabel,ylabel,grid,real from acoular import L_p
p = PointSource(signal=n, mpos=m, loc=(-0.1, -0.1, 0.3)) p1 = Mixer(source=p) wh5 = WriteH5(source=p, name=h5savefile) wh5.save() #definition the different source signal r = 52.5 nsamples = long(sfreq * 0.3) n1 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples) s1 = SineGenerator(sample_freq=sfreq, numsamples=nsamples, freq=freq) s2 = SineGenerator(sample_freq=sfreq, numsamples=nsamples, freq=freq, \ phase=pi) #define a circular array of 8 microphones m = MicGeom('array_64_8mic.xml') m.mpos_tot = array([(r*sin(2*pi*i+pi/8), r*cos(2*pi*i+pi/8), 0) \ for i in linspace(0.0, 1.0, 8, False)]).T t = MaskedTimeSamples(name=datafile) f = PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \ ind_low=1,ind_high=30) g = RectGrid(x_min=0 - .2, x_max=0.3, y_min=-0.13, y_max=0.3, z=0, increment=0.05) bb = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04) bc = BeamformerCapon(freq_data=f, grid=g, mpos=m, c=346.04, cached=False) be = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, n=54) bm = BeamformerMusic(freq_data=f, grid=g, mpos=m, c=346.04, n=6) bd = BeamformerDamas(beamformer=bb, n_iter=100) bo = BeamformerOrth(beamformer=be, eva_list=list(range(38, 54)))
All rights reserved. """ from acoular import WNoiseGenerator, PointSource, PowerSpectra, MicGeom, L_p from acoular.tools import barspectrum from numpy import array from pylab import figure,plot,show,xlim,ylim,xscale,xticks,xlabel,ylabel,\ grid,real, title, legend # constants sfreq = 12800 # sample frequency band = 3 # octave: 1 ; 1/3-octave: 3 (for plotting) # set up microphone at (0,0,0) m = MicGeom() m.mpos_tot = array([[0, 0, 0]]) # create noise source n1 = WNoiseGenerator(sample_freq=sfreq, numsamples=10 * sfreq, seed=1) t = PointSource(signal=n1, mics=m, loc=(1, 0, 1)) # create power spectrum f = PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=4096) # get spectrum data spectrum_data = real(f.csm[:, 0, 0]) # get power spectrum from cross-spectral matrix freqs = f.fftfreq() # FFT frequencies # use barspectrum from acoular.tools to create third octave plot data
def cart2spherical_dcase(x, y, z): phi = arctan2(y, x) * 180 / pi theta = arccos(z / (sqrt(x**2 + y**2 + z**2))) * 180 / pi return array([phi, 90 - theta]) # Gradangaben von Theta im Intervall [0,180] statt wie bei DCASE [90,-90] M1 = spherical2cart(deg2rad(45), deg2rad(55), 0.042) M2 = spherical2cart(deg2rad(315), deg2rad(125), 0.042) M3 = spherical2cart(deg2rad(135), deg2rad(125), 0.042) M4 = spherical2cart(deg2rad(225), deg2rad(55), 0.042) mg = MicGeom() mg.mpos_tot = array([M1, M2, M3, M4]).T # add microphone positions to MicGeom object # define evaluation grid # Hier könntest du vielleicht eine neue Spherical Grid Klasse schreiben oder # eine ArbitraryGrid Klasse, damit wir ein sinnvolles Gitter zur Lokalisierung # verwenden können. # Als Anregung siehe: https://spaudiopy.readthedocs.io/en/latest/spaudiopy.grids.html # rg = SphericalGrid_Equiangular(NPOINTS_AZI, NPOINTS_ELE) st = SteeringVector(grid=rg, mics=mg) # analyze the data and generate map name = AUDIO_DIR + TRACK ts = WavSamples(name=name, start=STARTFRAME * NUM, stop=ENDFRAME * NUM) bf = BeamformerTime(source=ts, steer=st) #ft = FiltFiltOctave(source=bf,band=4000)
#acoular imports import acoular acoular.config.global_caching = 'none' # to make sure that nothing is cached from acoular import MicGeom, RectGrid3D, \ SlotJet, OpenJet, RotatingFlow, \ Environment, UniformFlowEnvironment, GeneralFlowEnvironment # if this flag is set to True WRITE_NEW_REFERENCE_DATA = False # results are generated for comparison during testing. # Should always be False. Only set to True if it is necessary to # recalculate the data due to intended changes of the Beamformers. m = MicGeom() m.mpos_tot = ((0.5, 0.5, 0), (0, 0, 0), (-0.5, -0.5, 0)) mc = m.mpos g = RectGrid3D(x_min=-0.2, x_max=0.2, y_min=-0.2, y_max=0.2, z_min=0.5, z_max=0.9, increment=0.2) gc = g.gpos flows = [ SlotJet(v0=70.0, origin=(-0.7, 0, 0.7)), OpenJet(v0=70.0, origin=(-0.7, 0, 0.7)), RotatingFlow(v0=70.0, rpm=1000.0) ]
tr1 = Trajectory() tmax = U/rps delta_t = 1./rps/16.0 # 16 steps per revolution for t in arange(0, tmax*1.001, delta_t): i = t* rps * 2 * pi #angle # define points for trajectory spline tr.points[t] = (R*cos(i), R*sin(i), Z) # anti-clockwise rotation tr1.points[t] = (R*cos(i), R*sin(i), Z) # anti-clockwise rotation #=============================================================================== # define circular microphone array #=============================================================================== m = MicGeom() # set 28 microphone positions m.mpos_tot = array([(r*sin(2*pi*i+pi/4), r*cos(2*pi*i+pi/4), 0) \ for i in linspace(0.0, 1.0, 28, False)]).T #=============================================================================== # define the different source signals #=============================================================================== if sys.version_info > (3,): long = int nsamples = long(sfreq*tmax) n1 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples) s1 = SineGenerator(sample_freq=sfreq, numsamples=nsamples, freq=freq) s2 = SineGenerator(sample_freq=sfreq, numsamples=nsamples, freq=freq, \ phase=pi) #=============================================================================== # define the moving source and one fixed source #===============================================================================
# Parameters FNAME = join('reference_data', 'beamformer_traj_time_data.h5') SFREQ = 6000 SPEED = 10 # km/h SEED = 1 D = .5 SOURCE_POS = (0.0, 0.0, D) passby_dist = .5 # distance that the source is passing in front of array CONV_AMP = True # create linear mic geom MGEOM = MicGeom() N = 5 L = .5 MGEOM.mpos_tot = np.zeros((3, N), dtype=np.float64) win = np.sin(np.arange(N) * np.pi / (N - 1)) b = 0.4 MGEOM.mpos_tot[0] = np.linspace(-L, L, N) * (1 - b) / (win * b + 1 - b) # Monopole Trajectory t_passby = passby_dist / SPEED / 3.6 nsamples = int(t_passby * SFREQ) TRAJ = Trajectory() # source center TRAJ.points[0] = (-passby_dist / 2 + SOURCE_POS[0], SOURCE_POS[1], SOURCE_POS[2]) TRAJ.points[t_passby] = (+passby_dist / 2, SOURCE_POS[1], SOURCE_POS[2]) def create_test_time_data(nsamples): """