def run(): from os import path from acoular import __file__ as bpath, MicGeom, WNoiseGenerator, PointSource,\ Mixer, WriteH5, TimeSamples, PowerSpectra, RectGrid, SteeringVector,\ BeamformerBase, L_p from pylab import figure, plot, axis, imshow, colorbar, show # set up the parameters sfreq = 51200 duration = 1 nsamples = duration * sfreq micgeofile = path.join(path.split(bpath)[0], 'xml', 'array_64.xml') h5savefile = 'three_sources.h5' # generate test data, in real life this would come from an array measurement mg = MicGeom(from_file=micgeofile) n1 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=1) n2 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=2, rms=0.7) n3 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=3, rms=0.5) p1 = PointSource(signal=n1, mics=mg, loc=(-0.1, -0.1, 0.3)) p2 = PointSource(signal=n2, mics=mg, loc=(0.15, 0, 0.3)) p3 = PointSource(signal=n3, mics=mg, loc=(0, 0.1, 0.3)) pa = Mixer(source=p1, sources=[p2, p3]) wh5 = WriteH5(source=pa, name=h5savefile) wh5.save() # analyze the data and generate map ts = TimeSamples(name=h5savefile) ps = PowerSpectra(time_data=ts, block_size=128, window='Hanning') rg = RectGrid( x_min=-0.2, x_max=0.2, y_min=-0.2, y_max=0.2, z=0.3, \ increment=0.01 ) st = SteeringVector(grid=rg, mics=mg) bb = BeamformerBase(freq_data=ps, steer=st) pm = bb.synthetic(8000, 3) Lm = L_p(pm) # show map imshow( Lm.T, origin='lower', vmin=Lm.max()-10, extent=rg.extend(), \ interpolation='bicubic') colorbar() # plot microphone geometry figure(2) plot(mg.mpos[0], mg.mpos[1], 'o') axis('equal') show()
def get_sql_sources(cursor, sources_id, sfreq, mpos): # sources_id -> id für eine Quellkartierung mit bestimmten Quellen # source_id -> id jeder einzelnen source # source ids -> liste aller ids der einzelnen sources einer sources id source_ids = fetchall(cursor, get_source_ids, sources_id) cursor.execute(sq(get_ap, 1)) (ap) = cursor.fetchone() sourcelist = [] # list for source_id in source_ids: cursor.execute( sq(get_source, sources_id, source_id)) # get the source parameters one after the other (signal_id, x1, x2, x3, pol_type, dipole_id, p_rms) = cursor.fetchone() # generate harmonic or noise source... sgnl = WNoiseGenerator(rms=p_rms, sample_freq=sfreq, numsamples=512000, seed=(signal_id - 1)) # newsrc = PointSource(signal = sgnl, # mpos = m_error, # loc = (x1*ap, x2*ap, x3*ap)) newsrc = PointSource(signal=sgnl, mpos=mpos, loc=(x1 * ap[0], x2 * ap[0], x3 * ap[0])) sourcelist.append(newsrc) # add the new source to the list if len(source_ids ) > 1: # if there are multiple sources, they have to be mixed src = Mixer(source=sourcelist[0], sources=sourcelist[1:]) else: # if there's only one source, it is the only one in the list src = sourcelist[0] return src
def create_test_time_data(nsamples): """ creates test data for a single moving monopole emitting white noise Parameters ---------- speed : float source velocity in m/s. Returns ------- None. """ n1 = WNoiseGenerator(sample_freq=SFREQ, numsamples=nsamples, seed=SEED) p1 = MovingPointSource(signal=n1, mics=MGEOM, trajectory=TRAJ, conv_amp=CONV_AMP) wh5 = WriteH5(source=p1, name=FNAME) print(50 * "#") print(f"create {FNAME} ...") print(f"num samples: {nsamples}, pass-by time: {t_passby}s") print(50 * "#") wh5.save()
def test_timeconvolve(self): """compare results of timeconvolve with numpy convolve""" # Parameters NSAMPLES = 25 N1 = WNoiseGenerator(sample_freq=1000, numsamples=NSAMPLES, seed=1) MGEOM = MicGeom(mpos_tot=[[1], [1], [1]]) P1 = PointSource(signal=N1, mics=MGEOM) KERNEL = np.random.rand(20) CONV = TimeConvolve(kernel=KERNEL, source=P1) SIG = tools.return_result(P1, num=NSAMPLES) RES = tools.return_result(CONV, num=100) for i in range(P1.numchannels): REF = np.convolve(np.squeeze(KERNEL), np.squeeze(SIG[:, i])) np.testing.assert_allclose(np.squeeze(RES[:, i]), REF, rtol=1e-5, atol=1e-8)
BeamformerTimeSqTraj,BeamformerCapon,BeamformerMusic,BeamformerDamas,BeamformerCMF,BeamformerClean,BeamformerFunctional,\ TimeCache, FiltOctave, BeamformerTime, TimePower, IntegratorSectorTime, \ PointSource, MovingPointSource, SineGenerator, WNoiseGenerator, Mixer, WriteWAV from pylab import subplot, imshow, show, colorbar, plot, transpose, figure, \ psd, axis, xlim, ylim, title, tight_layout, text freq = 48000 sfreq = freq / 2 #sampling frequency duration = 1 nsamples = freq * duration datafile = 'cry_n0000001.wav' micgeofile = path.join(path.split(bpath)[0], 'xml', 'array_64_8mic.xml') h5savefile = 'cry_n0000001.wav' m = MicGeom(from_file=micgeofile) n = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=1) #1pascal 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')
from os import path from acoular import __file__ as bpath, MicGeom, WNoiseGenerator, PointSource,\ Mixer, WriteH5, TimeSamples, PowerSpectra, RectGrid, BeamformerBase, L_p from pylab import figure, plot, axis, imshow, colorbar, show # set up the parameters sfreq = 51200 duration = 1 nsamples = duration*sfreq micgeofile = path.join(path.split(bpath)[0],'xml','array_64.xml') h5savefile = 'three_sources.h5' # generate test data, in real life this would come from an array measurement mg = MicGeom( from_file=micgeofile ) n1 = WNoiseGenerator( sample_freq=sfreq, numsamples=nsamples, seed=1 ) n2 = WNoiseGenerator( sample_freq=sfreq, numsamples=nsamples, seed=2, rms=0.7 ) n3 = WNoiseGenerator( sample_freq=sfreq, numsamples=nsamples, seed=3, rms=0.5 ) p1 = PointSource( signal=n1, mpos=mg, loc=(-0.1,-0.1,0.3) ) p2 = PointSource( signal=n2, mpos=mg, loc=(0.15,0,0.3) ) p3 = PointSource( signal=n3, mpos=mg, loc=(0,0.1,0.3) ) pa = Mixer( source=p1, sources=[p2,p3] ) wh5 = WriteH5( source=pa, name=h5savefile ) wh5.save() # analyze the data and generate map ts = TimeSamples( name=h5savefile ) ps = PowerSpectra( time_data=ts, block_size=128, window='Hanning' ) rg = RectGrid( x_min=-0.2, x_max=0.2, y_min=-0.2, y_max=0.2, z=0.3, \ increment=0.01 ) bb = BeamformerBase( freq_data=ps, grid=rg, mpos=mg )
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 (f_borders, p, f_center) = barspectrum(spectrum_data, freqs, band, bar=True) (f_borders_, p_, f_center_) = barspectrum(spectrum_data, freqs,
#=============================================================================== # 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 #=============================================================================== p0 = MovingPointSource(signal=s1, mpos=m, trajectory=tr1) #t = p0 # use only moving source p1 = PointSource(signal=n1, mpos=m, loc=(0, R, Z)) t = Mixer(source=p0, sources=[ p1, ]) # mix both signals #t = p1 # use only fix source
from os.path import join import numpy as np from acoular import __file__ as bpath, config, WNoiseGenerator, PointSource, MicGeom config.global_caching = "none" # if this flag is set to True, new data will be simulated and WRITE_NEW_REFERENCE_DATA = False # new source 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 wanted changes of the sources. # Parameters SFREQ = 1000 SEED = 1 NSAMPLES = 100 N1 = WNoiseGenerator(sample_freq=SFREQ, numsamples=NSAMPLES, seed=SEED) MGEOM = MicGeom(mpos_tot=[[1], [1], [1]]) def get_source_result(Source, num=32): """ returns the result for a given source Parameters ---------- source : cls source class that is tested. num : int, optional number of samples to return. The default is 32. Returns