コード例 #1
0
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()
コード例 #2
0
#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================
figure(1, (10, 6))
i1 = 1  #no of subplot
for b in (bb, bc, be, bm, bl, bo, bs, bd, bcmf, bf):
    subplot(3, 4, i1)
    i1 += 1
    map = b.synthetic(cfreq, 1)
    mx = L_p(map.max())
    imshow(L_p(map.T),
           origin='lower',
           vmin=mx - 15,
           interpolation='nearest',
           extent=g.extend())
    colorbar()
    title(b.__class__.__name__)

#===============================================================================
# delay and sum beamformer in time domain
# processing chain: beamforming, filtering, power, average
#===============================================================================
bt = BeamformerTime(source=t1, grid=g, mpos=m, c=346.04)
ft = FiltFiltOctave(source=bt, band=cfreq)
pt = TimePower(source=ft)
avgt = TimeAverage(source=pt, naverage=1024)
cacht = TimeCache(source=avgt)  # cache to prevent recalculation

#===============================================================================
# delay and sum beamformer in time domain with autocorrelation removal
コード例 #3
0
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 )
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()
コード例 #4
0
bl = BeamformerClean(beamformer=bb, n_iter=100)
bf = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, \
    gamma=4)

#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================
figure(1,(10,6))
i1 = 1 #no of subplot
for b in (bb, bc, be, bm, bl, bo, bs, bd, bcmf, bf):
    subplot(3,4,i1)
    i1 += 1
    map = b.synthetic(cfreq,1)
    mx = L_p(map.max())
    imshow(L_p(map.T), origin='lower', vmin=mx-15,
           interpolation='nearest', extent=g.extend())
    colorbar()
    title(b.__class__.__name__)

#===============================================================================
# delay and sum beamformer in time domain
# processing chain: beamforming, filtering, power, average
#===============================================================================
bt = BeamformerTime(source=t1, grid=g, mpos=m, c=346.04)
ft = FiltFiltOctave(source=bt, band=cfreq)
pt = TimePower(source=ft)
avgt = TimeAverage(source=pt, naverage = 1024)
cacht = TimeCache( source = avgt) # cache to prevent recalculation

#===============================================================================
# delay and sum beamformer in time domain with autocorrelation removal
コード例 #5
0
ファイル: example2.py プロジェクト: xinkez/acoular
bt = BeamformerTimeSq(source=fi, grid=g, mpos=m, r_diag=True, c=c0)
avgt = TimeAverage(source=bt,
                   naverage=int(sfreq * tmax / 16))  # 16 single images
cacht = TimeCache(source=avgt)  # cache to prevent recalculation
map2 = zeros(g.shape)  # accumulator for average
# plot single frames
figure(1, (8, 7))
i = 1
for res in cacht.result(1):
    res0 = res[0].reshape(g.shape)
    map2 += res0  # average
    i += 1
    subplot(4, 4, i)
    mx = L_p(res0.max())
    imshow(L_p(transpose(res0)), vmax=mx, vmin=mx-10, interpolation='nearest',\
        extent=g.extend(), origin='lower')
    colorbar()
map2 /= i

subplot(4, 4, 1)
text(0.4, 0.25, 'fixed\nfocus', fontsize=15, ha='center')
axis('off')
tight_layout()

#===============================================================================
# moving focus time domain beamforming
#===============================================================================

# new grid needed, the trajectory starts at origin and is oriented towards +x
# thus, with the circular movement assumed, the center of rotation is at (0,2.5)
g1 = RectGrid(x_min=-3.0, x_max=+3.0, y_min=-1.0, y_max=+5.0, z=0, \
コード例 #6
0
ファイル: example_v2.py プロジェクト: waynezv/ANN
bd = BeamformerDamas(beamformer = bb, n_iter = 100)
bo = BeamformerOrth(beamformer = be, eva_list = range(38, 54))

bs = BeamformerCleansc(freq_data = f, grid = g, mpos = m, r_diag = True, c = 346.04)
bf = BeamformerCMF(freq_data = f, grid = g, mpos = m, c = 346.04, method = 'LassoLarsBIC')
bl = BeamformerClean(beamformer = bb, n_iter = 100)
bn = BeamformerFunctional(freq_data = f, grid = g, mpos = m, r_diag = True, c = 346.04, gamma = 4)

figure(1)
i1 = 1
for b in (bb, bc, be, bm, bd, bo, bs, bf, bl, bn):
    subplot(3, 4, i1)
    i1 += 1
    map = b.synthetic(freqInt, 1)
    mx = L_p(map.max())
    imshow(L_p(map.T), vmax = mx, vmin = mx - 15, interpolation = 'nearest', extent = g.extend())
    colorbar()
    title(b.__class__.__name__)

bt = BeamformerTime(source = t1, grid = g, mpos = m, c = 346.04)
ft = FiltFiltOctave(source = bt, band = freqInt)
pt = TimePower(source = ft)
avgt = TimeAverage(source = pt, naverage = 1024)
cacht = TimeCache(source = avgt)

fi = FiltFiltOctave(source = t1, band = freqInt)
bts = BeamformerTimeSq(source = fi, grid = g, mpos = m, r_diag = True, c = 346.04)
avgts = TimeAverage(source = bts, naverage = 1024)
cachts = TimeCache(source = avgts)

i2 = 2
コード例 #7
0
ファイル: acoular_demo.py プロジェクト: e3e-monitor/acoular
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 )
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()
コード例 #8
0
ファイル: precisionTest.py プロジェクト: esarradj/acoular
bdp6432Res  = bdp6432.synthetic(cfreq,1)

