示例#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)
示例#2
0
    def do_beamforming(self, mic_data):
        """ Beamforming using Acoular """
        mg, rg, st = self.get_acoular_essentials()

        count = 0
        #Divide audio samples as per frame rate (10fps) and do beamforming
        for s_time in tqdm(
                np.arange(self.start_time, self.end_time, self.interval)):

            audio_data = mic_data[:,
                                  int(s_time *
                                      self.sample_rate):int((s_time +
                                                             self.interval) *
                                                            self.sample_rate)]
            audio_data = np.transpose(audio_data)

            if audio_data.shape[0] == 0:
                continue

            #Acoular needs audio input through .h5 file
            target_file = self.outfile + '/temp.h5'

            if os.path.exists(target_file):
                os.remove(target_file)

            with h5py.File(target_file, 'w') as data_file:
                data_file.create_dataset('time_data', data=audio_data)
                data_file['time_data'].attrs.__setitem__(
                    'sample_freq', self.sample_rate)

            #.h5 file has issues with closing. Change 'ulimit' if not working

            ts = TimeSamples(name=target_file)
            ps = PowerSpectra(time_data=ts,
                              block_size=128,
                              window='Hanning',
                              overlap='50%')
            bb = BeamformerEig(freq_data=ps, steer=st)

            pm = bb.synthetic(self.freq_query, self.octave_band)
            Lm = L_p(pm)

            if count == 0:
                bf_data = np.zeros(
                    (Lm.shape[0], Lm.shape[1],
                     len(
                         np.arange(self.start_time, self.end_time,
                                   self.interval))))
                bf_data[:, :, count] = Lm
            else:
                bf_data[:, :, count] = Lm

            count += 1

        # remove temp.h5 file after its finished
        os.remove(target_file)

        return bf_data, rg
示例#3
0
def audio_csv_extraction(filepath, trackname, st, firstframe):

    if DETAILEDINFO_LVL >= 3:
        print('[Azimuth, Elevation], max_value')

    ts = WavSamples(name=filepath,start=firstframe*NUM,stop=(firstframe+1)*NUM)
    ps = PowerSpectra(time_data=ts, block_size=512, window='Hanning')
    be = BeamformerEig(freq_data=ps, steer=st, r_diag=True, n=3)


    # be = BeamformerBase(freq_data=ps, steer=st, r_diag=True)

    # bb = BeamformerBase(freq_data=ps, steer=st)
    # bo = BeamformerOrth(beamformer=be, eva_list=[3])
    
# Extraktion von Framenummer (Spalte 0), Geräuschklasse (Spalte 1), Azi (Spalte 3) und Ele (Spalte 4) aus .csv-Datei
    csvpath = CSV_DIR+trackname+".csv"
    rawdata = loadtxt(open(csvpath, "rb"), dtype="int32", delimiter=",", usecols=(0,1,3,4))


    if TRAINING or JUST_1SOURCE_FRAMES:
        labeldata = rawdata = rm_2sources_frames(rawdata)


    if THRESHOLD_FILTER:
        soundpressure = zeros((600,1))
        
    ## Sound Pressure Level ##
        wavsamples = WavSamples(name = filepath).data[:,3]
        for frameindex, _ in enumerate(soundpressure[:,0]):
            soundpressure[frameindex,0] = sum(wavsamples[frameindex*NUM:(frameindex+1)*NUM]**2)/NUM
        spl = L_p(soundpressure[:,0])
    ##########################

        threshold = threshold_calculator(spl)

    ## Liste der per Threshold gefilterten Frames ##
        active_frames = []
        for index, frame in enumerate(spl):
            if frame > threshold:
                active_frames.append(index)
    ################################################
        # active_frames weiterhin eine Liste, aus der man Elemente
        # auch zwischendrin löschen kann
        # thrdata = array(active_frames).reshape((len(active_frames),1))

        thrdata = []
        for ind, frame in enumerate(rawdata[:,0]):
            if frame in active_frames:
                thrdata.append(rawdata[ind,:])
            
        labeldata = array(thrdata)

    if not(TRAINING or THRESHOLD_FILTER):
        labeldata = rawdata


    return ts, be, labeldata
