コード例 #1
0
def otherLagrangeInterpolation():
    sample_rate, sample = wavfile.read('songs/hakuna_matata.wav')
    x = np.array(range(0, 100))
    y = np.array(sample[5000000:5000100])

    sample_rateBAD, sampleBAD = wavfile.read(
        'songs/bad_songs/not_good_song.wav')
    sampleBAD = sampleBAD[5000000:5000100]

    BadSample = y.copy()

    dz.theEvilMethod(BadSample, 0.5, blocksize=2)
    matches = recognize.cheat(y, BadSample)
    f = lagrange(x, y)
    IwannaSee(y, BadSample, sampleBAD)
コード例 #2
0
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)
コード例 #3
0
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)
コード例 #4
0
ファイル: Interpolation1D.py プロジェクト: jpgiraldor/marconi
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)
コード例 #5
0
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)
コード例 #6
0
import damage, recognize, utils, evaluate
import numpy as np

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,
コード例 #7
0
#! /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()
コード例 #8
0
import numpy as np

from scipy.io import wavfile
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)
コード例 #9
0
#! /usr/bin/env python

from scipy.io import wavfile
from scipy.interpolate import interp1d
import damage, recognize, utils, evaluate

sample_rate, samples = wavfile.read('songs/hakuna_matata.wav')

newsamples = samples.copy()
damage.zerofill(newsamples, 0.5)
wavfile.write('songs/zerofill_hakuna_matata.wav', sample_rate, newsamples)

matches = recognize.cheat(samples, newsamples, false_negatives=0.01)
validx, validy = utils.tovalidxy(newsamples, matches)
f = interp1d(validx, validy, fill_value='extrapolate')

invalidx = utils.invalidx(matches)
fixedy = f(invalidx)

utils.replace(newsamples, invalidx, fixedy)
wavfile.write('songs/zerofill_cheat_linear_hakuna_matata.wav', sample_rate, newsamples)

evaluate.study(samples, newsamples, matches=matches)