// (c) 2022 cepstrum.co.jp // howling canceller simulation program for Scilab // // +------------------------------------------------------------+ // | | // | s (speech signal) | // | | | // | +---+ d v | // | +--->| h +--->(+)---+ ds | // | | +---+ | | // | +---------+ | + v +-------+ | // +--->| limiter +---+ x ^ (+)---+--->| delay +---+ // +---------+ | | - ^ | e +-------+ ze // | +---+ | | // +--->| w +----------+ | // +---+ y | // | | // +-----------------+ clear; // clear all variables INPUT_WAVEFILE_NAME='ford8k.wav'; OUTPUT_WAVEFILE_NAME='out.wav'; DATLEN=200000; // data file length (even number) FS=8000; // sampling frequency [Hz] FIRLEN=256; // adaptive filter legnth DLYLEN=256; // delay length GAIN=4.0; // maximum gain of acoustic system MARGIN=2.0; // dynamic range margin MU=0.05; // step size parameter of adaptive filter indata=loadwave(PWD+'\'+INPUT_WAVEFILE_NAME); outdata=zeros(1:DATLEN); missalignment=zeros(1:DATLEN); err=zeros(1:DATLEN); // generate impulse response of acoustice system (h) rand('normal'); rand('seed', 912); h=[zeros(1:5), rand(1:FIRLEN-5)]; h=h.*(0.97^(1:FIRLEN)); h=h/max(abs(fft(h, -1))); h=GAIN*h; buf=zeros(1:FIRLEN); w=zeros(1:FIRLEN); delay=zeros(1:DLYLEN); ze=0; for i=1:DATLEN x=ze; // limiter if (1.0/GAIN)h, red-->w)', 'fontsize', 3); plot2d(1:FIRLEN, h, style=2); // blue plot2d(1:FIRLEN, w, style=5); // red // calculate frequency response of h, w hspec=fft([h, zeros(1:FS-FIRLEN)], -1); hspec=hspec(1:FS/2); [hdb, hphi]=dbphi(hspec); wspec=fft([w, zeros(1:FS-FIRLEN)], -1); wspec=wspec(1:FS/2); [wdb, wphi]=dbphi(wspec); // plot amplitude response of h, w [dB] scf(4); clf; title('amplitude response [dB] (blue-->h red-->w)', 'fontsize', 3); plot2d(1:FS/2, hdb, style=2); // blue plot2d(1:FS/2, wdb, style=5); // red // plot phase response of h, w scf(5); clf; title('phase response (blue-->h red-->w)', 'fontsize', 3); plot2d(1:FS/2, hphi/180, style=2); // blue plot2d(1:FS/2, wphi/180, style=5); // red