Exemplo n.º 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()
Exemplo n.º 2
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()
Exemplo n.º 3
0
#ww.save()

#===============================================================================
# fixed focus frequency domain beamforming
#===============================================================================

f = PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \
    ind_low=1,ind_high=30) # CSM calculation
g = RectGrid(x_min=-3.0,
             x_max=+3.0,
             y_min=-3.0,
             y_max=+3.0,
             z=Z,
             increment=0.3)
b = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=c0)
map1 = b.synthetic(freq, 3)

#===============================================================================
# fixed focus time domain beamforming
#===============================================================================

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, (8, 7))
i = 1
for res in cacht.result(1):
Exemplo n.º 4
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()
Exemplo n.º 5
0
#===============================================================================
# this provides the cross spectral matrix and defines the beamformer
# usually, another type of beamformer (e.g. CLEAN-SC) would be more appropriate
# to be really fast, we restrict ourselves to only 10 frequencies
# in the range 2000 - 6000 Hz (5*400 - 15*400)
#===============================================================================

f = EigSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \
    ind_low=5, ind_high=15)
b = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04)

#===============================================================================
# reads the data, finds the maximum value (to properly scale the views)
#===============================================================================

map = b.synthetic(4000,1)
L1 = L_p(map)
mx = L1.max()

#===============================================================================
# print out the result integrated over an 3d-sector of the 3d map
#===============================================================================

print(L_p(b.integrate((-0.3,-0.1,0.58,-0.1,0.1,0.78)))[f.ind_low:f.ind_high])

#===============================================================================
# displays the 3d view
#===============================================================================

X,Y,Z = mgrid[g.x_min:g.x_max:1j*g.nxsteps,\
            g.y_min:g.y_max:1j*g.nysteps,\
Exemplo n.º 6
0
eva = f.eva[:]

f32 = EigSpectra(time_data=t1, 
               window='Hanning', overlap='50%', block_size=128, #FFT-parameters
               ind_low=7, ind_high=15, precision='complex64') #to save computational effort, only
csm32 = f32.csm[:]
eva32 = f32.eva[:]

psf32 = PointSpreadFunction(grid=g, mpos=m, c=346.04, precision='float32')
psf32Res = psf32.psf[:]

psf64 = PointSpreadFunction(grid=g, mpos=m, c=346.04, precision='float64')
psf64Res = psf64.psf[:]

bb32 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, precision='float32')
bb32Res = bb32.synthetic(cfreq,1)

bb64 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, precision='float64')
bb64Res = bb64.synthetic(cfreq,1)

bf = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, gamma = 60, precision='float32')
bfRes = bf.synthetic(cfreq,1)

# 32 Bit PSF precision
bd3232 = BeamformerDamas(beamformer=bb32, n_iter=100, psf_precision='float32')
bd3232Res = bd3232.synthetic(cfreq,1)
bc3232 = BeamformerClean(beamformer=bb32, psf_precision='float32')
bc3232Res = bc3232.synthetic(cfreq,1)
bdp3232 = BeamformerDamasPlus(beamformer=bb32, n_iter=100, psf_precision='float32')
bdp3232Res  = bdp3232.synthetic(cfreq,1)
Exemplo n.º 7
0
# uncomment to save the signal to a wave file
#ww = WriteWAV(source = t)
#ww.channels = [0,14]
#ww.save()

#===============================================================================
# fixed focus frequency domain beamforming
#===============================================================================

f = PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \
    ind_low=1,ind_high=30) # CSM calculation 
g = RectGrid(x_min=-3.0, x_max=+3.0, y_min=-3.0, y_max=+3.0, z=Z, increment=0.3)

st = SteeringVector(grid=g, mics=m)
b = BeamformerBase(freq_data=f, steer=st, r_diag=True)
map1 = b.synthetic(freq,3)

#===============================================================================
# fixed focus time domain beamforming
#===============================================================================
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
                         r_diag=False,
                         c=346.04,
                         steer='inverse')
bb3Full = BeamformerBase(freq_data=f,
                         grid=g,
                         mpos=m,
                         r_diag=False,
                         c=346.04,
                         steer='true level')
bb4Full = BeamformerBase(freq_data=f,
                         grid=g,
                         mpos=m,
                         r_diag=False,
                         c=346.04,
                         steer='true location')
