def gen_waveform_from_coords(coords):
    '''
       Takes x-y coordinates and genrates the waveform associated with them.
       :param coords:
       :return:
       '''

    params_normalised = decoder.predict([coords])

    if params_normalised.shape[1] == 10:
        params = denormalise_batch(params_normalised, y_norm, y_mean)

    else:
        dim4_params = denormalise_batch(params_normalised, x_batch_std,
                                        x_batch_mean).numpy()

        rounding_vals = np.array([0, 1, 2, 3])
        diffs = abs(rounding_vals - dim4_params[0, 1])
        closest_index = np.argmin(diffs)
        dim4_params[0, 1] = rounding_vals[closest_index]

        params = vec_to_freqpower(dim4_params)

    waveform_length = 3200
    # gen_sine = lambda x: 0.5*gen_sine_full(x, waveform_length,32000)

    params_reshaped = np.reshape(params, (2, -1))

    # complex_waveform = np.zeros((waveform_length,))
    # for i in range(0,5):
    #    complex_waveform += gen_sine(params_reshaped[0,i])*params_reshaped[1,i]#*
    # return complex_waveform

    return gen_waveform_freq_and_power(params_reshaped, waveform_length)
def objective(**params):
    params_normalised = decoder.predict([[params['X'], params['Y']]])
    params_out = denormalise_batch(params_normalised, y_norm, y_mean)

    outval = params_out[0][0].numpy()
    if outval <= 0:
        outval = 999999999

    return outval
Beispiel #3
0
def get_synth_params(coords):
    '''take [x,y] corrdinate and return synth parameters.'''

    params_normalised = decoder.predict([coords])
    dim4_params = denormalise_batch(params_normalised, x_batch_std,
                                    x_batch_mean).numpy()

    rounding_vals = np.array([0, 1, 2, 3])
    diffs = abs(rounding_vals - dim4_params[0, 1])
    closest_index = np.argmin(diffs)
    dim4_params[0, 1] = rounding_vals[closest_index]

    params = vec_to_freqpower(dim4_params).numpy()
    return params
def objective_rms_to_peak_high_dimension_autoenc(**params):
    fund_freq = params['fund_freq']
    n_harmonics = params['n_harmonics']
    detuning_hz = params['detuning_hz']
    harmonics_power = params['harmonics_power']

    params_1d = get_freqs_powers(
        np.array([[
            fund_freq, n_harmonics, detuning_hz, harmonics_power
        ]]))  # get fundamental and powers of waveforms from the 4 params

    params_1d = np.array(
        [[fund_freq, n_harmonics, detuning_hz, harmonics_power]])

    #normalise the parameters:
    params_1d_normalised = (
        params_1d - x_batch_mean) / x_batch_std  #give this to the encoder

    xy = encoder.predict(params_1d_normalised)

    op_unnormalised = decoder.predict([xy[2]])

    recovered_vals = denormalise_batch(op_unnormalised, x_batch_mean,
                                       x_batch_std)

    freq_powers_1d = get_freqs_powers(recovered_vals)

    freq_powers_reshaped = np.reshape(freq_powers_1d, (2, -1))

    waveform_length = 3200
    waveform_out = gen_waveform_freq_and_power(freq_powers_reshaped,
                                               waveform_length)

    peak_to_rms = sound_metrics.peak_to_rms(waveform_out)
    print(
        """The peak to RMS at fund_freq=%.6f n_harmonics=%d detuning=%d harmonic power=%.4f is %.6f"""
        % (fund_freq, n_harmonics, detuning_hz, harmonics_power, peak_to_rms))
    return -peak_to_rms
Beispiel #5
0
import tensorflow as tf
import numpy as np
from data_handling import denormalise_batch

y_mean = np.array([
    1.5245759e+03, 2.2862642e+03, 2.2864233e+03, 1.5244318e+03, 0.0000000e+00,
    1.0000000e+00, 3.7491098e-01, 2.5000253e-01, 1.2500882e-01, 0.0000000e+00
])

y_norm = np.array([
    8.5161224e+02, 1.9803693e+03, 2.9146074e+03, 3.1424453e+03, 1.0000000e+00,
    1.0000000e+00, 3.3071095e-01, 3.2275078e-01, 2.6020426e-01, 1.0000000e+00
])

decoder = tf.keras.models.load_model('../models/decoder')

prediction = decoder.predict([[-3, 3]])

params_out = denormalise_batch(prediction, y_norm, y_mean)