def test_Slaney_setup(): # check that the filter coefs are computed the same way # as in Slaneys original code refData = loadmat('test/Slaney16kTestdata.mat', squeeze_me=True) fbSlaney = Slaney(fs=16000, cfs=refData['cf']) assert (peak_error(fbSlaney.feedback, refData['ERBfeedback']) < 1e-10) assert (peak_error(fbSlaney.forward, refData['ERBforward']) < 1e-10) assert (peak_error(fbSlaney._gain, refData['gain']) < 1e-10)
def test_FIR_ir(): # check if the impulse response matches the MATLAB version Fdata = loadmat('test/FIR16kTestdata.mat', squeeze_me=True)['FD'] fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) assert(peak_error(fbFIR.ir, Fdata['G'][()].conj())<1e-10)
def test_FIR_ERB(): # check if the filter bandwidths are calculated the same way # as the MATLAB reference Fdata = loadmat('test/FIR16kTestdata.mat', squeeze_me=True)['FD'] fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) assert(peak_error(1.0186*fbFIR.ERB, Fdata['b'][()])<1e-10)
def test_Slaney_process_single(): # santity check that process_single works. insig = np.zeros((1024, )) insig[0] = 1 refData = loadmat('test/Slaney16kTestdata.mat', squeeze_me=True) fbSlaney = Slaney(fs=16000, cfs=refData['cf']) outsig = fbSlaney.process_single(insig, 10) assert (peak_error(outsig, refData['y'][10, :]) < 1e-10)
def test_FIR_process_single(): # check if a single channel is processed correctly insig = loadmat('test/Inputdata.mat', squeeze_me=True)['indata16k'] fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) refout = loadmat('test/FIR16kTestdata.mat', squeeze_me=True)['y'] outsig = fbFIR.process_single(insig, 10) assert(peak_error(outsig, refout[:, 10])<1e-10)
def test_FIR_process(): # check if filtering works correctly insig = loadmat('test/Inputdata.mat', squeeze_me=True)['indata16k'] fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) outsig = fbFIR.process(insig) refout = loadmat('test/FIR16kTestdata.mat', squeeze_me=True)['y'].T assert(peak_error(outsig, refout)<1e-10)
def test_Slaney_process_2(): # repeat the test as above but load the feedback and feedforward # coefficients from the MATLAB code. This makes the result match. insig = np.zeros((1024, )) insig[0] = 1 refData = loadmat('test/Slaney16kTestdata.mat', squeeze_me=True) fbSlaney = Slaney(fs=16000, cfs=refData['cf']) fbSlaney.feedback = refData['ERBfeedback'] fbSlaney.forward = refData['ERBforward'] outsig = fbSlaney.process(insig) assert (peak_error(outsig, refData['y']) < 1e-10)
def test_Slaney_process(): # check that the resulting impulse response matches. # NOTE the threshold is set very high: 5e-4. The reason is that even # with the feedback and feedforward coefficients being very close # (to within 1e-21) due to the high order this can still result in a # large error refData = loadmat('test/Slaney16kTestdata.mat', squeeze_me=True) fbSlaney = Slaney(fs=16000, cfs=refData['cf']) insig = np.zeros((1024, )) insig[0] = 1 outsig = fbSlaney.process(insig) assert (peak_error(outsig, refData['y']) < 5e-4)
def test_Slaney_process_memory(): # check if processing a whole is the same as processing 2 chunks insig = np.zeros((1024, )) insig[0] = 1 fbSlaney = Slaney(fs=16000) refout = fbSlaney.process(insig) fbSlaney = Slaney(fs=16000) outsig1 = fbSlaney.process(insig[:800]) outsig2 = fbSlaney.process(insig[800:]) outsig = np.hstack((outsig1, outsig2)) assert (peak_error(outsig, refout) < 1e-10)
def test_Slaney_clear(): # make sure that if _clear() is called result is same as a brand # new filterbank insig = np.zeros((1024, )) insig[0] = 1 fbSlaney = Slaney(fs=16000) refout = fbSlaney.process(insig) fbSlaney = Slaney(fs=16000) _ = fbSlaney.process(np.random.randn(1000)) fbSlaney._clear() outsig = fbSlaney.process(insig) assert (peak_error(outsig, refout) < 1e-10)
def test_FIR_process_memory(): # check if processing a whole is the same as processing 2 chunks insig = loadmat('test/Inputdata.mat', squeeze_me=True)['indata16k'] fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) refout = fbFIR.process(insig) fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) outsig1 = fbFIR.process(insig[:800]) outsig2 = fbFIR.process(insig[800:]) outsig = np.hstack((outsig1, outsig2)) assert(peak_error(outsig, refout)<1e-10)
def test_FIR_clear(): # make sure that if _clear() is called result is same as a brand # new filterbank insig = loadmat('test/Inputdata.mat', squeeze_me=True)['indata16k'] fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) refout = fbFIR.process(insig) fbFIR = FIR(fs=16000, cfs=ERBnum2Hz(np.arange(1, 32.1, .5)), complexresponse=True) _ = fbFIR.process(np.random.randn(1000)) fbFIR._clear() outsig = fbFIR.process(insig) assert(peak_error(outsig, refout)<1e-10)
def test_Chen_setup(): fbChen = Chen(fs=fs, cfs=ERBspacing_given_spacing(80, 0.9 * 4000, .5)) ref_Ak = refData['C2'] ref_Bk = refData['normalizedGain'] ref_Ck = np.exp(refData['compensatedPhase']) ref_ComplexA = refData['GT_complexA'] ref_ComplexB = refData['GT_complexB'] assert (peak_error(fbChen.Ak, ref_Ak) < 1e-10) assert (peak_error(fbChen.Bk, ref_Bk) < 1e-10) assert (peak_error(fbChen.Ck, ref_Ck) < 1e-10) assert (peak_error(fbChen.Ck, ref_Ck) < 1e-10) assert (peak_error(fbChen.ComplexA, ref_ComplexA) < 1e-10) assert (peak_error(fbChen.ComplexB, ref_ComplexB) < 1e-10)
def test_Chen_clear(): fbChen = Chen(fs=fs, cfs=ERBspacing_given_spacing(80, 0.9 * 4000, .5)) _ = fbChen.process(np.random.randn(1000)) fbChen._clear() outsig = fbChen.process(insig) assert (peak_error(outsig, refout[:, :1000]) < 1e-10)
def test_Chen_process_memory(): fbChen = Chen(fs=fs, cfs=ERBspacing_given_spacing(80, 0.9 * 4000, .5)) outsig1 = fbChen.process(insig[:500]) outsig2 = fbChen.process(insig[500:]) outsig = np.hstack((outsig1, outsig2)) assert (peak_error(outsig, refout[:, :1000]) < 1e-10)
def test_Chen_process_single(): fbChen = Chen(fs=fs, cfs=ERBspacing_given_spacing(80, 0.9 * 4000, .5)) outsig = fbChen.process_single(insig, 10) assert (peak_error(outsig, refout[10, :1000]) < 1e-10)
def test_OZGTFB_clear(): fbOZ = OZGTFB(fs=fs, cfs=ERBspacing_given_N(80, 5000, 32)) _ = fbOZ.process(np.random.randn(1000)) fbOZ._clear() outsig = fbOZ.process(insig) assert (peak_error(outsig, refout) < 1e-10)
def test_OZGTFB_process_memory(): fbOZ = OZGTFB(fs=fs, cfs=ERBspacing_given_N(80, 5000, 32)) outsig1 = fbOZ.process(insig[:800]) outsig2 = fbOZ.process(insig[800:]) outsig = np.hstack((outsig1, outsig2)) assert (peak_error(outsig, refout) < 1e-10)
def test_OZGTFB_process_single(): fbOZ = OZGTFB(fs=fs, cfs=ERBspacing_given_N(80, 5000, 32)) outsig = fbOZ.process_single(insig, 10) assert (peak_error(outsig, refout[10, :]) < 1e-10)
def test_OZGTFB_setup(): fbOZ = OZGTFB(fs=fs, cfs=ERBspacing_given_N(80, 5000, 32)) assert (peak_error(fbOZ._feedback, refData['feedback']) < 1e-4) assert (peak_error(fbOZ._gain, refData['gain']) < 1e-10)