Ejemplo n.º 1
0
def play_rnn_OLA(model, path, n, win, format='rov', args=None, translation=True, lpf=True):
    net = model(*args)
    net.load_state_dict(torch.load(path))

    x = net.generate(1, n).detach().squeeze().numpy()
    
    x = iflatten_complex_data_with(x, 31)
    x = pad_data_zeros(x, get_single_side_frequency().shape[0])
    x = ifft_data(x)
    x = iwindow(x, win + 0.001, 0.9)
    x = istandardize_data(x)

    x = overlap_and_add_data(x)
    if lpf:
        x = low_pass_filter(x)

    write_one_file('example', x, format=format)

    cmd = CMD + PAR1 + 'example' + PAR2
    if translation:
        cmd += TRANSLATION

    os.system(cmd)

    return x
Ejemplo n.º 2
0
    def example(self):
        # Generate an example with numpy array data type
        x = self.generate(1).detach().cpu()
        x = np.array(x)
        x = iflatten_complex_data_with(x, 16)
        x = pad_data_zeros(x, get_single_side_frequency().shape[0])
        x = ifft_data(x)
        # x = iwindow(x, WIN, 0.8)

        return x[0]
Ejemplo n.º 3
0
def sqrt_spectra(examples):
    n = examples[0].shape[0]
    freq = get_single_side_frequency(n)

    spectras = []
    fe = fft_data(examples)
    for e in fe:
        spectras.append((freq, np.absolute(e)))

    return spectras
Ejemplo n.º 4
0
def log_spectra(examples):
    n = examples[0].shape[0]
    freq = get_single_side_frequency(n)

    spectras = []
    fe = fft_data(examples)
    for e in fe:
        m = np.amax(np.absolute(e))
        spectras.append((freq, 20 * np.log10(np.absolute(e) / m)))

    return spectras
Ejemplo n.º 5
0
    def example(self, r):
        # Generate an example with numpy array data type
        global dim
        x = self.generate(1, r).detach().cpu()
        x = x.squeeze().unsqueeze(0)
        x = np.array(x)
        x = iflatten_complex_data_with(x, 31)
        x = pad_data_zeros(x, get_single_side_frequency().shape[0])
        x = ifft_data(x)
        # x = iwindow(x, WIN, 0.8)

        return x[0]
Ejemplo n.º 6
0
def lpf_dimension_reduction(data, frequency, trim_length=None):
    if trim_length is None:
        trim_length = config.TRIM_LENGTH

    bins = data[0].shape[0]
    freq = get_single_side_frequency(trim_length)

    idx = freq <= frequency
    dim = np.sum(idx)

    data_reducted = []
    for d in data:
        data_reducted.append(d[idx])

    return data_reducted, dim
Ejemplo n.º 7
0
def _draw(i):
    global AX1
    global AX2
    global AX3
    global AX4
    global FIGURE
    global QUEUE
    global DATA

    if not QUEUE.empty():
        DATA = QUEUE.get()

        if DATA == 'close':
            plt.close(FIGURE)
            return

        example_length = DATA['example'].shape[0]
        freq = get_single_side_frequency(example_length)
        # DATA['loss_title'] = data['loss_title']
        # DATA['losses'].append(data['loss']),
        # DATA['loss_labels'] = data['loss_labels']
        # DATA['score_title'] = data['score_title']
        # DATA['scores'].append(data['score'])
        # DATA['score_labels'] = data['score_labels']
        # DATA['interval'] = data['interval']
        n = len(DATA['losses'])
        interval = DATA['interval']

        x = np.arange(interval, interval * n + 1, interval)
        loss_Y = np.array(DATA['losses']).T
        score_Y = np.array(DATA['scores']).T

        AX1.clear()
        AX2.clear()
        AX3.clear()
        AX4.clear()

        AX1.set_title(DATA['loss_title'])
        AX1.set_xlabel('Training Steps')
        AX1.set_ylabel('Model Loss')

        for i in range(loss_Y.shape[0]):
            AX1.plot(x, loss_Y[i].flatten(), label=DATA['loss_labels'][i])
        AX1.legend()

        AX2.set_title(DATA['score_title'])
        AX2.set_xlabel('Training Steps')
        AX2.set_ylabel('Score')

        for i in range(score_Y.shape[0]):
            AX2.plot(x, score_Y[i].flatten(), label=DATA['score_labels'][i])
        AX2.legend()

        AX3.set_title('Spectra')
        AX3.set_xlabel('Frequency')
        AX3.set_ylabel('Power (dB)')

        example = DATA['example']

        spectra = np.absolute(fft_data([DATA['example']])[0]).real
        m = np.amax(spectra)
        spectra = 20 * np.log10(spectra / m)
        AX3.plot(freq, spectra)

        AX4.set_title('Example')
        AX4.set_xlabel('Time')
        AX4.set_ylabel('Axis')

        AX4.plot(example.real)

    return