def test_delay_feedback_gain(self): g = adsp.delay_feedback_gain_for_t60(1, _fs_, _t60_) x = adsp.impulse(_N_) for n in range(1, _N_): x[n] = x[n-1] * g t60_samp = int(_fs_ * _t60_) self.assertTrue(np.abs(x[t60_samp] - 0.001) < _tolerance_, 'Incorrect T60 gain! Expected: {}, Actual: {}'.format(0.001, x[t60_samp]))
def generate_modal_signal(amps, freqs, taus, num_modes, N, fs, fs_measure=None): """ Generates a modal signal from modal model information Parameters ---------- amps : array-like The complex amplitudes of the modes freqs : array-like The frequencies of the modes [Hz] taus : array-like The decay rates of the modes [gain/sample] num_modes : int The number of modes N : int The length of the signal to generates [samples] fs : float The sample rate fs_measure: float, optional The sample rate at which the measurements at which the decay rates were measured. To use the same value as fs, set to "None" """ assert num_modes == len(amps), 'Incorrect number of amplitudes' assert num_modes == len(freqs), 'Incorrect number of frequencies' assert num_modes == len(taus), 'Incorrect number of decay rates' filts = [] for n in range(num_modes): b, a = design_modal_filter(amps[n], freqs[n], taus[n], fs, fs_measure=fs_measure) filts.append([b, a]) imp = adsp.impulse(N) y = np.zeros(N) for n in range(num_modes): b = filts[n][0] a = filts[n][1] y += signal.lfilter(b, a, imp) return adsp.normalize(y)
def test_prony(self): imp = adsp.impulse(_N_) b, a = adsp.design_lowshelf(10000, 2, 2, _fs_) x = signal.lfilter(b, a, imp) bp, ap = adsp.prony(x, 2, 2) _, H = signal.freqz(b, a, fs=_fs_) _, Hp = signal.freqz(bp, ap, fs=_fs_) H = adsp.normalize(H) Hp = adsp.normalize(Hp) diffs = 0 for n, _ in enumerate(H): diffs += np.abs(np.abs(H[n]) - np.abs(Hp[n])) error = diffs / len(H) self.assertTrue(error < _tolerance_, 'Error: {}'.format(error))
def setUp(self): self.h = adsp.impulse(_N_) self.worN = np.logspace(1, 3.3, num=1000, base=20)
from matplotlib import ticker # %% mode_data = np.loadtxt('hydroflask_water_modes.csv', dtype=np.complex_) sixteenth_full = mode_data[4] freqs = sixteenth_full[:40].astype(float) taus = sixteenth_full[40:80].astype(float) * 1.8 amps = sixteenth_full[80:] FS = 48000 N = int(3 * FS) # x = adsp.generate_modal_signal(amps, freqs, taus, len(amps), int(3 * FS), FS) # %% imp = adsp.impulse(N) x = np.zeros(N) for n in range(len(amps)): if n < 5: freq_osc = freqs[n] * 0.1 * np.sin( 2 * np.pi * 1.5 * np.arange(N) / FS) * 0.99996**np.arange(N) filt = adsp.Filter(2, FS) for k in range(N): b, a = adsp.design_modal_filter(amps[n], freqs[n] + freq_osc[k], taus[n], FS, fs_measure=FS) filt.set_coefs(b, a)