signal = np.random.normal(0, 1, size=n_buffers * blocklength) # the adaptive filter filt = FastBlockLMSFilter(length, blocklength, stepsize=0.1, leakage=0.9999) # secondary path estimate has to account for block size plant_model = FIRFilter(np.concatenate((np.zeros(blocklength), h_sec))) # simulates an audio interface with primary and secondary paths and 40 dB SNR noise # at the error sensor sim = FakeInterface( blocklength, signal, h_pri=h_pri, h_sec=h_sec, noise=wgn(olafilt(h_pri, signal), 40, "dB"), ) elog = [] y = np.zeros(blocklength) # control signal is zero for first block for i in range(n_buffers): # record reference signal x and error signal e while playing back y x, e, _, _ = sim.playrec(-y) # filter the reference signal fx = plant_model(x) # adapt filter filt.adapt(fx, e) # filter y = filt.filt(x) # log error elog.append(e)
length = 64 # number of adaptive FIR filter taps blocklength = 4 # length of I/O buffer and blocksize of filter n_buffers = 10000 # size of simulation estimation_phase = 2000 # primary and secondary paths h_pri = np.zeros(64) h_pri[60] = 1 h_sec = np.zeros(64) h_sec[20] = 1 # simulates an audio interface with primary and secondary paths and 40 dB SNR noise # at the error sensor signal = np.random.normal(0, 1, size=n_buffers * blocklength) sim = FakeInterface( blocklength, signal, h_pri=h_pri, h_sec=h_sec, noise=wgn(signal, 20, "dB") ) # the adaptive filter filt = FastBlockLMSFilter( length, blocklength, stepsize=0.01, leakage=0.99999, power_averaging=0.9 ) filt.locked = True # secondary path estimate has to account for block size plant_model = FIRFilter(np.zeros(blocklength + length)) # adaptive plant model adaptive_plant_model = FastBlockLMSFilter( length, blocklength, stepsize=0.01, leakage=0.99999 )