Exemplo n.º 1
0
def fbeamformers():
    bb = BeamformerBase(freq_data=f, steer=st, r_diag=True, cached=False)
    be = BeamformerEig(freq_data=f, steer=st, r_diag=True, n=54, cached=False)

    #frequency beamformers to test
    bbase = BeamformerBase(freq_data=f, steer=st, r_diag=True, cached=False)
    bc = BeamformerCapon(freq_data=f, steer=st, cached=False)
    beig = BeamformerEig(freq_data=f,
                         steer=st,
                         r_diag=True,
                         n=54,
                         cached=False)
    bm = BeamformerMusic(freq_data=f, steer=st, n=6, cached=False)
    bd = BeamformerDamas(beamformer=bb, n_iter=10, cached=False)
    bdp = BeamformerDamasPlus(beamformer=bb, n_iter=100, cached=False)
    bo = BeamformerOrth(beamformer=be,
                        eva_list=list(range(38, 54)),
                        cached=False)
    bs = BeamformerCleansc(freq_data=f, steer=st, r_diag=True, cached=False)
    bcmf = BeamformerCMF(freq_data=f,
                         steer=st,
                         method='LassoLarsBIC',
                         cached=False)
    bl = BeamformerClean(beamformer=bb, n_iter=10, cached=False)
    bf = BeamformerFunctional(freq_data=f,
                              steer=st,
                              r_diag=False,
                              gamma=3,
                              cached=False)
    bgib = BeamformerGIB(freq_data=f,
                         steer=st,
                         method='LassoLars',
                         n=2,
                         cached=False)
    return (bbase, bc, beig, bm, bl, bo, bs, bd, bcmf, bf, bdp, bgib)
Exemplo n.º 2
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.º 3
0
 def test_beamformer_caching(self):
     # within each subcase, we need new beamformer objects because result is not updated when
     # global_caching or cached changes
     with self.subTest("global_caching = 'none'"):
         acoular.config.global_caching = 'none'
         b0 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         b1 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         self.assertNotEqual(id(b0.result), id(b1.result))
     with self.subTest("global_caching = 'individual'"):
         acoular.config.global_caching = 'individual'
         b0 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         b1 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         self.assertEqual(id(b0.result), id(b1.result))
         b1 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=False)
         self.assertNotEqual(id(b0.result), id(b1.result))
     with self.subTest("global_caching = 'all'"):
         acoular.config.global_caching = 'all'
         b0 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         b1 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=False)
         self.assertEqual(id(b0.result), id(b1.result))
     with self.subTest("global_caching = 'readonly'"):
         acoular.config.global_caching = 'readonly'
         b0 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         b1 = BeamformerBase(freq_data=f,
                             steer=st,
                             r_diag=True,
                             cached=True)
         self.assertEqual(id(b0.result), id(b1.result))
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
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.º 6
0
csm = f.csm[:]
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
# the 3D grid (very coarse to enable fast computation for this example)
#===============================================================================

g = RectGrid3D(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.3, \
    z_min=0.48, z_max=0.88, increment=0.05)

#===============================================================================
# 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])
Exemplo n.º 8
0
#===============================================================================
# for frequency domain methods, this provides the cross spectral matrix and its
# eigenvalues and eigenvectors, if only the matrix is needed then class 
# PowerSpectra can be used instead
#===============================================================================
f = EigSpectra(time_data=t1, 
               window='Hanning', overlap='50%', block_size=128, #FFT-parameters
               ind_low=7, ind_high=15) #to save computational effort, only
               # frequencies with index 1-30 are used


#===============================================================================
# beamformers in frequency domain
#===============================================================================
bb = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04)
bd = BeamformerDamas(beamformer=bb, n_iter=100)
be = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, n=54)
bo = BeamformerOrth(beamformer=be, eva_list=list(range(38,54)))
bs = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04)
bf = BeamformerFunctional(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, gamma = 60)

#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================



fi = 1 #no of figure
for r_diag in (True,False):
    figure(fi)
