def calibrate_signal(signal, resp, fs, frange):
    """Given original signal and recording, spits out a calibrated signal"""
    # remove dc offset from recorded response (synthesized orignal shouldn't have one)
    dc = np.mean(resp)
    resp = resp - dc

    npts = len(signal)
    f0 = np.ceil(frange[0] / (float(fs) / npts))
    f1 = np.floor(frange[1] / (float(fs) / npts))

    y = resp
    # y = y/np.amax(y) # normalize
    Y = np.fft.rfft(y)

    x = signal
    # x = x/np.amax(x) # normalize
    X = np.fft.rfft(x)

    H = Y / X

    # still issues warning because all of Y/X is executed to selected answers from
    # H = np.where(X.real!=0, Y/X, 1)
    # H[:f0].real = 1
    # H[f1:].real = 1
    # H = smooth(H)

    A = X / H

    return np.fft.irfft(A)
def calibrate_signal ( signal , resp , fs , frange ) : dc = np . mean ( resp ) resp = resp - dc npts = len ( signal ) f0 = np . ceil ( frange [ 0 ] / ( float ( fs ) / npts ) ) f1 = np . floor ( frange [ 1 ] / ( float ( fs ) / npts ) ) y = resp Y = np . fft . rfft ( y ) x = signal X = np . fft . rfft ( x ) H = Y / X A = X / H return np . fft . irfft ( A )
Given original signal and recording, spits out a calibrated signal