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 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()
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') 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)
# 3rd Octave Filter #=============================================================================== fi = FiltFiltOctave(source=un, band=freq, fraction='Third octave') #============================================================================== #write to H5 File #============================================================================== # # write Signal to wav file # ww = WriteWAV(source = p0) # ww.channels = [0,27] # ww.save() # write H5 File h5f1 = WriteH5(name='ps', source=ps).save() #============================================================================== #load H5 File #============================================================================== #load from h5 File mt1 = MaskedTimeSamples(name='ps') #============================================================================== #fixed focus time domain beamforming point source #============================================================================== bt_ps = BeamformerTime(source=ps, grid=g, mpos=m, c=c0) bt_ps_h5 = BeamformerTime(source=mt1, grid=g, mpos=m, c=c0) btSq_ps = BeamformerTimeSq(source=ps, grid=g, mpos=m, r_diag=True, c=c0)