Пример #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)
Пример #2
0
from pylab import figure, subplot, imshow, show, colorbar, title, tight_layout

# files
datafile = 'example_data.h5'
calibfile = 'example_calib.xml'
micgeofile = path.join(path.split(acoular.__file__)[0], 'xml', 'array_56.xml')

#octave band of interest
cfreq = 4000

#===============================================================================
# first, we define the time samples using the MaskedTimeSamples class
# alternatively we could use the TimeSamples class that provides no masking
# of channels and samples
#===============================================================================
t1 = MaskedTimeSamples(name=datafile)
t1.start = 0  # first sample, default
t1.stop = 16000  # last valid sample = 15999
invalid = [1, 7]  # list of invalid channels (unwanted microphones etc.)
t1.invalid_channels = invalid

#===============================================================================
# calibration is usually needed and can be set directly at the TimeSamples
# object (preferred) or for frequency domain processing at the PowerSpectra
# object (for backwards compatibility)
#===============================================================================
t1.calib = Calib(from_file=calibfile)

#===============================================================================
# the microphone geometry must have the same number of valid channels as the
# TimeSamples object has
Пример #3
0
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)
f = PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \
    ind_low=1,ind_high=30)
g = RectGrid(x_min=0 - .2,
             x_max=0.3,
             y_min=-0.13,
             y_max=0.3,
             z=0,
             increment=0.05)
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)
Пример #4
0
RectGrid, BeamformerBase, BeamformerEig, BeamformerOrth, BeamformerCleansc, \
MaskedTimeSamples, FiltFiltOctave, BeamformerTimeSq, TimeAverage, \
TimeCache, BeamformerTime, TimePower, BeamformerCMF, \
BeamformerCapon, BeamformerMusic, BeamformerDamas, BeamformerClean, \
BeamformerFunctional
from numpy import zeros
from os import path
from pylab import figure, subplot, imshow, show, colorbar, title

dataFile = 'example_data.h5'
calibFile = 'example_calib.xml'
micGeoFile = path.join(path.split(acoular.__file__)[0], 'xml', 'array_56.xml')

freqInt = 4000

t1 = MaskedTimeSamples(name = dataFile)
t1.start = 0
t1.stop = 16000
invalid = [1, 7]
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)

f = EigSpectra(time_data = t1,
        window = 'Hanning', overlap = '50%', block_size = 128,
Пример #5
0
from cPickle import dump

# files
datafile = 'example_data.h5'
calibfile = 'example_calib.xml'
micgeofile = path.join( path.split(acoular.__file__)[0],'xml','array_56.xml')

#octave band of interest
cfreq = 4000

#===============================================================================
# first, we define the time samples using the MaskedTimeSamples class
# alternatively we could use the TimeSamples class that provides no masking
# of channels and samples
#===============================================================================
t1 = MaskedTimeSamples(name=datafile)
t1.start = 0 # first sample, default
t1.stop = 16000 # last valid sample = 15999
invalid = [1,7] # list of invalid channels (unwanted microphones etc.)
t1.invalid_channels = invalid 

#===============================================================================
# calibration is usually needed and can be set directly at the TimeSamples 
# object (preferred) or for frequency domain processing at the PowerSpectra 
# object (for backwards compatibility)
#===============================================================================
t1.calib = Calib(from_file=calibfile)

#===============================================================================
# the microphone geometry must have the same number of valid channels as the
# TimeSamples object has
Пример #6
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
This example shows the different behaviour of SampleSplitter class  
when the maximum size of a block buffer is reached
"""

from acoular import TimePower, MaskedTimeSamples, SampleSplitter
import threading
from time import sleep

samples = 25000
h5savefile = 'example_data.h5'
ts = MaskedTimeSamples(name=h5savefile, start=0, stop=samples)

# set up Sample Splitter
ss = SampleSplitter(source=ts)

tp1 = TimePower(source=ss)
tp2 = TimePower(source=ss)
ss.register_object(tp1, tp2)  # register objects


def print_number_of_blocks_in_block_buffers():
    buffers = list(ss.block_buffer.values())
    elements = [len(buf) for buf in buffers]
    print(dict(zip(['tp1', 'tp2'], elements)))


def do_stuff1(obj):  #
    for i in obj.result(2048):
Пример #7
0
#==============================================================================

# # 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)
btSq_ps_h5 = BeamformerTimeSq(source=mt1, grid=g, mpos=m, r_diag=True, c=c0)

avgt_ps = TimeAverage(source=bt_ps, naverage=int(sfreq * tmax / 2))
avgt_psSq = TimeAverage(source=btSq_ps, naverage=int(sfreq * tmax / 2))
avgt_ps_h5 = TimeAverage(source=bt_ps_h5, naverage=int(sfreq * tmax / 2))
avgt_psSq_h5 = TimeAverage(source=btSq_ps_h5, naverage=int(sfreq * tmax / 2))
Пример #8
0
 (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":
 (FiltWNoiseGenerator(ma=[1., 2., 3.]), "obj.ma = array((0., 0., 0.))"),
 #sources.py
 "MaskedTimeSamples.invalid_channels item assignment":
 (MaskedTimeSamples(invalid_channels=[1]), "obj.invalid_channels[0] = 0"),
 "MaskedTimeSamples.invalid_channels list assignment":
 (MaskedTimeSamples(), "obj.invalid_channels = [0]"),
 #    "SphericalHarmonicSource.alpha item assignment": (SphericalHarmonicSource(alpha=array((0, 1))), "obj.alpha[0] = 1."),
 "SphericalHarmonicSource.alpha array assignment":
 (SphericalHarmonicSource(alpha=array((0, 1))),
  "obj.alpha = array((1., 1., 1.))"),
 #    "UncorrelatedNoiseSource.seed item assignment": (UncorrelatedNoiseSource(seed=array((1, 2))), "obj.seed[0] = 3"),
 "UncorrelatedNoiseSource.seed array assignment":
 (UncorrelatedNoiseSource(seed=array((1, 2))), "obj.seed = array((3,4))"),
 "SourceMixer.sources item assignment":
 (SourceMixer(sources=[SamplesGenerator()]),
  "obj.sources[0] = PointSource()"),
 "SourceMixer.sources list assignment": (SourceMixer(
     sources=[SamplesGenerator()]), "obj.sources = [PointSource()]"),
 # tbeamform.py
Пример #9
0
BeamformerFunctional

# other imports
from numpy import zeros
from os import path
from pylab import figure, subplot, imshow, show, colorbar, title, tight_layout

# files
datafile = 'sammy.csv'
#calibfile = 'example_calib.xml'
micgeofile = path.join(path.split(acoular.__file__)[0], 'xml', 'array_64.xml')

#octave band of interest
cfreq = 4000

t1 = MaskedTimeSamples(name=datafile)
t1.start = 0
t1.stop = 16000
invalid = [1, 7]
t1.invalid_channels = invalid

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)
f = PowerSpectra(time_data=t1,
                 window='Hanning',