Exemplo n.º 9
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)
g = RectGrid3D(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.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,
Exemplo n.º 11
0
             y_max=0.3,
             z=0.68,
             increment=0.05)

env = Environment(c=346.04)

st = SteeringVector(grid=g, mics=m, env=env)

f = PowerSpectra(
    time_data=t1,
    window='Hanning',
    overlap='50%',
    block_size=128,  #FFT-parameters
    cached=False)  #cached = False

bb = BeamformerBase(freq_data=f, steer=st, r_diag=True, cached=False)
bc = BeamformerCapon(freq_data=f, steer=st, cached=False)
be = BeamformerEig(freq_data=f, steer=st, r_diag=True, n=54, cached=False)
bm = BeamformerMusic(freq_data=f, steer=st, n=6, cached=False)
bd = BeamformerDamas(beamformer=bb, n_iter=100, cached=False)
bdp = BeamformerDamasPlus(beamformer=bb, n_iter=100, cached=False)
bo = BeamformerOrth(beamformer=be, eva_list=list(range(38, 54)), cached=False)
bs = BeamformerCleansc(freq_data=f, steer=st, r_diag=True, cached=False)
bcmf = BeamformerCMF(freq_data=f,
                     steer=st,
                     method='LassoLarsBIC',
                     cached=False)
bl = BeamformerClean(beamformer=bb, n_iter=100, cached=False)
bf = BeamformerFunctional(freq_data=f,
                          steer=st,
                          r_diag=False,
Exemplo n.º 12
0
g = RectGrid3D(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.3, \
    z_min=0.48, z_max=0.88, increment=0.05)

#===============================================================================
# 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 = 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])
from pickle import dump, load

# see example3
t = TimeSamples(name='example_data.h5')
cal = Calib(from_file='example_calib.xml')
m = MicGeom(from_file=path.join(\
    path.split(acoular.__file__)[0], 'xml', 'array_56.xml'))
g = RectGrid3D(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.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))
Exemplo n.º 14
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')
Exemplo n.º 15
0
#===============================================================================
# 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):
Exemplo n.º 16
0
f = EigSpectra(
    time_data=t1,
    window='Hanning',
    overlap='50%',
    block_size=128,  #FFT-parameters
    ind_low=1,
    ind_high=15)  #to save computational effort, only
# frequencies with index 1-30 are used

#===============================================================================
# different beamformers in frequency domain
#===============================================================================
# first, some simple delay and sum beamformers,
# but with different steering vector types
#===============================================================================
bb0 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='true level') # this is the default
bb1 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='true location') # gives better results for 3D location at low freqs.
bb2 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='classic') # classical formulation (e.g. Johnson/Dudgeon)
bb3 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='inverse') # 'inverse' formulation (e.g. Brooks 2001)

#===============================================================================
# second, the same with CleanSC
#===============================================================================
bs0 = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='true level')
bs1 = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='true location')
bs2 = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
Exemplo n.º 17
0
#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)
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
Exemplo n.º 18
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.º 19
0
# eigenvalues and eigenvectors, if only the matrix is needed then class
# PowerSpectra can be used instead
#===============================================================================
f = EigSpectra(
    time_data=t1,
    window='Hanning',
    overlap='50%',
    block_size=128,  #FFT-parameters
    ind_low=7,
    ind_high=15)  #to save computational effort, only
# frequencies with index 1-30 are used

#===============================================================================
# beamformers in frequency domain
#===============================================================================
bb = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04)
bd = BeamformerDamas(beamformer=bb, n_iter=100)
be = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, n=54)
bo = BeamformerOrth(beamformer=be, eva_list=list(range(38, 54)))
bs = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04)

#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================
fi = 1  #no of figure
for r_diag in (True, False):
    figure(fi)
    fi += 1
    bb.r_diag = r_diag
    be.r_diag = r_diag
    bs.r_diag = r_diag
Exemplo n.º 20
0
# eigenvalues and eigenvectors, if only the matrix is needed then class 
# PowerSpectra can be used instead
#===============================================================================
f = PowerSpectra(time_data=t1, 
                 window='Hanning', overlap='50%', block_size=128, #FFT-parameters
                 ind_low=8, ind_high=16) #to save computational effort, only
                   # frequencies with index 1-30 are used


