pySoundToolbox.py
def genArrayResponseFunc(angles, antennaPositions=np.array([[0.113, -0.036, -0.076, -0.113], [0.0, 0.0, 0.0, 0.0]]), frequencies=1, amplitudes=1, phaseShifts=0, noiseStd=0):
    """
    Generates an array response function.

    @param angles 1-D numpy array with angles of the sources in rad
    @param antennaPositions positions of the antennas to an abitrary origin as numpy array
    @param frequenies numpy array or float with the frequencies of the sound sources in Hz
    @param amplitudes numpy array or float with the amplitude of the sound source signals
    @param phaseShifts numpy array or float with the phaseShifts of the sound source sinals
    @param noiseStd standard deviation of the white noise present (0 means no noise)
    @return array response function with parameter t. t is numpy array, a row represents the response of one microphone
    """
    # Amount of antennas
    antennaNum = antennaPositions.shape[1]

    # Convert signal parameters to array, to keep signal generation easy

    if np.isscalar(angles):
        angles = np.array([angles], dtype=np.float128)
    # Amount of sources
    sourcesNum = angles.shape[0]

    if np.isscalar(frequencies):
        frequencies = np.ones(sourcesNum, dtype=np.float128) * frequencies
    if np.isscalar(phaseShifts):
        phaseShifts = np.ones(sourcesNum, dtype=np.float128) * phaseShifts
    if np.isscalar(amplitudes):
        amplitudes = np.ones(sourcesNum, dtype=np.float128) * amplitudes

    # Generate source signals
    sourceSignals = []
    for i in range(angles.shape[0]):
        sourceSignals.append(genSine(frequency=frequencies[i], amplitude=amplitudes[i], phaseShift=phaseShifts[i]))

    # Create steering matrix
    # A row is the mapping of all sources to one microphone
    # A column is the mapping of one source to all microphones
    speedOfSound = 343.2 # m/s
    steeringMat = np.matrix(np.empty((antennaNum, sourcesNum), dtype=np.complex256))
    for i in range(sourcesNum):
        doa = np.array([np.cos(angles[i]), np.sin(angles[i])]) # Normalized direction of arrival
        for k in range(antennaNum):
            delay = antennaPositions[:, k].dot(doa) / speedOfSound
            steeringMat[k, i] = np.exp(-1j * 2 * np.pi * frequencies[i] * delay)

    def func(t):
        """
        Array response function.

        @param t time, which needs to be a float or a numpy array with times
        @return a numpy array with the elongation of the wave at times t.
            A row represents one microphone within the array.
        """
        if type(t) != np.ndarray:
            t = np.array([t])

        data = np.matrix(np.empty((antennaNum, t.shape[0]), dtype=np.complex))
        for i in range(t.shape[0]):
            sourceData = np.matrix([[sourceSignals[k](t[i])] for k in range(sourcesNum)], dtype=np.complex256)
            noise = 0
            if noiseStd != 0:
                noise = np.matrix(np.random.normal(size=antennaNum, scale=noiseStd), dtype=np.complex256).transpose()\
                    + 1j * np.matrix(np.random.normal(size=antennaNum, scale=noiseStd), dtype=np.complex256).transpose()
            data[:, i] = steeringMat * sourceData + noise

        return data

    return func

    Generates an array response function.

    @param angles 1-D numpy array with angles of the sources in rad
    @param antennaPositions positions of the antennas to an abitrary origin as numpy array
    @param frequenies numpy array or float with the frequencies of the sound sources in Hz
    @param amplitudes numpy array or float with the amplitude of the sound source signals
    @param phaseShifts numpy array or float with the phaseShifts of the sound source sinals
    @param noiseStd standard deviation of the white noise present (0 means no noise)
    @return array response function with parameter t. t is numpy array, a row represents the response of one microphone
    
Generates an array response function.
Generates an array response function .
def genArrayResponseFunc(angles, antennaPositions=np.array([[0.113, -0.036, -0.076, -0.113], [0.0, 0.0, 0.0, 0.0]]), frequencies=1, amplitudes=1, phaseShifts=0, noiseStd=0):
    antennaNum = antennaPositions.shape[1]
    if np.isscalar(angles):
        angles = np.array([angles], dtype=np.float128)
    sourcesNum = angles.shape[0]
    if np.isscalar(frequencies):
        frequencies = np.ones(sourcesNum, dtype=np.float128) * frequencies
    if np.isscalar(phaseShifts):
        phaseShifts = np.ones(sourcesNum, dtype=np.float128) * phaseShifts
    if np.isscalar(amplitudes):
        amplitudes = np.ones(sourcesNum, dtype=np.float128) * amplitudes
    sourceSignals = []
    for i in range(angles.shape[0]):
        sourceSignals.append(genSine(frequency=frequencies[i], amplitude=amplitudes[i], phaseShift=phaseShifts[i]))
    speedOfSound = 343.2 
    steeringMat = np.matrix(np.empty((antennaNum, sourcesNum), dtype=np.complex256))
    for i in range(sourcesNum):
        doa = np.array([np.cos(angles[i]), np.sin(angles[i])]) 
        for k in range(antennaNum):
            delay = antennaPositions[:, k].dot(doa) / speedOfSound
            steeringMat[k, i] = np.exp(-1j * 2 * np.pi * frequencies[i] * delay)
    def func(t):
        if type(t) != np.ndarray:
            t = np.array([t])
        data = np.matrix(np.empty((antennaNum, t.shape[0]), dtype=np.complex))
        for i in range(t.shape[0]):
            sourceData = np.matrix([[sourceSignals[k](t[i])] for k in range(sourcesNum)], dtype=np.complex256)
            noise = 0
            if noiseStd != 0:
                noise = np.matrix(np.random.normal(size=antennaNum, scale=noiseStd), dtype=np.complex256).transpose()\
                    + 1j * np.matrix(np.random.normal(size=antennaNum, scale=noiseStd), dtype=np.complex256).transpose()
            data[:, i] = steeringMat * sourceData + noise
        return data
    return func
