示例#1
0
def main():
    wave_data, wave_params = read_wave_data(IN_FILENAME)

    fft_util = FftUtil(1024)

    freq_domain_data = fft_util.analysis(wave_data)
    plot_spectrogram(freq_domain_data, wave_params.framerate, 'Unaltered freq domain data')
    
    spectrogram_data = reduce_to_spectrogram_data(freq_domain_data)
    plot_spectrogram(spectrogram_data, wave_params.framerate, "Spectrogram data")
        
    expanded_spectrogram_data = expand_from_spectrogram_data(spectrogram_data)
    plot_spectrogram(expanded_spectrogram_data, wave_params.framerate, "Expanded spectrogram data")

    lg_freq_domain, lg_signal = lim_griffen_reconstruction(spectrogram_data, wave_params)
    plot_spectrogram(lg_freq_domain, wave_params.framerate, "Lim Griffen reconstruction")

    reconverted_audio = fft_util.resynthesis(freq_domain_data)
    reconverted_spectrogram_data = fft_util.resynthesis(expanded_spectrogram_data)

    write_wave_data(OUT_FILENAME, reconverted_spectrogram_data, wave_params)
    print("L2-norm of original audio and resynthesis of unmodified data: ", 
          np.linalg.norm(wave_data - reconverted_audio))
    print("L2-norm of original audio and resynthesis of spectrogram_data data: ", 
          np.linalg.norm(wave_data - reconverted_spectrogram_data))
    print("L2-norm of original audio and lim griffen reconstruction: ",
          np.linalg.norm(wave_data - lg_signal))

    plot_comparison(wave_data, lg_signal)
示例#2
0
def lim_griffen_reconstruction(spectrogram_data, wave_params):
    magnitude_data = expand_from_spectrogram_data(spectrogram_data)
    half_window = spectrogram_data.shape[1]-1
    fft_util = FftUtil(half_window * 2)
    length_of_audio = (magnitude_data.shape[0] + 1) * half_window
    output_signal = np.random.rand(length_of_audio)
    for i in range(101):
        output_freq_domain = fft_util.analysis(output_signal)
        output_signal = fft_util.resynthesis(magnitude_data *
                                             np.exp(np.angle(output_freq_domain) * 1j))
        if i % 10 == 0:
            output_filename = "iter_" + str(i) + ".wav"
            write_wave_data(output_filename, output_signal, wave_params)
    return (output_freq_domain, output_signal)
示例#3
0
def test_analysis_resynthesis():
    fft_util = FftUtil(1024)
    wave_data, wave_params = read_wave_data(IN_FILENAME)
    complex_data = fft_util.analysis(wave_data)
    output = fft_util.resynthesis(complex_data)
    write_wave_data(OUT_FILENAME, output, wave_params)