def test_hysteresis(self): freq = 100 n = np.arange(_N_) x = np.sin(2 * np.pi * n * freq / _FS_) * (n / _N_) hysteresis = adsp.Hysteresis(1.0, 1.0, 1.0, _FS_, mode='RK4') y = hysteresis.process_block(x) hysteresis2 = adsp.Hysteresis(1.0, 1.0, 1.0, _FS_, mode='RK2') y2 = hysteresis2.process_block(x) hysteresis3 = adsp.Hysteresis(1.0, 1.0, 1.0, _FS_, mode='NR10') y3 = hysteresis3.process_block(x) self.assertTrue( np.sum(np.abs(y - y2)) / _N_ < 5.0e-6, 'RK2 Hysteresis response is incorrect!') self.assertTrue( np.sum(np.abs(y - y3)) / _N_ < 5.0e-6, 'NR10 Hysteresis response is incorrect!')
# %% # look at file idx = 4 plt.plot(clean_data[idx]) # %% hyst_data = [] drive_data = [] sat_data = [] width_data = [] for x in tqdm(clean_data): drive = np.random.uniform() sat = np.random.uniform() width = np.random.uniform() hyst = adsp.Hysteresis(drive, sat, width, FS, mode='RK4') y = hyst.process_block(x) drive_data.append(np.ones_like(x) * drive) sat_data.append(np.ones_like(x) * sat) width_data.append(np.ones_like(x) * width) hyst_data.append(y.astype(np.float32)) # %% idx = 4 plt.figure() plt.plot(clean_data[idx]) plt.plot(hyst_data[idx]) plt.plot(drive_data[idx]) plt.plot(sat_data[idx]) plt.plot(width_data[idx])
# %% # look at file idx = 8 plt.plot(clean_data[idx]) # %% hyst_data = [] drive_data = [] sat_data = [] width_data = [] for i, x in tqdm(enumerate(clean_data)): fs = 1.0 / fs_data[i][0] drive = np.random.uniform() sat = np.random.uniform() width = np.random.uniform() hyst = adsp.Hysteresis(drive, sat, width, fs, dAlpha=0.95, mode='RK4') y = hyst.process_block(x) drive_data.append(np.ones_like(x) * drive) sat_data.append(np.ones_like(x) * sat) width_data.append(np.ones_like(x) * width) hyst_data.append(y.astype(np.float32)) # %% idx = 4 plt.figure() plt.plot(clean_data[idx]) plt.plot(hyst_data[idx]) plt.figure() freqs, x_fft = plot_fft(clean_data[idx], 1.0 / fs_data[idx][0])
clean_data.append(x) clean_data = np.asarray(clean_data) print(np.shape(clean_data)) # %% # look at file idx = 4 plt.plot(clean_data[idx]) # %% hyst_data = [] drive_data = [] for x in tqdm(clean_data): drive = random.choice([0.05, 0.25, 0.5, 0.75, 1.0]) hyst = adsp.Hysteresis(drive, 1.0, 1.0, FS, mode='RK4') y = hyst.process_block(x) drive_data.append(np.ones_like(x) * drive) hyst_data.append(y.astype(np.float32)) # %% idx = 4 plt.figure() plt.plot(clean_data[idx]) plt.plot(hyst_data[idx]) plt.plot(drive_data[idx]) plt.figure() freqs, x_fft = plot_fft(clean_data[idx], FS) freqs, y_fft = plot_fft(hyst_data[idx], FS)
clean_data.append(x) clean_data = np.asarray(clean_data) # print(np.shape(clean_data)) # %% # look at file idx = 4 plt.plot(clean_data[idx]) # %% NUM_FILES = len(clean_data) hyst_data = [] for i, x in tqdm(enumerate(clean_data)): fs = 1.0 / fs_data[i][0] hyst = adsp.Hysteresis(1.0, 1.0, 1.0, fs, mode='RK4') y = hyst.process_block(x) hyst_data.append(y.astype(np.float32)) # %% idx = 4 plt.figure() plt.plot(clean_data[idx]) plt.plot(hyst_data[idx]) plt.figure() freqs, x_fft = plot_fft(clean_data[idx], 1.0 / fs_data[idx][0]) freqs, y_fft = plot_fft(hyst_data[idx], 1.0 / fs_data[idx][0]) plt.semilogx(freqs, x_fft) plt.semilogx(freqs, y_fft)
# %% from audio_dspy.hysteresis import Hysteresis import numpy as np import matplotlib.pyplot as plt import audio_dspy as adsp FS = 96000 # %% # drive plot WIDTH = 1.0 SAT = 0.5 legend = [] for DRIVE in [0.0, 0.25, 1.0]: hyst = adsp.Hysteresis(DRIVE, SAT, WIDTH, FS, mode='NR4') adsp.plot_dynamic_curve(hyst.process_block, freq=10, fs=FS, gain=3, num=10000) legend.append(f'Drive = {DRIVE}') plt.legend(legend) plt.grid() plt.title('Hysteresis Drive') plt.tight_layout() plt.savefig('drive.png') # %% # saturation plot WIDTH = 1.0 DRIVE= 1.0 legend = [] for SAT in [0.0, 0.4, 0.8]: