Ejemplo n.º 1
0
def get_sql_sources(cursor, sources_id, sfreq, mpos):
    # sources_id -> id für eine Quellkartierung mit bestimmten Quellen
    # source_id -> id jeder einzelnen source
    # source ids -> liste aller ids der einzelnen sources einer sources id
    source_ids = fetchall(cursor, get_source_ids, sources_id)
    cursor.execute(sq(get_ap, 1))
    (ap) = cursor.fetchone()
    sourcelist = []  # list
    for source_id in source_ids:
        cursor.execute(
            sq(get_source, sources_id,
               source_id))  # get the source parameters one after the other
        (signal_id, x1, x2, x3, pol_type, dipole_id, p_rms) = cursor.fetchone()
        # generate harmonic or noise source...
        sgnl = WNoiseGenerator(rms=p_rms,
                               sample_freq=sfreq,
                               numsamples=512000,
                               seed=(signal_id - 1))
        #    newsrc = PointSource(signal = sgnl,
        #                         mpos = m_error,
        #                         loc = (x1*ap, x2*ap, x3*ap))
        newsrc = PointSource(signal=sgnl,
                             mpos=mpos,
                             loc=(x1 * ap[0], x2 * ap[0], x3 * ap[0]))
        sourcelist.append(newsrc)  # add the new source to the list
    if len(source_ids
           ) > 1:  # if there are multiple sources, they have to be mixed
        src = Mixer(source=sourcelist[0], sources=sourcelist[1:])
    else:  # if there's only one source, it is the only one in the list
        src = sourcelist[0]
    return src
Ejemplo 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()
Ejemplo n.º 3
0
PointSource, MovingPointSource, SineGenerator, WNoiseGenerator, Mixer, WriteWAV

from pylab import subplot, imshow, show, colorbar, plot, transpose, figure, \
psd, axis, xlim, ylim, title, tight_layout, text

freq = 48000
sfreq = freq / 2  #sampling frequency
duration = 1
nsamples = freq * duration
datafile = 'cry_n0000001.wav'
micgeofile = path.join(path.split(bpath)[0], 'xml', 'array_64_8mic.xml')
h5savefile = 'cry_n0000001.wav'
m = MicGeom(from_file=micgeofile)
n = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=1)  #1pascal
p = PointSource(signal=n, mpos=m, loc=(-0.1, -0.1, 0.3))
p1 = Mixer(source=p)
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
Ejemplo n.º 4
0
# 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, 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')
Ejemplo n.º 5
0
    long = int
nsamples = long(sfreq * tmax)
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 the moving source and one fixed source
#===============================================================================

p0 = MovingPointSource(signal=s1, mpos=m, trajectory=tr1)
#t = p0 # use only moving source
p1 = PointSource(signal=n1, mpos=m, loc=(0, R, Z))
t = Mixer(source=p0, sources=[
    p1,
])  # mix both signals
#t = p1 # use only fix source

# 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,
Ejemplo n.º 6
0
    #    "ChannelMixer.weights item assignment" : (ChannelMixer(weights=[[1.,2.,3.]]), "obj.weights[0] = 0."),
    "ChannelMixer.weights new array assignment": (ChannelMixer(
        weights=[[1., 2., 3.]]), "obj.weights = array([0.])"),
    #    "SpatialInterpolator.Q item assignment": (SpatialInterpolator(), "obj.Q[0] = 0."),
    "SpatialInterpolator.Q array assignment":
    (SpatialInterpolator(),
     "obj.Q = array([[0.,0.,0.],[0.,0.,0.],[0.,0.,0.]])"),
    #    "SpatialInterpolatorRotation.Q item assignment": (SpatialInterpolatorRotation(), "obj.Q[0] = 0."),
    "SpatialInterpolatorRotation.Q array assignment":
    (SpatialInterpolatorRotation(),
     "obj.Q = array([[0.,0.,0.],[0.,0.,0.],[0.,0.,0.]])"),
    #    "SpatialInterpolatorConstantRotation.Q item assignment": (SpatialInterpolatorConstantRotation(), "obj.Q[0] = 0."),
    "SpatialInterpolatorConstantRotation.Q array assignment":
    (SpatialInterpolatorConstantRotation(),
     "obj.Q = array([[0.,0.,0.],[0.,0.,0.],[0.,0.,0.]])"),
    "Mixer.sources item assignment": (Mixer(sources=[SamplesGenerator()]),
                                      "obj.sources[0] = SamplesGenerator()"),
    "Mixer.sources list assignment": (Mixer(sources=[SamplesGenerator()]),
                                      "obj.sources = [SamplesGenerator()]"),
    "WriteWAV.channels item assignment": (WriteWAV(channels=[1]),
                                          "obj.channels[0] = 0"),
    "WriteWAV.channels list assignment": (WriteWAV(), "obj.channels = [0]"),
}


class Test_DigestChange(TestCase):
    """Test that ensures that digest of Acoular classes changes correctly on 
    changes of CArray and List attributes.
    """
    def get_digests(self, obj, statement):
        """A function that collects the digest of the obj before (d1) and
Ejemplo n.º 7
0
num_single_sound_data = 100  # 单声源训练集数目
m = MicGeom(from_file=micgeofile)

# 设置声源位置信息和声压强度
# n2 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=2, rms=0.7)
# n3 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, seed=3, rms=0.5)
for i in range(num_single_sound_data):
    print(i)
    [Rms] = np.around(np.random.random(1), 2)
    n1 = WNoiseGenerator(sample_freq=sfreq, numsamples=nsamples, rms=Rms)
    # 随机产生0-1的数作为声源坐标并进行四舍五入操作
    [source_x, source_y] = np.dot(np.around(np.random.random(2), 2), 3) - 1.5
    p1 = PointSource(signal=n1, mpos=m, loc=(source_x, source_y, 2.5))
    # p2 = PointSource(signal=n2, mpos=m,  loc=(0.15,0,0.3))
    # p3 = PointSource(signal=n3, mpos=m,  loc=(0,0.1,0.3))
    # p = Mixer(source = p1, sources = [p2])
    p = Mixer(source=p1)
    # 保存文件名
    os.makedirs(
        '/home3/zengwh/VoiceRec/data/compute/100000_data/Val/one_source',
        exist_ok=True)
    h5savefile = '/home3/zengwh/VoiceRec/data/compute/100000_data/Val/one_source/x_{:.2f}_y_{:.2f}_rms_{:.2f}_sources.h5'.format(
        source_x, source_y, Rms)
    wh5 = WriteH5(source=p, name=h5savefile)
    #print(wh5)
    wh5.save()
    h5 = h5py.File(h5savefile)
    h5 = h5['time_data'][::50, :]
    os.system("rm {}".format(h5savefile))
    np.save(h5savefile[:-2] + 'npy', h5)