def akimaInterpolation(): sample_rate, sample = wavfile.read('songs/hakuna_matata.wav') sample = sample[5000000:5000100] sample_rateBAD, sampleBAD = wavfile.read( 'songs/bad_songs/not_good_song.wav') sampleBAD = sampleBAD[5000000:5000100] BadSample = sample.copy() dz.theEvilMethod(BadSample, 0.5) matches = recognize.cheat(sample, BadSample) x, y = utils.tovalidxy(BadSample, matches) f = Akima1DInterpolator(x, y) IwannaSee(sample, BadSample, sampleBAD)
def cubicSplineInterpolation(): sample_rate, sample = wavfile.read('songs/hakuna_matata.wav') BadSample = sample.copy() dz.theEvilMethod(BadSample, 0.5) matches = recognize.cheat(sample, BadSample) x, y = utils.tovalidxy(BadSample, matches) f = InterpolatedUnivariateSpline(x, y) xNotValid = utils.invalidx(matches) fixedy = f(xNotValid) utils.replace(BadSample, xNotValid, fixedy) wavfile.write('songs/generator_song/regen_splineUnivariate_song.wav', sample_rate, BadSample)
def cubitInterpolation1D(): sample_rate, sample = wavfile.read('songs/hakuna_matata.wav') BadSample = sample.copy() dz.theEvilMethod(BadSample, 0.5) wavfile.write('songs/bad_songs/not_good_song.wav', sample_rate, BadSample) matches = recognize.cheat(sample, BadSample) x, y = utils.tovalidxy(BadSample, matches) f = interp1d(x, y, kind='cubic', fill_value='extrapolate') xNotValid = utils.invalidx(matches) fixedy = f(xNotValid) utils.replace(BadSample, xNotValid, fixedy) wavfile.write('songs/generator_song/regen_sinOriginal_song.wav', sample_rate, BadSample)
def lagrangeInterpolation(): sample_rate, sample = wavfile.read('songs/hakuna_matata.wav') sample = sample[5000000:5000100] sample_rateBAD, sampleBAD = wavfile.read( 'songs/bad_songs/not_good_song.wav') sampleBAD = sampleBAD[5000000:5000100] BadSample = sample.copy() dz.theEvilMethod(BadSample, 0.7) matches = recognize.cheat(sample, BadSample) x, y = utils.tovalidxy(BadSample, matches) f = BarycentricInterpolator(x, y) utils.repair(BadSample, matches, f) IwannaSee(sample, BadSample, sampleBAD)
sample_rate, samples = wavfile.read('songs/hakuna_matata.wav') samples = samples[1000000:2000000] fp = [0, 0.05, 0.1, 0.2, 0.3] fn = [0, 0.05, 0.1, 0.2, 0.3] print('zerofill') for p in fp: for n in fn: newsamples = samples.copy() damage.zerofill(newsamples, 0.4) matches = recognize.cheat(samples, newsamples, false_positives=p, false_negatives=n) validx, validy = utils.tovalidxy(newsamples, matches) f = interp1d(validx, validy, kind='cubic', fill_value='extrapolate') invalidx = utils.invalidx(matches) fixedy = f(invalidx) utils.replace(newsamples, invalidx, fixedy) print('fp:', p, 'fn:', n, 'mean:', np.mean(evaluate.abserrors(samples, newsamples))) print('noiseadd') for p in fp: for n in fn: newsamples = samples.copy() damage.noiseadd(newsamples, 0.6, rate=0.3) matches = recognize.cheat(samples, newsamples, false_positives=p,
#! /usr/bin/env python from scipy.io import wavfile from interpolate import NewtonInterpolator import damage, recognize, utils sample_rate, samples = wavfile.read('songs/hakuna_matata.wav') samples = samples[5000000:5000100] newsamples = samples.copy() damage.zerofill(newsamples, 0.3) matches = recognize.cheat(samples, newsamples) x, y = utils.tovalidxy(newsamples, matches) f = NewtonInterpolator(x, y) utils.repair(newsamples, matches, f) import matplotlib.pyplot as plt plt.title('Newton interpolation') plt.xlabel('Frame') plt.ylabel('Amplitude') plt.plot(samples, label='real') plt.plot(newsamples, label='interpolated') plt.legend(loc='best') plt.show()
from scipy.interpolate import interp1d from sklearn.linear_model import LinearRegression from sklearn.preprocessing import PolynomialFeatures from sklearn.metrics import mean_squared_error, r2_score from sklearn.metrics import accuracy_score samplerate, samples = wavfile.read('canciones/hakuna_matata.wav') samples = samples[5000000:5000100] newsamples = samples.copy() damage.noiseadd(newsamples, 0.7, 0.3) matches = recognize.cheat(samples, newsamples, false_positives=0.04, false_negatives=0.1) matchesSD = recognize.cheat(samples, samples, false_positives=0.04, false_negatives=0.1) x, y = utils.tovalidxy(newsamples, matches) xSD, ySD = utils.tovalidxy(samples, matchesSD) x = np.array(x).reshape((-1, 1)) y = np.array(y) xSD = np.array(xSD).reshape((-1, 1)) ySD = np.array(ySD) xP, yP, xSD, ySD = utils.partir(x, y, xSD, ySD, 10) polynomial_features = PolynomialFeatures(degree=10) y_poly_pred = utils.polinomialR(xP, yP, ySD, polynomial_features) utils.plotting(xP, yP, samples, y_poly_pred)