Esempio n. 1
0
 def test_log_sweep(self):
     sweep = adsp.sweep_log(1, _fs_ / 2, 10, _fs_)
     sweep2 = adsp.sweep_log(1, _fs_ / 2, 10, _fs_)
     h = adsp.sweep2ir(sweep, sweep2)
     self.assertTrue(
         self.diff_vs_imp(h) < _tolrance_,
         'Log Sweep response is not flat!')
Esempio n. 2
0
    def __init__(self, duration, fs, f0=20, f1=20000):
        """
        Creates an object to create and process a Farina-style measurement.

        Parameters
        ----------
        duration : float
            length [seconds] of the desired measurement signal
        fs : float
            sample rate [Hz] of the measurement signal
        f0 : float
            Frequency [Hz] at which to start the measurement
        f1 : float
            Frequency [Hz] at which to end the measurement
        """
        N = int(duration * fs)
        self.fs = fs

        # create probe and inverse probe
        self.probe = adsp.sweep_log(f0, f1, duration, fs)
        R = np.log(f1 / f0)
        k = np.exp(np.arange(N) * R / N)
        self.inv_probe = np.flip(self.probe) / k

        # @TEST: test that probe convolved with inverse has flat spectrum,
        # and impulse-like response

        # determin times to look for harmonics
        self.far_response = None
        self.harm_times = [0]
        mult = 1
        while True:
            mult += 1
            delta_n = int(N * np.log(mult) / np.log(f1 / f0))
            self.harm_times.append(delta_n)
            if self.harm_times[-1] - self.harm_times[-2] < fs * 0.05:
                break
        # Direct-Form II, transposed
        y = self.z[1] + self.b[0]*x
        self.z[1] = self.z[2] + self.b[1]*x - self.fb_lambda (self.a[1],y)
        self.z[2] = self.b[2]*x - self.fb_lambda (self.a[2],y)
        return y

    def process_block (self, block):
        for n in range (len (block)):
            block[n] = self.processSample (block[n])
        return block

#%%
fs = 44100
b, a = adsp.design_LPF2 (1000, 10, fs)

sweep = adsp.sweep_log (20, 22000, 1, fs)

legend = []
freqs = np.logspace (1, 3.4, num=1000, base=20)
for g in [0.00001, 0.04, 0.2, 1.0]:
    cur_sweep = np.copy (sweep) * g
    y = np.copy (cur_sweep)

    filter = NLFeedback()
    filter.setCoefs (b, a)
    filter.fb_lambda = lambda a,x : a*np.tanh (x)
    y = filter.process_block (y)

    h = adsp.normalize (adsp.sweep2ir (cur_sweep, y))
    adsp.plot_magnitude_response (h, [1], worN=freqs, fs=fs)
 def time_log_sweep(self):
     for _ in range(_num_):
         adsp.sweep_log(1, _fs_ / 2, _dur_, _fs_)
 def setup(self):
     self.sweep = adsp.sweep_log(1, _fs_ / 2, _dur_, _fs_)
     self.sweep2 = adsp.sweep_log(1, _fs_ / 2, _dur_, _fs_)
#%%
imp = np.zeros(64)
imp[0] = 1
out = np.copy(imp)

proc = FBProc()
proc.feedback_lambda = lambda x: -0.8 * adsp.soft_clipper(x)
out = proc.process_block(out)

plt.plot(imp)
plt.plot(out)

#%%
fs = 44100
sweep = adsp.sweep_log(20, 22000, 4, fs)
y = np.copy(sweep)
y_NL = np.copy(sweep)

procLin = FBProc()
procLin.feedback_lambda = lambda x: 0.5 * (2 * x)
y = procLin.process_block(y)

procNL = FBProc()
procNL.feedback_lambda = lambda x: 0.5 * adsp.soft_clipper(2 * x)
y_NL = procNL.process_block(y_NL)

#%%
h = adsp.sweep2ir(sweep, y)
h_NL = adsp.sweep2ir(sweep, y_NL)