#64 Bit
bd6464 = BeamformerDamas(beamformer=bb64, n_iter=100, psf_precision='float64')
bd6464Res = bd6464.synthetic(cfreq,1)
bc6464 = BeamformerClean(beamformer=bb64, psf_precision='float64')
bc6464Res = bc6464.synthetic(cfreq,1)
bdp6464 = BeamformerDamasPlus(beamformer=bb64, n_iter=100, psf_precision='float64')
bdp6464Res  = bdp6464.synthetic(cfreq,1)



#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================
i1 = 1
for b in (bb32, bd3232, bc3232, bdp3232, bd3264, bc3264, bdp3264,
          bb64, bd6432, bc6432, bdp6432, bd6464, bc6464, bdp6464):
    subplot(2, 7, i1)
    i1 += 1
    res = b.synthetic(cfreq,1)
    mx = L_p(res.max())
    imshow(L_p(res.T), vmax=mx, vmin=mx-15, 
           interpolation='nearest', extent=g.extend())
    print(b.steer)
    colorbar()
    title(b.__class__.__name__ + b.precision,fontsize='small')


show()
コード例 #9
0
ファイル: example2.py プロジェクト: esarradj/acoular
fi = FiltFiltOctave(source=t, band=freq, fraction='Third octave')
bt = BeamformerTimeSq(source=fi, steer=st, r_diag=True)
avgt = TimeAverage(source=bt, naverage=int(sfreq*tmax/16)) # 16 single images
cacht = TimeCache(source=avgt) # cache to prevent recalculation
map2 = zeros(g.shape) # accumulator for average
# plot single frames
figure(1,(8,7))
i = 1
for res in cacht.result(1):
    res0 = res[0].reshape(g.shape)
    map2 += res0 # average
    i += 1  
    subplot(4,4,i)
    mx = L_p(res0.max())
    imshow(L_p(transpose(res0)), vmax=mx, vmin=mx-10, interpolation='nearest',\
        extent=g.extend(), origin='lower')
    colorbar()
map2 /= i

subplot(4,4,1)
text(0.4,0.25,'fixed\nfocus', fontsize=15, ha='center')
axis('off')
tight_layout()


#===============================================================================
# moving focus time domain beamforming
#===============================================================================

# new grid needed, the trajectory starts at origin and is oriented towards +x
# thus, with the circular movement assumed, the center of rotation is at (0,2.5)
コード例 #10
0
ファイル: example2.py プロジェクト: shiweixingcn/acoular
fi = FiltFiltOctave(source=t, band=freq, fraction="Third octave")
bt = BeamformerTimeSq(source=fi, grid=g, mpos=m, r_diag=True, c=c0)
avgt = TimeAverage(source=bt, naverage=int(sfreq * tmax / 16))  # 16 single images
cacht = TimeCache(source=avgt)  # cache to prevent recalculation
map2 = zeros(g.shape)  # accumulator for average
# plot single frames
figure(1)
i = 0
for res in cacht.result(1):
    res0 = res[0].reshape(g.shape)
    map2 += res0  # average
    i += 1
    subplot(4, 4, i)
    mx = L_p(res0.max())
    imshow(L_p(transpose(res0)), vmax=mx, vmin=mx - 10, interpolation="nearest", extent=g.extend(), origin="lower")
    colorbar()
map2 /= i
suptitle("fixed focus")

# ===============================================================================
# moving focus time domain beamforming
# ===============================================================================

# new grid needed, the trajectory starts at origin and is oriented towards +x
# thus, with the circular movement assumed, the center of rotation is at (0,2.5)
g1 = RectGrid(
    x_min=-3.0, x_max=+3.0, y_min=-1.0, y_max=+5.0, z=0, increment=0.3
)  # grid point of origin is at trajectory (thus z=0)
# beamforming with trajectory (rvec axis perpendicular to trajectory)
bts = BeamformerTimeSqTraj(source=fi, grid=g1, mpos=m, trajectory=tr, rvec=array((0, 0, 1.0)))