Example #1
0
import acoular
from pylab import figure, plot, imshow, colorbar, show,xlim, ylim,legend,cm
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon,Rectangle

#fft block size
block = 128

#example data 
micgeofile = path.join( path.split(acoular.__file__)[0],'xml','array_56.xml')
mg = acoular.MicGeom( from_file=micgeofile )
ts = acoular.TimeSamples( name='example_data.h5' )
ps = acoular.PowerSpectra( time_data=ts, block_size=128, window='Hanning' )
rg = acoular.RectGrid(x_min=-0.6, x_max=-0.0, y_min=-0.3, y_max=0.3, z=0.68,
             increment=0.02)
st = acoular.SteeringVector( grid = rg, mics=mg )
f = acoular.PowerSpectra(time_data=ts,block_size=block)
bf  = acoular.BeamformerBase(freq_data = f,steer= st)


#Integrate function can deal with multiple methods for integration:

#1. a circle containing of three values: x-center, y-center and radius
circle = array([-0.3,-0.1, 0.05])

#2. a rektange containing of 4 values: lower corner(x1, y1) and upper corner(x2, y2).
rect  =  array([-0.5,   -0.15, -0.4 , 0.15])

#3. a polygon containing of vector tuples: x1,y1,x2,y2,...,xi,yi
poly = array([ -0.25, -0.1, -0.1, -0.1, -0.1, -0.2, -0.2, -0.25, -0.3, -0.2])
t = ac.Mixer(source = p0, sources = [p1,])

# Saving 32 channel wav

# ww = ac.WriteWAV(source = t)
# ww.channels = [0,32]
# ww.save

##################### Frequency beamforming fixed focus ######################

fi = ac.PowerSpectra(time_data=t, window='Hanning', overlap='50%', block_size=128, \
    ind_low=1,ind_high=15) # CSM calculation 
g = ac.RectGrid(x_min=-2, x_max=+2, y_min=0, y_max=+4, z=5, increment=0.1)

st = ac.SteeringVector(grid=g, mics=m)
b = ac.BeamformerBase(freq_data=fi, steer=st)
map1 = b.synthetic(f,3)

mx = ac.L_p(map1.max())
plot.figure()
plot.imshow(ac.L_p(np.transpose(map1)), vmax=mx, vmin=mx-5, interpolation='bilinear',\
        extent=g.extend(), origin='lower')
plot.colorbar()

##################### Time beamforming moving focus ##########################

fi = ac.FiltFiltOctave(source=t, band=f, fraction='Third octave')
g = ac.RectGrid(x_min=-2.0, x_max=+2.0, y_min=0.0, y_max=+4.0, z=0.0, \
    increment=0.1)# grid point of origin is at trajectory (thus z=0)
st = ac.SteeringVector(grid=g, mics=m)