Lbb1Rem = L_p(bb1Rem.synthetic(4000, 1))
Lbb2Rem = L_p(bb2Rem.synthetic(4000, 1))
Lbb3Rem = L_p(bb3Rem.synthetic(4000, 1))
Lbb4Rem = L_p(bb4Rem.synthetic(4000, 1))
Lbb1Full = L_p(bb1Full.synthetic(4000, 1))
Lbb2Full = L_p(bb2Full.synthetic(4000, 1))
Lbb3Full = L_p(bb3Full.synthetic(4000, 1))
Lbb4Full = L_p(bb4Full.synthetic(4000, 1))

bf1Rem = BeamformerFunctional(freq_data=f,
                              grid=g,
                              mpos=m,
                              r_diag=True,
                              c=346.04,
                              steer='classic',
                              gamma=3)
    z_min=0.48, z_max=0.88, increment=0.1)
f = EigSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, ind_low=5, ind_high=15)
csm = f.csm[:]
eva = f.eva[:]
eve = f.eve[:]

#""" Creating the beamformers
bb1Rem = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='classic')
bb2Rem = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='inverse')
bb3Rem = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='true level')
bb4Rem = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='true location')
bb1Full = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='classic')
bb2Full = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='inverse')
bb3Full = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true level')
bb4Full = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true location')
Lbb1Rem = L_p(bb1Rem.synthetic(4000,1))
Lbb2Rem = L_p(bb2Rem.synthetic(4000,1))
Lbb3Rem = L_p(bb3Rem.synthetic(4000,1))
Lbb4Rem = L_p(bb4Rem.synthetic(4000,1))
Lbb1Full = L_p(bb1Full.synthetic(4000,1))
Lbb2Full = L_p(bb2Full.synthetic(4000,1))
Lbb3Full = L_p(bb3Full.synthetic(4000,1))
Lbb4Full = L_p(bb4Full.synthetic(4000,1))

bf1Rem = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='classic', gamma=3)
bf2Rem = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='inverse', gamma=3)
bf3Rem = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='true level', gamma=3)
bf4Rem = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='true location', gamma=3)
bf1Full = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='classic', gamma=3)
bf2Full = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='inverse', gamma=3)
bf3Full = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true level', gamma=3)
Exemplo n.º 10
0
# usually, another type of beamformer (e.g. CLEAN-SC) would be more appropriate
# to be really fast, we restrict ourselves to only 10 frequencies
# in the range 2000 - 6000 Hz (5*400 - 15*400)
#===============================================================================

f = PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \
    ind_low=5, ind_high=15)
env = Environment(c=346.04)
st = SteeringVector(grid=g, mics=m, env=env)
b = BeamformerBase(freq_data=f, steer=st, r_diag=True)

#===============================================================================
# reads the data, finds the maximum value (to properly scale the views)
#===============================================================================

map = b.synthetic(4000,1)
L1 = L_p(map)
mx = L1.max()

#===============================================================================
# print out the result integrated over an 3d-sector of the 3d map
#===============================================================================

print(L_p(b.integrate((-0.3,-0.1,0.58,-0.1,0.1,0.78)))[f.ind_low:f.ind_high])

#===============================================================================
# displays the 3d view
#===============================================================================

X,Y,Z = mgrid[g.x_min:g.x_max:1j*g.nxsteps,\
            g.y_min:g.y_max:1j*g.nysteps,\
Exemplo n.º 11
0
object_name.configure_traits()
m = MicGeom(from_file='UCA8.xml')



import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from os import path
import acoular
from acoular import L_p, Calib, MicGeom, TimeSamples, \
RectGrid, BeamformerBase, EigSpectra, BeamformerOrth, BeamformerCleansc, \
MaskedTimeSamples, FiltFiltOctave, BeamformerTimeSq, TimeAverage, \
TimeCache, BeamformerTime, TimePower, BeamformerCMF, \
BeamformerCapon, BeamformerMusic, BeamformerDamas, BeamformerClean, \
BeamformerFunctional

object_name.configure_traits()
m = MicGeom(from_file='UCA8.xml')

m = MicGeom(from_file='UCA8.xml')
g = RectGrid(x_min=-0.8, x_max=-0.2, y_min=-0.1, y_max=0.3, z=0.8, increment=0.01)
t1 = TimeSamples(name='cry_n0000001.wav')
f1 = EigSpectra(time_data=t1, block_size=256, window="Hanning", overlap='75%')
e1 = BeamformerBase(freq_data=f1, grid=g, mpos=m, r_diag=False)
fr = 4000
L1 = L_p(e1.synthetic(fr, 0))

object_name.configure_traits()
m = MicGeom(from_file='UCA8.xml')