def genArrayResponseFunc ( angles , antennaPositions = np . array ( [ [ 0.113 , - 0.036 , - 0.076 , - 0.113 ] , [ 0.0 , 0.0 , 0.0 , 0.0 ] ] ) , frequencies = 1 , amplitudes = 1 , phaseShifts = 0 , noiseStd = 0 ) : antennaNum = antennaPositions . shape [ 1 ] if np . isscalar ( angles ) : angles = np . array ( [ angles ] , dtype = np . float128 ) sourcesNum = angles . shape [ 0 ] if np . isscalar ( frequencies ) : frequencies = np . ones ( sourcesNum , dtype = np . float128 ) * frequencies if np . isscalar ( phaseShifts ) : phaseShifts = np . ones ( sourcesNum , dtype = np . float128 ) * phaseShifts if np . isscalar ( amplitudes ) : amplitudes = np . ones ( sourcesNum , dtype = np . float128 ) * amplitudes sourceSignals = [ ] for i in range ( angles . shape [ 0 ] ) : sourceSignals . append ( genSine ( frequency = frequencies [ i ] , amplitude = amplitudes [ i ] , phaseShift = phaseShifts [ i ] ) ) speedOfSound = 343.2 steeringMat = np . matrix ( np . empty ( ( antennaNum , sourcesNum ) , dtype = np . complex256 ) ) for i in range ( sourcesNum ) : doa = np . array ( [ np . cos ( angles [ i ] ) , np . sin ( angles [ i ] ) ] ) for k in range ( antennaNum ) : delay = antennaPositions [ : , k ] . dot ( doa ) / speedOfSound steeringMat [ k , i ] = np . exp ( - 1j * 2 * np . pi * frequencies [ i ] * delay ) def func ( t ) : """
        Array response function.

        @param t time, which needs to be a float or a numpy array with times
        @return a numpy array with the elongation of the wave at times t.
            A row represents one microphone within the array.
        """ if type ( t ) != np . ndarray : t = np . array ( [ t ] ) data = np . matrix ( np . empty ( ( antennaNum , t . shape [ 0 ] ) , dtype = np . complex ) ) for i in range ( t . shape [ 0 ] ) : sourceData = np . matrix ( [ [ sourceSignals [ k ] ( t [ i ] ) ] for k in range ( sourcesNum ) ] , dtype = np . complex256 ) noise = 0 if noiseStd != 0 : noise = np . matrix ( np . random . normal ( size = antennaNum , scale = noiseStd ) , dtype = np . complex256 ) . transpose ( ) + 1j * np . matrix ( np . random . normal ( size = antennaNum , scale = noiseStd ) , dtype = np . complex256 ) . transpose ( ) data [ : , i ] = steeringMat * sourceData + noise return data return func
Generates an array response function.
Generates an array response function .
"""
    Generates an array response function.

    @param angles 1-D numpy array with angles of the sources in rad
    @param antennaPositions positions of the antennas to an abitrary origin as numpy array
    @param frequenies numpy array or float with the frequencies of the sound sources in Hz
    @param amplitudes numpy array or float with the amplitude of the sound source signals
    @param phaseShifts numpy array or float with the phaseShifts of the sound source sinals
    @param noiseStd standard deviation of the white noise present (0 means no noise)
    @return array response function with parameter t. t is numpy array, a row represents the response of one microphone
    """ # Amount of antennas # Convert signal parameters to array, to keep signal generation easy # Amount of sources # Generate source signals # Create steering matrix # A row is the mapping of all sources to one microphone # A column is the mapping of one source to all microphones # m/s # Normalized direction of arrival """
        Array response function.

        @param t time, which needs to be a float or a numpy array with times
        @return a numpy array with the elongation of the wave at times t.
            A row represents one microphone within the array.
        """
angles
antennaPositions
frequencies
amplitudes
phaseShifts
noiseStd