Esempio n. 1
0
def test_tf_prep():

    pd = polarData.fromPkl(filename)

    mic = Microphone(pd, (50, 100))

    mic.polar[30].plot(both=True)

    mic.self_apply_xy()

    mic.polar[30].plot(both=True)

    angles, freqs, data = mic.tf_prep()

    print(angles)
    print(freqs)
    print(data)

    angles = tf.constant(angles)
    freqs = tf.constant(freqs)
    data = tf.constant(data)

    print(angles)
    print(freqs)
    print(data)
Esempio n. 2
0
def test_xy():
    filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15/spv1840.pkl"
    pd = polarData.fromPkl(filename)

    pd.plotAngle(90)

    # position in mm
    mic = Microphone(pd, [-500, 2000])

    fs = 44.1e3
    length = 100000
    n = np.arange(length)

    f_targ = (fs / length) * 4000  # (2pi/ T)*k
    # f_targ_2 = 2300

    sin_wave_1 = np.sin(n * (2 * np.pi) * (f_targ / fs))
    # sin_wave_2 = np.sin(n*(2*np.pi)*(f_targ_2/fs))
    sin_wave = audioSample(sin_wave_1, type="t", Fs=fs)

    pad = 10000
    # sin_wave.hanning()
    sin_wave.zeroPadStart(pad)
    sin_wave.zeroPadEnd(pad)

    sin_wave.plot(both=True)

    for theta in range(0, 20, 15):
        sin_shifted = mic.apply_xy(sin_wave, theta)

        sin_shifted.plot(both=True)
Esempio n. 3
0
def simulate_polar_array():

    filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15/spv1840.pkl"
    pd = polarData.fromPkl(filename)

    fs = 44.1e3
    length = 100000
    n = np.arange(10000)
    f_options = np.int32(np.logspace(2, 4, 4)) * 2 * (fs / length)

    # pd.plotAngle(90)

    f_1 = f_options[0]
    f_2 = f_options[2]
    c = 343e3
    d_1 = c / (2 * f_1)
    d_2 = c / (2 * f_2)

    # position in mm
    mic_1 = Microphone(pd, [0, 0])
    mic_2 = Microphone(pd, [d_1, 0])
    mic_3 = Microphone(pd, [0, d_2])

    mic_array = MicrophoneArray([mic_1, mic_2])
    # mic_array = MicrophoneArray([mic_1, mic_2, mic_3])

    plt.figure(2)

    for f_test in f_options:

        sin_wave = np.sin(n * (2 * np.pi) * (f_test / fs))
        sin_wave = 2 / length * audioSample(sin_wave, type="t", Fs=fs)
        # sin_wave.hanning()

        thetas = np.array(list(range(0, 361, 2)))
        mags = []

        for theta in thetas:

            print(f_test, theta)

            result = mic_array.apply(sin_wave, theta)

            # sin_wave.plot(both=True)
            # result.plot(both=True)

            # get magnitude of the closest frequency of the result
            result.toDb()
            mags.append(result.getFreq([f_test])[0].real)

        plt.polar(thetas * np.pi / 180, mags)

    plt.legend(f_options, loc="upper left")
    mic_array.visualize()
Esempio n. 4
0
def pd_convert():
    """
    Conversion of polarData object to objects compatible 
    compatible with TensorFlow
    """

    
    filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15_fixedpkls/spv1840.pkl" 
    pd = polarData.fromPkl(filename)

    print(pd.toTF().shape)
Esempio n. 5
0
def simulate_polar_1mic():

    filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15/spv1840.pkl"
    pd = polarData.fromPkl(filename)

    pd.plotAngle(0, both=True)

    # position in mm
    mic = Microphone(pd, [-500, 2000])

    fs = 44.1e3
    length = 100000
    n = np.arange(10000)
    f_options = np.int32(np.logspace(2, 4, 6)) * 2 * (fs / length)

    plt.figure(1)

    for f_test in f_options:

        sin_wave = np.sin(n * (2 * np.pi) * (f_test / fs))
        sin_wave = audioSample(sin_wave, type="t", Fs=fs)
        # sin_wave.hanning()

        thetas = np.array(list(range(0, 361, 1)))
        mags = []

        for theta in thetas:

            print(f_test, theta)

            result = mic.apply(sin_wave, theta)

            # sin_wave.plot(both=True)
            # result.plot(both=True)

            # get magnitude of the closest frequency of the result
            result.toDb()
            mags.append(result.getFreq([f_test])[0].real)

        plt.polar(thetas * np.pi / 180, mags)

    plt.title("RESULT")
    plt.legend(np.int32(f_options), loc="upper left")
    pd.plotFreqs(f_options, fig=2)
Esempio n. 6
0
def test_apply_filter():
    """
    Application of a zpk filter to a polarData object
    """

    
    filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15_fixedpkls/spv1840.pkl" 
    pd = polarData.fromPkl(filename)
    filt = ZPKOptimizableFilter(num_zeros=2,num_poles=1)
    worN = len(pd[0].f()) # number of frequencies
    fs = pd[0].fs
    filt_freqz = filt.freqz(worN, fs) # frequency response, audioSample object

    filt_freqz.plot(both=True, fig=3, show=False, figtitle="Filter")

    pd.setType("f")

    test_frequencies = ([100,1000,1240, 10000])
    pd.plotFreqs(test_frequencies, fig=1, show=False, title="BEFORE")
    pd.applyFilter(filt_freqz)
    pd.plotFreqs(test_frequencies, fig=2, show=True, title="AFTER")
Esempio n. 7
0
from pythonAudioMeasurements.microphoneArray import MicrophoneArray
from pyAudioFilter.polar_optimizer import PolarOptimizer


# use to help with GPU tensorflow warnings of you
# have not configured or don't have a GPU
tf.config.set_visible_devices([], 'GPU')


# ------------------------------------------------------------------------------------------
# SET-UP
# ------------------------------------------------------------------------------------------

# load in a microphone
filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15_fixedpkls/spv1840.pkl" 
pd = polarData.fromPkl(filename)

# set specific locations for the mics
locations = [(0,0), (100,200), (-100, 200), (-100,-200), (100,-200)]

# alternate method of generating mics randomly in a box of a specified width
num_mics = 20
box_width = 600 # mm
locations = box_width*np.random.rand(num_mics,2) # comment to use set microphone locations

# create a microphone array
mic_array =  MicrophoneArray([Microphone(pd, loc) for loc in locations])

# look at where the microphones visualize array geometry
mic_array.visualize()
import pickle
from pythonAudioMeasurements.audioSample import audioSample
from pythonAudioMeasurements.polarData import polarData

filename = "/home/terrasa/UROP/polar-measurement/data/19_Jan15_fixedpkls/spv1840.pkl"
filename_2 = "/home/terrasa/UROP/polar-measurement/data/19_Jan15/spv1840.pkl"


with open(filename, "rb") as this_file:
    # should be a dictionary
    raw_load = pickle.load(this_file)

test_samp = raw_load["measurements"][5]
print(test_samp)
as_asamp = audioSample(test_samp[0], test_samp[1], test_samp[2])
print(as_asamp)


as_asamp.plot(both=True)


pd = polarData.fromPkl(filename)
pd_2 = polarData.fromPkl(filename_2, pickleAsAudioSample=True)

pd.plotFreqs([400, 1000])
pd_2.plotFreqs([400, 1000])