示例#4
0
#===============================================================================
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
#===============================================================================
figure(1, (10, 6))
i1 = 1  #no of subplot
示例#5
0
# (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
    i1 = 1  #no of subplot
    for steer in ('true level', 'true location', 'classic', 'inverse'):
示例#6
0
             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,
                          gamma=4,
                          cached=False)
示例#7
0
#===============================================================================
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
    i1 = 1  #no of subplot
    for steer in ('true level', 'true location', 'classic', 'inverse'):
                           steer='true level')
bca4Full = BeamformerCapon(freq_data=f,
                           grid=g,
                           mpos=m,
                           r_diag=False,
                           c=346.04,
                           steer='true location')
Lbca1Full = L_p(bca1Full.synthetic(4000, 1))
Lbca2Full = L_p(bca2Full.synthetic(4000, 1))
Lbca3Full = L_p(bca3Full.synthetic(4000, 1))
Lbca4Full = L_p(bca4Full.synthetic(4000, 1))

be1Rem = BeamformerEig(freq_data=f,
                       grid=g,
                       mpos=m,
                       r_diag=True,
                       c=346.04,
                       steer='classic',
                       n=12)
be2Rem = BeamformerEig(freq_data=f,
                       grid=g,
                       mpos=m,
                       r_diag=True,
                       c=346.04,
                       steer='inverse',
                       n=12)
be3Rem = BeamformerEig(freq_data=f,
                       grid=g,
                       mpos=m,
                       r_diag=True,
                       c=346.04,
Lbf4Rem = L_p(bf4Rem.synthetic(4000,1))
Lbf1Full = L_p(bf1Full.synthetic(4000,1))
Lbf2Full = L_p(bf2Full.synthetic(4000,1))
Lbf3Full = L_p(bf3Full.synthetic(4000,1))
Lbf4Full = L_p(bf4Full.synthetic(4000,1))

bca1Full = BeamformerCapon(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='classic')
bca2Full = BeamformerCapon(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='inverse')
bca3Full = BeamformerCapon(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true level')
bca4Full = BeamformerCapon(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true location')
Lbca1Full = L_p(bca1Full.synthetic(4000,1))
Lbca2Full = L_p(bca2Full.synthetic(4000,1))
Lbca3Full = L_p(bca3Full.synthetic(4000,1))
Lbca4Full = L_p(bca4Full.synthetic(4000,1))

be1Rem = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='classic', n=12)
be2Rem = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='inverse', n=12)
be3Rem = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='true level', n=12)
be4Rem = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, steer='true location', n=12)
be1Full = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='classic', n=12)
be2Full = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='inverse', n=12)
be3Full = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true level', n=12)
be4Full = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=False, c=346.04, steer='true location', n=12)
Lbe1Rem = L_p(be1Rem.synthetic(4000,1))
Lbe2Rem = L_p(be2Rem.synthetic(4000,1))
Lbe3Rem = L_p(be3Rem.synthetic(4000,1))
Lbe4Rem = L_p(be4Rem.synthetic(4000,1))
Lbe1Full = L_p(be1Full.synthetic(4000,1))
Lbe2Full = L_p(be2Full.synthetic(4000,1))
Lbe3Full = L_p(be3Full.synthetic(4000,1))
Lbe4Full = L_p(be4Full.synthetic(4000,1))
x = rg.gpos[0]
y = rg.gpos[1]
z = rg.gpos[2]

summed_azi_x = 0.0
summed_azi_y = 0.0
summed_ele = 0.0
summed_max_v = 0.0
print('[Azimuth, Elevation], max_value')