#===============================================================================
# different beamformers in frequency domain
#===============================================================================
# first, some simple delay and sum beamformers, 
# but with different steering vector types
#===============================================================================
bb0 = BeamformerBase(freq_data=f, steer=st0, r_diag=True)
bb1 = BeamformerBase(freq_data=f, steer=st1, r_diag=True)
bb2 = BeamformerBase(freq_data=f, steer=st2, r_diag=True)
bb3 = BeamformerBase(freq_data=f, steer=st3, r_diag=True)

#===============================================================================
# second, the same with CleanSC
#===============================================================================
bs0 = BeamformerCleansc(freq_data=f, steer=st0, r_diag=True)
bs1 = BeamformerCleansc(freq_data=f, steer=st1, r_diag=True)
bs2 = BeamformerCleansc(freq_data=f, steer=st2, r_diag=True)
bs3 = BeamformerCleansc(freq_data=f, steer=st3, r_diag=True)


#===============================================================================
# third, caching is disabled here for BeamformerEig to save cache storage
Exemplo n.º 21
0
#===============================================================================
# the environment, i.e. medium characteristics
# (in this case, the speed of sound is set)
#===============================================================================
env = Environment(c=346.04)

# =============================================================================
# a steering vector instance. SteeringVector provides the standard freefield
# sound propagation model in the steering vectors.
# =============================================================================
st = SteeringVector(grid=g, mics=m, env=env)

#===============================================================================
# beamformers in frequency domain
#===============================================================================
bb = BeamformerBase(freq_data=f, steer=st, r_diag=True)
bd = BeamformerDamas(beamformer=bb, n_iter=100)
be = BeamformerEig(freq_data=f, steer=st, r_diag=True, n=54)
bo = BeamformerOrth(beamformer=be, eva_list=list(range(38, 54)))
bs = BeamformerCleansc(freq_data=f, steer=st, r_diag=True)

#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================
fi = 1  #no of figure
for r_diag in (True, False):
    figure(fi, (10, 6))
    fi += 1
    bb.r_diag = r_diag
    be.r_diag = r_diag
    bs.r_diag = r_diag
Exemplo n.º 22
0
# the 3D grid (very coarse to enable fast computation for this example)
#===============================================================================

g = RectGrid3D(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.3, \
    z_min=0.48, z_max=0.88, increment=0.05)

#===============================================================================
# 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(
Exemplo n.º 23
0
# eigenvalues and eigenvectors, if only the matrix is needed then class
# PowerSpectra can be used instead
#===============================================================================
f = PowerSpectra(
    time_data=t1,
    window='Hanning',
    overlap='50%',
    block_size=128,  #FFT-parameters
    ind_low=8,
    ind_high=16)  #to save computational effort, only
# frequencies with indices 8..15 are used

#===============================================================================
# different beamformers in frequency domain
#===============================================================================
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)))
bs = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04)
bcmf = BeamformerCMF(freq_data=f, grid=g, mpos=m, c=346.04, \
    method='LassoLarsBIC')
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
#===============================================================================
Exemplo n.º 24
0
# eigenvalues and eigenvectors, if only the matrix is needed then class
# PowerSpectra can be used instead
#===============================================================================
f = EigSpectra(
    time_data=t1,
    window='Hanning',
    overlap='50%',
    block_size=128,  #FFT-parameters
    ind_low=4,
    ind_high=15)  #to save computational effort, only
# frequencies with index 1-30 are used

#===============================================================================
# different beamformers in frequency domain
#===============================================================================
# first, some simple delay and sum beamformers,
# but with different steering vector types
#===============================================================================
bb0 = BeamformerBase(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='true level', cached = False) # this is the default
bs0 = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='true level', cached=False, n=200)
be0 = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, n=-1, \
    steer='true level', cached=False)
bo0 = BeamformerOrth(beamformer=be0, eva_list=range(38, 54), cached=False)

from time import time
ti = time()
map = bs0.result[:]
print time() - ti, g.size