Exemple #1
0
def get_beamformer_traj_result(Beamformer, num=32):
    """
    returns the result for a given Beamformer class
    
    Parameters
    ----------
    Beamformer : cls
        trajectory beamformer.
    num : int, optional
        number of samples to return. The default is 32.

    Returns
    -------
    array
        first block returned by the trajectory beamformers result() function.

    """
    ## with moving grid
    ts = MaskedTimeSamples(name=FNAME)
    gMoving = RectGrid(x_min=-.1,
                       x_max=.1,
                       y_min=0,
                       y_max=0,
                       z=0,
                       increment=.1)
    stMoving = SteeringVector(grid=gMoving, mics=MGEOM)
    bt = Beamformer(source=ts, trajectory=TRAJ, steer=stMoving)
    if hasattr(bt, 'n_iter'):
        bt.n_iter = 2
    return next(bt.result(num)).astype(np.float32)
Exemple #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()
Exemple #3
0
    def get_acoular_essentials(self):

        #Set the mic array geometry
        mg = MicGeom(from_file=self.array_arrngmnt)

        #Set rectangular plane and grid parameters for Acoular
        self.set_grid()
        rg = RectGrid(x_min=self.x_min_grid, x_max=self.x_max_grid, y_min=self.y_min_grid, y_max=self.y_max_grid, z=self.distance, \
            increment=self.grid_increment)

        st = SteeringVector(grid=rg, mics=mg)

        return mg, rg, st
def fbeampreparation():
    # Gradangaben von Theta im Intervall [0,180] statt wie bei DCASE [90,-90]
    M1 = spherical2cart(deg2rad(45),deg2rad(55),0.042)
    M2 = spherical2cart(deg2rad(315),deg2rad(125),0.042)
    M3 = spherical2cart(deg2rad(135),deg2rad(125),0.042)
    M4 = spherical2cart(deg2rad(225),deg2rad(55),0.042)
    mg = MicGeom()
    mg.mpos_tot = array([M1,M2,M3,M4]).T # add microphone positions to MicGeom object
    
    # define evaluation grid
    rg = SphericalGrid_Equiangular(NPOINTS_AZI, NPOINTS_ELE)
    st = SteeringVector(grid=rg, mics=mg)
    
    if DEBUG:
        firstframe = STARTFRAME
        lastframe = ENDFRAME
    else:
        firstframe = 0
        lastframe = 600
    
    return mg, rg, st, firstframe, lastframe
Exemple #5
0
    block_size=128,  #FFT-parameters
    ind_low=8,
    ind_high=16)  #to save computational effort, only
# frequencies with index 1-30 are used

#===============================================================================
# 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):
Exemple #6
0
invalid = [1, 7]  # list of invalid channels (unwanted microphones etc.)
t1.invalid_channels = invalid
t1.calib = Calib(from_file=calibfile)
m = MicGeom(from_file=micgeofile)
m.invalid_channels = invalid

g = RectGrid(x_min=-0.6,
             x_max=-0.0,
             y_min=-0.3,
             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)
Exemple #7
0
M2 = spherical2cart(deg2rad(315), deg2rad(125), 0.042)
M3 = spherical2cart(deg2rad(135), deg2rad(125), 0.042)
M4 = spherical2cart(deg2rad(225), deg2rad(55), 0.042)

mg = MicGeom()
mg.mpos_tot = array([M1, M2, M3,
                     M4]).T  # add microphone positions to MicGeom object

# define evaluation grid
# Hier könntest du vielleicht eine neue Spherical Grid Klasse schreiben oder
# eine ArbitraryGrid Klasse, damit wir ein sinnvolles Gitter zur Lokalisierung
# verwenden können.
# Als Anregung siehe: https://spaudiopy.readthedocs.io/en/latest/spaudiopy.grids.html
#
rg = SphericalGrid_Equiangular(NPOINTS_AZI, NPOINTS_ELE)
st = SteeringVector(grid=rg, mics=mg)

# analyze the data and generate map
name = AUDIO_DIR + TRACK
ts = WavSamples(name=name, start=STARTFRAME * NUM, stop=ENDFRAME * NUM)
bf = BeamformerTime(source=ts, steer=st)
#ft = FiltFiltOctave(source=bf,band=4000)
tp = TimePower(source=bf)
tavg = TimeAverage(source=tp, naverage=NUM)

# =============================================================================
# plot first data block
# =============================================================================
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
               z_max=0.36,
               increment=0.02)

#===============================================================================
# The following provides the cross spectral matrix and defines the CLEAN-SC beamformer.
# 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=pa,
                 window='Hanning',
                 overlap='50%',
                 block_size=128,
                 ind_low=5,
                 ind_high=16)
st = SteeringVector(grid=g, mics=m, steer_type='true location')
b = BeamformerCleansc(freq_data=f, steer=st)

#===============================================================================
# Calculate the result for 4 kHz octave band
#===============================================================================