st = SteeringVector(grid=rg, mics=mg)
ts = WavSamples(name=name, start=STARTFRAME * NUM, stop=(STARTFRAME + 1) * NUM)
ps = PowerSpectra(time_data=ts, block_size=512, window='Hanning')
# bb = BeamformerBase(freq_data=ps, steer=st)

be = BeamformerEig(freq_data=ps, steer=st, r_diag=True, n=3)
# bo = BeamformerOrth(beamformer=be, eva_list=[3])

##################### DeepLearning-Matrix ##########################
################   Elevation    Azimuth      Frequenzbänder  Frames
DL_Matrix = zeros((NPOINTS_ELE, NPOINTS_AZI, len(FREQBANDS), FRAMES))
# Wenn .npz, dann keine FRAMES, weil die in einzelne .npy-Tabellen?!
# DL_Matrix = zeros((NPOINTS_ELE, NPOINTS_AZI, len(FREQBANDS)))

for frame_index, frame in enumerate(range(STARTFRAME, ENDFRAME)):
    print('### FRAME: ', frame - STARTFRAME, ' (', frame, ') ###')
    for freq_index, freq in enumerate(FREQBANDS):
        print('FREQ =', freq)
        ts.start = frame * NUM
        ts.stop = (frame + 1) * NUM
示例#11
0
# 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, \
    steer='classic')
bs3 = BeamformerCleansc(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, \
    steer='inverse')

#===============================================================================
# third, caching is disabled here for BeamformerEig to save cache storage
# (the results are not needed anyway, exept one time for BeamformerOrth)
#===============================================================================
be = BeamformerEig(freq_data=f, grid=g, mpos=m, r_diag=True, c=346.04, n=-1, \
    cached=False)
bo = BeamformerOrth(beamformer=be, eva_list=range(38, 54))

#===============================================================================
# save all beamformers in an external file
# important: import dump from cPickle !!!
#===============================================================================
all_bf = (bb0, bb1, bb2, bb3, bs0, bs1, bs2, bs3, bo)
fi = open('all_bf.sav', 'w')
dump(all_bf, fi, -1)  # uses newest pickle protocol -1 (default = 0)
fi.close()

#===============================================================================
# plot result maps for different beamformers in frequency domain
#===============================================================================
figure(1)
示例#12
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)
    suptitle('Old Implementation | R_diag=' + str(r_diag))
    fi +=1 
示例#13
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
示例#14
0
    3. Für alle eine Skalierung

'''

FRAME = 275

# Use Folder with 1 Audiofile
WAVFILE = listdir(SINGLE_FILE_TEST)[0]
WAVDIR = SINGLE_FILE_TEST + '/' + WAVFILE

mg, rg, st, _, _ = fbeampreparation()


ts = WavSamples(name=WAVDIR,start=FRAME*NUM,stop=(FRAME+1)*NUM)
ps = PowerSpectra(time_data=ts, block_size=512, window='Hanning')
be = BeamformerEig(freq_data=ps, steer=st, r_diag=True, n=3)

csvpath = CSV_DIR+WAVFILE[:-4]+".csv"
csvdata = loadtxt(open(csvpath, "rb"), dtype="int32", delimiter=",", usecols=(0,3,4))
fr_index = where(csvdata[:,0]==FRAME)[0][0]
if csvdata[fr_index+1,0] != FRAME:
    print("Im ausgewählten Frame ist nur 1 Quelle aktiv (nicht 2).")
    sys.exit()
Src1_AziEle = csvdata[fr_index,1:3]
Src2_AziEle = csvdata[fr_index+1,1:3]

Src1_Matrix = zeros((NPOINTS_ELE, NPOINTS_AZI, len(FREQBANDS)), dtype="float32")
Src2_Matrix = zeros((NPOINTS_ELE, NPOINTS_AZI, len(FREQBANDS)), dtype="float32")

# Opt 1
maxval1 = zeros(len(FREQBANDS))