📄 echo_canceller.m
字号:
% design echo canceller with different adaptive filters
clear
% read data from the .wav file
% sp_rex = wavread('INLS1_orig.WAV','double');
sp_rex = wavread('0_9b.wav','double');
sp_trx = wavread('0_9b.wav','double');
% generate the low pass filter to simulate the echo circuit( 16 orders)
% fc=3.4kHz
coeff = [0.0227,-0.0069,-0.0159,0.0437,-0.0735,0.1018,-0.1251,...
0.1404,0.8256,0.1404,-0.1251,0.1018,-0.0735,0.0437,-0.0159,-0.0069,0.0227];
flt_st = zeros(1,16); % input register of the filter
% initial the filter
TH = 25; % db
miu = 0.001;alpha = 1/128;
w = zeros(1,17);
u = w; pe_n = 0; pd_n = 0;
% entry for the echo cancelling
L = length(sp_rex); flag = 1;
for i=1:L
sample(i) = coeff * [flt_st sp_rex(i)]';
% updata register for the echo circuit
flt_st(1:end-1) = flt_st(2:end);
flt_st(end) = sp_rex(i);
% call the lms algorithm to updata the adptive filter coefficiences
u = [u(2:17) sp_rex(i)];
if(flag ==1)
[w pe_n pd_n d_est(i) e(i)] = lms(u,w,sample(i),pe_n,pd_n,miu,alpha);
rate = -20*log(pe_n/pd_n);
if(rate > TH)
fprintf('The alforithm is convergenced at %dth item!\n rate=%d\n',i,rate);
flag = 0;
end
% else d_est(i) = w * u';
end
end
sp_rex_est = filter(w,1,sp_rex);
est = sample' - sp_rex_est;
figure(1)
stem(coeff);hold on;stem(w,'r')
figure(2)
subplot(2,1,1);plot(sample);hold on;plot(sp_rex_est,'r')
subplot(2,1,2);plot(est)
sound(sp_rex*32);sound(sp_rex_est*32);sound(est*32)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -