主要内容

回声消除

R2026b

一段录制的语音包含由墙壁反射引起的回声。使用自相关性将其滤除。

在音频录制中,一个人用语音说出“MATLAB®”一词。加载数据和采样率 Fs=7418Hz。

load mtlb
% To hear, type soundsc(mtlb,Fs)

通过在音频录制中添加延迟 Δ 个采样并由已知因子 α 衰减的信号副本,对回声进行建模:y(n)=x(n)+αx(n-Δ)。指定时滞为 0.23 秒,衰减系数为 0.5。

timelag = 0.23;
delta = round(Fs*timelag);
alpha = 0.5;

orig = [mtlb;zeros(delta,1)];
echo = [zeros(delta,1);mtlb]*alpha;

mtEcho = orig + echo;
% To hear, type soundsc(mtEcho,Fs)

绘制原始信号、回声信号以及生成的信号。

t = (0:length(mtEcho)-1)/Fs;

tiledlayout("flow")
nexttile
plot(t,[orig echo])
legend(["Original" "Echo"])
nexttile
plot(t,mtEcho)
legend("Total")
xlabel("Time (s)")

Figure contains 2 axes objects. Axes object 1 contains 2 objects of type line. These objects represent Original, Echo. Axes object 2 with xlabel Time (s) contains an object of type line. This object represents Total.

计算信号自相关性的无偏估计值。选择并绘制对应于大于零的滞后的部分。

[Rmm,lags] = xcorr(mtEcho,"unbiased");

Rmm = Rmm(lags>0);
lags = lags(lags>0);

figure
plot(lags/Fs,Rmm)
xlabel("Lag (s)")

Figure contains an axes object. The axes object with xlabel Lag (s) contains an object of type line.

自相关性在回声到达的滞后处具有尖锐的峰。通过使信号通过 IIR 系统进行滤波来消除回声,该系统的输出 w 遵循 w(n)+αw(n-Δ)=y(n)。

[~,dl] = findpeaks(Rmm,lags,MinPeakHeight=0.22);

mtNew = filter(1,[1 zeros(1,dl-1) alpha],mtEcho);
% To hear, type soundsc(mtNew,Fs)

绘制滤波后的信号并与原始信号进行比较。

tiledlayout("flow")
nexttile
plot(t,orig)
legend("Original")
nexttile
plot(t,mtNew)
legend("Filtered")
xlabel("Time (s)")

Figure contains 2 axes objects. Axes object 1 contains an object of type line. This object represents Original. Axes object 2 with xlabel Time (s) contains an object of type line. This object represents Filtered.

另请参阅

函数