map = b.synthetic(4000, 1)

#===============================================================================
# Display views of setup and result.
# For each view, the values along the repsective axis are summed.
# Note that, while Acoular uses a left-oriented coordinate system,
# for display purposes, the z-axis is inverted, plotting the data in
# a right-oriented coordinate system.
#===============================================================================
Exemple #9
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)

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
Exemple #10
0
 (SlotJet(), "obj.origin = array((1., 0., 0.))"),
 #    "SlotJet.flow item assignment": (SlotJet(), "obj.flow[0] = 0."),
 "SlotJet.flow array assignment": (SlotJet(),
                                   "obj.flow = array((0., 0., 0.))"),
 #    "SlotJet.plane item assignment": (SlotJet(), "obj.plane[0] = 1."),
 "SlotJet.plane array assignment": (SlotJet(),
                                    "obj.plane = array((1., 0., 0.))"),
 #    "OpenJet.origin item assignment": (OpenJet(), "obj.origin[0] = 1."),
 "OpenJet.origin array assignment": (OpenJet(),
                                     "obj.origin = array((1., 0., 0.))"),
 #    "RotatingFlow.origin item assignment": (RotatingFlow(), "obj.origin[0] = 1."),
 "RotatingFlow.origin array assignment":
 (RotatingFlow(), "obj.origin = array((1., 0., 0.))"),
 #fbeamform.py
 #    "SteeringVector.ref item assignment": (SteeringVector(), "obj.ref[0] = 1."),
 "SteeringVector.ref array assignment": (SteeringVector(),
                                         "obj.ref = array((1., 1., 1.))"),
 #    "BeamformerOrth.eva_list item assignment": (BeamformerOrth(eva_list=array((0, 1))), "obj.eva_list[0] = 2"),
 "BeamformerOrth.eva_list array assignment":
 (BeamformerOrth(eva_list=array((0, 1))), "obj.eva_list = array((2))"),
 #grids.py
 "MergeGrid.grids item assignment": (MergeGrid(grids=[RectGrid()]),
                                     "obj.grids[0] = RectGrid()"),
 "MergeGrid.grids list assignment": (MergeGrid(),
                                     "obj.grids = [RectGrid()]"),
 # signals.py
 #    "FiltWNoiseGenerator.ar item assignment": (FiltWNoiseGenerator(ar=[1.,2.,3.]), "obj.ar[0] = 0."),
 "FiltWNoiseGenerator.ar array assignment":
 (FiltWNoiseGenerator(ar=[1., 2., 3.]), "obj.ar = array((0., 0., 0.))"),
 #    "FiltWNoiseGenerator.ma item assignment": (FiltWNoiseGenerator(ma=[1.,2.,3.]), "obj.ma[0] = 0."),
 "FiltWNoiseGenerator.mar array assignment":
Exemple #11
0
#===============================================================================
g = RectGrid3D(x_min=-0.6, x_max=+0.0, y_min=0.0, y_max=0.0, \
    z_min=0.3, z_max=0.9, increment=0.05)


#===============================================================================
# the environment, i.e. medium characteristics
# (in this case, the speed of sound is set)
#===============================================================================
env = Environment(c = 346.04)

# =============================================================================
# a steering vector instance for different steering vector types. SteeringVector 
# provides the standard freefield sound propagation model in the steering vectors.
# =============================================================================
st0 = SteeringVector(grid=g, mics=m, env=env, \
    steer_type='true level')  # this is the default
st1 = SteeringVector(grid=g, mics=m, env=env, \
    steer_type='true location')  # gives better results for 3D location at low freqs.
st2 = SteeringVector(grid=g, mics=m, env=env, \
    steer_type='classic')  # classical formulation (e.g. Johnson/Dudgeon)
st3 = SteeringVector(grid=g, mics=m, env=env, \
    steer_type='inverse')  # 'inverse' formulation (e.g. Brooks 2001)


#===============================================================================
# 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 = PowerSpectra(time_data=t1, 
                 window='Hanning', overlap='50%', block_size=128, #FFT-parameters
Exemple #12
0
               z_max=0.36,
               increment=0.02)

#===============================================================================
# The following provides the cross spectral matrix and defines the CLEAN-SC beamformer.
# 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=pa,
                 window='Hanning',
                 overlap='50%',
                 block_size=128,
                 ind_low=5,
                 ind_high=16)
st = SteeringVector(grid=g, mics=m, steer_type='true level')
b = BeamformerCleansc(freq_data=f, steer=st)

#===============================================================================
# Calculate the result for 4 kHz octave band
#===============================================================================

map = b.synthetic(4000, 1)

#===============================================================================
# Display views of setup and result.
# For each view, the values along the repsective axis are summed.
# Note that, while Acoular uses a left-oriented coordinate system,
# for display purposes, the z-axis is inverted, plotting the data in
# a right-oriented coordinate system.
#===============================================================================