Summary of the invention
The technical problem that the present invention solves is to provide a kind of echo cancel method and system, can eliminate local echo and long-range echo fully, and operand reduces greatly.
The technical scheme that realizes the object of the invention is as follows:
A kind of echo cancel method comprises step:
Judge the echo state based on input signal short-time energy:
Under the echo floodage, eliminate echo by lock filter;
Under the echo state of activation, upgrade sliding window side-play amount and tracking filter coefficient, and judge according to judgment criterion whether described tracking filter finishes locking: if finish locking, then directly eliminate echo, and will lock the coefficient assignment to lock filter by tracking filter; If do not finish locking, then change by lock filter and eliminate echo.
Preferably, if the maximum ω in the filter coefficient vector
i(n+1) item i>(L+1)/2 and sliding window side-play amount less than on the sliding window peak excursion in limited time, the sliding window side-play amount increases a unit, the tracking filter coefficient vector unit that moves to left simultaneously, wherein: L is a filter order.
Preferably, if the maximum ω in the filter coefficient vector
i(n+1) item i>(L+1)/2 and sliding window side-play amount equal on the sliding window peak excursion in limited time, the zero setting of sliding window side-play amount, and the filter coefficient vector is updated to fricton-tight window side-play amount filter coefficient vector simultaneously, and wherein: L is a filter order.
Preferably, described sliding window peak excursion upper limit value is to be not less than the positive integer of actual maximum echo delay divided by sample rate.
Preferably, if the maximum ω in the filter coefficient vector
i(n+1) item i<(L+1)/2 and sliding window side-play amount are timing, and the sliding window side-play amount reduces by a unit, the tracking filter coefficient vector unit that moves to right simultaneously, and wherein: L is a filter order.
Preferably, if the sliding window side-play amount is zero, then the filter coefficient vector is updated to fricton-tight window side-play amount filter coefficient vector; Otherwise fricton-tight window side-play amount filter coefficient vector remains unchanged.
Preferably, described filter elimination echo is according to the filter locking coefficient and the sliding window side-play amount of correspondence input signal to be carried out filtering.
Preferably, the judgment criterion whether described tracking filter finishes locking is: each vector satisfies the maximum ω in the filter coefficient in the convergence length tracking filter coefficient vector continuously
i(k) item i=(L+1)/2 and convergency value are less than the convergence threshold of setting, and wherein: L is a filter order.
Preferably, described convergence threshold value is greater than the estimated value of noise amplitude peak.
In addition, the system that the present invention also provides a kind of echo to eliminate comprises:
The near end echo cancellation element comprises filter, echo state machine and controller, is used to eliminate near end echo;
And the far-end echo cancellation element, comprise filter, echo state machine and controller, be used to eliminate far-end echo;
The demand that described far-end echo cancellation element is eliminated according to echo is selected operating state or bypass condition.
Preferably, described filter is the double filter structure that is made of lock filter and tracking filter.
Preferably, described controller reaches the situation that tracking filter is finished locking according to the feedback result of echo state machine, and selection is to be eliminated echo or eliminated echo by tracking filter by lock filter.
Preferably, described echo state machine switches to echo floodage or echo state of activation according to the variation of input signal short-time energy.
The present invention also provides a kind of echo cancelling device, comprising:
The echo state machine is used for according to the short-time energy of upgrading input signal, and judgement is echo floodage or echo state of activation;
Tracking filter and lock filter are used for input signal filtering, eliminate echo;
Controller is used for the echo state according to echo state machine feedback, reaches the situation that tracking filter is finished locking, and selection is to be eliminated echo or eliminated echo by tracking filter by lock filter.
Preferably, described tracking filter determines whether to finish locking according to the judgment criterion of setting: if finish locking, then tracking filter is locked coefficient vector and sliding window side-play amount assignment and give lock filter, eliminate echo by tracking filter; If do not finish locking, eliminate echo by lock filter.
Preferably, the judgment criterion whether described tracking filter finishes locking is: each vector satisfies in the convergence length tracking filter coefficient vector continuously, the item i=(L+1)/2 of the maximum ω i (k) and convergency value are less than the convergence threshold of setting in the filter coefficient, and wherein: L is a filter order.
Preferably, described convergence threshold value is greater than the estimated value of noise amplitude peak.
The contrast prior art, beneficial effect of the present invention is summarized as follows:
1, echo cancel method of the present invention-sliding window enhancement mode NLMS method, changed the iterative manner of traditional NLMS method filter coefficient, limited number of time iteration by seldom can make filter coefficient infinitely approach the actual value of actual echo path parameter, thereby can eliminate echo fully, and avoid adopting the measure of non-linear making an uproar residual echo.In addition, the inventive method can thoroughly be eliminated long delay echo by sliding window, and operand reduces greatly, thereby greatly saves hardware resource such as memory device.
2, the present invention is thorough, stable to guarantee that echo is eliminated by lock filter and tracking filter associated working.Adjust filter coefficient by the tracking filter self adaptation, progressively approach echo path, and the filter after will restraining locks coefficient vector and lock filter is passed in the sliding window skew; And lock filter is offset input signal filtering with up-to-date filter locking coefficient vector that obtains and sliding window when tracking filter does not start or do not restrain, thereby eliminates echo.Double filter co-ordination under logic control, thus the problem that the noise mistake is locked better solved, guarantee the steady effect of echo cancellation process.
3, in addition, the present invention is that echo is flooded and two states of echo activation by the state reduction with state machine, has greatly simplified the implementation procedure that echo is eliminated, and has guaranteed the reliability of real work.
Below in conjunction with the drawings and specific embodiments the present invention is further described.
Embodiment
The invention provides a kind of new echo cancel method, broken through the limitation of traditional NLMS method, carry out echo elimination, solved the insurmountable problem of conventional method based on sliding window enhancement mode NLMS method.Basic thought of the present invention is based on sliding window enhancement mode NLMS method self adaptation and adjusts linear tap transversal filter coefficient, can infinitely approach the echo original shape by limited number of time iteration seldom, and it is deducted, thereby realize the elimination of local echo and long-range echo from true echo signal.As shown in Figure 2, be echo cancelling system block diagram of the present invention.This system comprises: near end echo cancellation element and far-end echo cancellation element, each device all comprises double filter, echo state machine and controller.Near end echo cancellation element and far-end echo cancellation element are respectively applied for the elimination that realizes local echo and long-range echo.Both removing methods are identical, can realize simultaneously, also can only select to realize the elimination of local echo.When long-range echo is eliminated (having echo cancellation performance or local side has been installed Echo Canceller such as remote terminal itself), then part (being long-range echo cancel method and correlation behavior logic) can be by bypass in the frame of broken lines, thereby further saves resource.
Below, in conjunction with Fig. 3,4 and Fig. 9 the implementation procedure of scheme of the present invention is specifically set forth.Because local echo is identical with the elimination implementation procedure of long-range echo, be input, output signal difference, that is: the elimination of local echo is that the local echo that deducts local voice signal x (n) from real local echo y (n) is estimated, in this process, input signal is x (n), y (n), and output signal is r (n); And the elimination of long-range echo is the long-range echo estimation that deducts local speech voice signal s (n) from received speech signal c (n), and in this process, input signal is s (n), c (n), and output signal is x (n).
At first need to determine the optimum value of several constants according to actual conditions, suitable value can reduce operand to greatest extent under the prerequisite that does not influence performance, these several constants are: sliding window peak excursion upper limit Max_Offset, filter order L, n convergency value d (n), convergence threshold d_GATE constantly, d (n) convergence minimum length d_L, very little constant e.If it is DT that actual echo postpones, sample rate is Fs, and constant value rule is respectively described below:
The Max_Offset value is: greater than the minimum positive integer of actual maximum echo delay/Fs.Generally speaking, local echo delay is less, and long-range echo delay is longer, can reach the hundreds of millisecond.
If DT/Fs is big (for example greater than 9), L selects the odd number less than DT/Fs.This moment method is operated in the sliding window pattern, and the elimination of generally long-range echo is operated in this pattern.
If DT/Fs less (for example being less than or equal to 9), L selects the minimum odd number greater than DT/Fs.This moment method is operated in windowless pattern, and the elimination of generally local echo is operated in this pattern.
D (n) convergence threshold d_GATE value should be greater than the estimated value of noise amplitude peak.
D (n) convergence minimum length d_L should get higher value, gets the positive integer greater than 28 usually.
E gets very little positive number, such as 0.0001.
Secondly, the iterative formula that the present invention relates to is described as follows:
(1) y^ (n)=W (n)
T(n-m (n)) is for echo is estimated.
W (n)=[ω wherein
0(n), ω
1(n) ... ω
L-1(n)]
T, ω
i(n) be filter coefficient.Common W (0)=[0,0 ... 0].
X(n-m(n))=[x(n-m(n)),x(n-1-m(n)),x(n-2-m(n)),...x(n-L+1-m(n))]。
When being operated in the sliding window pattern, m (n) is the filter n skew of sliding window constantly, m (0)=0 usually;
When being operated in windowless pattern, m (n) constant is 0.
(2) e (n)=y (n)-y^ (n) is error signal.
(3) d (n)=d (n-1)/2+|e (n) |, common d (0)=0.
(4)
Be received signal short-time energy.When being operated in the sliding window pattern, m (n) is filter n sliding window skew constantly, m (0)=0 usually; When being operated in windowless pattern, m (n) constant is 0.
(5)
Wherein e is very little positive number.
(6) W (n+1)=W (n)+u (n) * X (n-m (n)) is the filter coefficient vector.
When being operated in the sliding window pattern, m (n) is filter n sliding window skew constantly, m (0)=0 usually.
When being operated in windowless pattern, m (n) constant is 0.
(7) window slide (this process is only applicable to the sliding window pattern, when being operated in windowless pattern following time, ignores this process)
1. upgrade sliding window skew m (n+1), upgrade the filter coefficient vector:
If { ω
0(n+1), ω
1(n+1) ..., ω
L-1(n+1) } the maximum ω in
iWhen item i (n+1)>(L+1)/2 and m (n)<Max_Offset, m (n+1)=m (n)+1, move to left unit, i.e. a ω of vector W (n+1) simultaneously
1(n+1) → ω
0(n+1), ω
2(n+1) → ω
1(n+1) ..., ω
L-1(n+1) → ω
L-2(n+1), 0 → ω
L-1(n+1).
If { ω
0(n+1), ω
1(n+1) ..., ω
L-1(n+1) } the maximum ω in
iWhen item i (n+1)>(L+1)/2 and m (n)=Max_Offset, m (n+1)=0, W (n+1)=W
M=0
If { ω
0(n+1), ω
1(n+1) ... ω
L-1(n+1) } the maximum ω in
i(n+1) item i<(L+1)/2 and m (n)>0 o'clock, m (n+1)=m (n)-1, move to right unit, i.e. a ω of vector W (n+1) simultaneously
L-2(n+1) → ω
L-1(n+1), ω
1-3(n+1) → ω
1-2(n+1) ..., ω
1(n+1) → ω
2(n+1), 0 → ω
1(n+1).
Otherwise, m (n+1)=m (n).
2. upgrade fricton-tight window offset filter coefficient vector W
M=0:
If m (n+1)=0, then W
M=0=W (n+1); Otherwise keep W
M=0Constant.
(8) upgrade lock-out state
The convergence decision criteria: each W (k) in continuous d_L the vector (k=n+1, n ..., n-d_L+2) satisfy { ω
0(k), ω
1(k) ... ω
L-1(k) } the maximum ω in
i(k) item i=(L+1)/2 and d (n)<d_GATE.
If satisfy above-mentioned convergence decision criteria, then upgrade lock-out state: d
Lock=d (n), W
Lock=W (n+1), m
Lock=m (m+1).Common d
LockInitial value be 0, W
LockInitial value be zero vector (0,0...0) T, m
LockInitial value be 0.
Replace with that c (n), y^ (n) replace with c^ (n), r (n) replaces with x (n) if the x among Fig. 4 and Fig. 9 (n) is replaced with r (n), y (n), then just become the implementation procedure that long-range echo is eliminated, be not repeated herein.
The value of filter order L is determining it is in work of sliding window pattern or windowless pattern work.The software realization flow that the elimination of local echo is operated in the sliding window pattern and removes the realization flow that just makes windowless pattern into the part in the frame of broken lines (being the window slipper) as shown in Figure 9, and sliding window skew this moment m perseverance is 0.
As shown in Figure 9, the specific implementation flow process of echo elimination is as follows:
At first, finish a new sampled point, upgrade the short-time energy P of local echo
x(n): P
x(n)=P
x(n-1)+x
2(n)-x
2Or upgrade the short-time energy P of far-end echo (n-K),
r(n): P
r(n)=P
r(n-1)+r
2(n)-r
2(n-K); By P
xOr P
rJudge with current state whether status change is arranged, if having, then with the state machine transition to new state, i.e. m (n) → m
Lock, u (n) → u
Lock, W (n) → W
Lock
Then, judge the echo state:, then upgrade echo successively and estimate y if flood attitude for echo
Lock(n)=W
Lock(n)
TX (n-m
Lock), upgrade error signal e
Lock(n)=y (n)-y
Lock(n), r (n)=e
Lock(n), eliminate echo, finish an echo and eliminate, and wait for that next sampled point arrives by lock filter.
If be the echo activated state, then upgrade echo successively and estimate y^ (n)=W (n)
TX (n-m), upgrade error signal e (n)=y (n)-y^ (n), upgrade d (n)=d (n-1)/2+|e (n) |, upgrade received signal short-time energy
, upgrade
, and upgrade tracking filter coefficient W (n+1)=W (n)+u (n) * X (n-m (n));
Once more, under being operated in the sliding window pattern, (, ignore this process) when being operated in windowless pattern following time
1. upgrade sliding window skew m (n+1), upgrade the filter coefficient vector:
If { ω
0(n+1), ω
1(n+1) ..., ω
L-1(n+1) } the maximum ω in
iWhen item i (n+1)>(L+1)/2 and m (n)<Max_Offset, m (n+1)=m (n)+1, move to left unit, i.e. a ω of vector W (n+1) simultaneously
1(n+1) → ω
0(n+1), ω
2(n+1) → ω
1(n+1) ..., ω
L-1(n+1) → ω
L-2(n+1), 0 → ω
L-1(n+1).
If { ω
0(n+1), ω
1(n+1) ..., ω
L-1(n+1) } the maximum ω in
iWhen item i (n+1)>(L+1)/2 and m (n)=Max_Offset, m (n+1)=0, W (n+1)=W
M=0
If { ω
0(n+1), ω
1(n+1) ... ω
L-1(n+1) } the maximum ω in
i(n+1) item i<(L+1)/2 and m (n)>0 o'clock, m (n+1)=m (n)-1, move to right unit, i.e. a ω of vector W (n+1) simultaneously
L-2(n+1) → ω
L-1(n+1), ω
1-3(n+1) → ω
1-2(n+1) ..., ω
1(n+1) → ω
2(n+1), 0 → ω
1(n+1).
Otherwise, m (n+1)=m (n).
2. upgrade fricton-tight window offset filter coefficient vector W
M=0:
If m (n+1)=0, then W
M=0=W (n+1); Otherwise keep W
M=0Constant.
At last, judge whether tracking filter finishes locking:, upgrade lock-out state: m if tracking filter has been finished locking
Lock=m, d
Lock(n)=d (n), W
Lock=W (n+1) behind the renewal lock filter coefficient, upgrades r (n)=e (n), eliminates echo by tracking filter, finishes an echo and eliminates, and wait for that next sampled point arrives.
If tracking filter is not finished locking, upgrade echo and estimate y
Lock(n)=W
Lock(n)
TX (n-m
Lock), upgrade error signal e
Lock(n)=y (n)-y
Lock(n), r (n)=e
Lock(n), eliminate echo, finish an echo and eliminate, and wait for that next sampled point arrives by lock filter.
The realization flow of above-mentioned Fig. 9 is simplified the step that is stated as shown in Figure 3, that is:
301, finish a new sampled point;
302, upgrade input signal short-time energy;
303, judge the whether transition of echo state, and the current state of living in of decision state machine;
304, if state machine is in the echo floodage, eliminate echo by lock filter, finish an echo and eliminate, and wait for that next sampled point arrives.
305,, upgrade the tracking filter coefficient, then sliding window if state machine is in the echo state of activation;
306, judge whether tracking filter finishes locking;
307, if tracking filter is not finished locking, eliminate echo, finish an echo and eliminate, and wait for that next sampled point arrives by lock filter.
308, if tracking filter has been finished locking, upgrade the lock filter coefficient, eliminate echo, finish an echo and eliminate, and wait for that next sampled point arrives by tracking filter.
Double filter of the present invention comprises a tracking filter and a lock filter, wherein: the main task of tracking filter is to adjust filter coefficient by self adaptation, progressively approach echo path, and the filter after will restraining locks coefficient vector and lock filter is passed in the sliding window skew; And the main task of lock filter is when tracking filter does not start or do not restrain, and is offset input signal filtering with up-to-date filter locking coefficient vector that obtains and sliding window, to eliminate echo.Based on this double filter structure as shown in Figure 5, r (n), y (n) replace with c (n), r (n) replaces with x (n) if x (n) replaced with, and just become long-range echo and eliminate the double filter structure.The co-ordination under logic control of double filter structure.Whether decision starts tracking filter to control logic according to the echo state, as not starting, stops tracking filter, and starts lock filter elimination echo immediately; Start as need, start the tracking filter self adaptation immediately and adjust network parameter, and constantly judge with pre-determined decision criteria whether current tracking filter has finished locking, if do not finish locking, then start lock filter immediately, and produce output by lock filter filtering echo; If finish locking, then upgrade the lock filter coefficient, eliminate echo by tracking filter and produce output.No matter when, as long as lock filter work is then always carried out filtering with the up-to-date filter parameter that obtains to input signal.
There are two kinds of operating states in echo cancellation process: echo state of activation and echo floodage.During real work,, then be considered as the echo state of activation when being better than background noise when echo energy is enough big; On the contrary, when echo energy very little, near or then be considered as the echo floodage during less than background noise.The echo state switches through whole communication process.State switches based on the short-time energy variation of x (n) and r (n) and takes place, and the short-time energy of the two is estimated to be defined as:
The short-time energy of x (n)
Wherein the constant K value should satisfy: be far smaller than the sampling number that people's ear can be distinguished the mora duration.Generally, the duration just can be perceiveed by people's ear greater than the voice signal of 20ms, if sample rate Fs=8KHz, then K<<160.
The short-time energy of r (n)
Wherein the constant K value should satisfy: be not less than lowest frequency voice half period sampling number.Generally speaking, speech frequency is in 300Hz~3KHz scope, if sample rate Fs=8KHz, then K 〉=14.
Should adopt iterative formula during realization, reduce operand, above-mentioned two formulas are respectively:
P
x(n)=P
x(n-1)+x
2(n)-x
2(n-K), and
P
r(n)=P
r(n-1)+r
2(n)-r
2(n-K), and
Local echo is eliminated state machine as shown in Figure 6, P
X_upFor local echo is activated the upper limit, P
X_downFor local echo is activated lower limit.Can be P according to factors such as local analog voice channel gain and local echo path loss during actual the use
X_up, P
X_downGet suitable value, but must satisfy P
X_up>P
X_downP generally
X_upValue is not more than the product of maximum noise amplitude square and K, but should be much larger than the noise average amplitude square product with K, P
X_downValue is slightly less than P
X_up
Far-end echo is eliminated state machine as shown in Figure 7, P
R_upFor long-range echo is activated the upper limit, P
R_downFor long-range echo is activated lower limit.Can be P according to factors such as long-range analog voice channel gain and long-range echo path loss during actual the use
R_up, P
R_downGet suitable value, but must satisfy P
R_up>P
R_downP generally
R_upValue is not more than the product of maximum noise amplitude square and K, but should be much larger than the noise average amplitude square product with K, P
R_downValue is slightly less than P
R_up
It should be noted that when state machine generation status change, m (n), d (n), W (n) must be returned to nearest convergency value, that is: m
Lock→ m (n), d
Lock→ d (n), W
Lock→ W (n).
As shown in Figure 8, the device block diagram for echo of the present invention is eliminated comprises:
The echo state machine according to the short-time energy of upgrading near end input signal x (n) or remote end input signal r (n), judges that the echo state is echo floodage or echo state of activation;
Controller according to the feedback result of echo state machine, reaches tracking filter and whether finishes locking, and selection is to be eliminated echo or eliminated echo by tracking filter by lock filter;
If the echo floodage is then eliminated echo by lock filter;
If the echo state of activation is then upgraded the tracking filter coefficient, judge whether described tracking filter finishes locking: if tracking filter has been finished locking, then upgrade the lock filter coefficient, eliminate echo by tracking filter; If tracking filter is not finished locking, eliminate echo by lock filter.
The near end echo cancellation element is the same with the far-end echo cancellation element, all is the lock condition according to work at present state and tracking filter in the state machine, by logic controller decision double filter working method.In addition, can also be simultaneously referring to table 1 in conjunction with the aforesaid function situation of understanding echo cancelling device that specifies.
Table 1
Below, by The Realization of Simulation sliding window enhancement mode NLMS method of the present invention and traditional NLMS method are compared, to show the exclusive advantage of the present invention.
1, required hardware resource relatively
Tradition NLMS method needs the exponent number L of minimum filter
Min〉=Δ T/Fs, wherein Fs is a sample rate, Δ T is an echo delay.
And required filter order of sliding window enhancement mode NLMS method of the present invention and Δ T do not have direct relation, even Δ T very big (as the hundreds of millisecond), L also can very little (for example can get L=7).
If sample rate is 8KHz, echo delay Δ T=100ms, the required filter order L of traditional NLMS method should be greater than 800.And sliding window enhancement mode NLMS method filter order of the present invention can be got any odd number greater than 5.This shows that sliding window enhancement mode NLMS method filter order of the present invention is much smaller than the required filter order of traditional NLMS method, thereby the required memory cell of the inventive method is much smaller than conventional method.
2, operand relatively
Suppose that time of echo delay quantizes Δ n and is the smallest positive integral greater than Δ T/Fs, wherein Fs is a sample rate, and Δ T is an echo delay.Sampling time T of every mistake, operand is more as shown in table 2 in conventional method and the inventive method unit's sampling time:
Table 2
In table 2, L is traditional NLMS method filter order, and minimum value is the smallest positive integral that quantizes (Δ T/Fs) greater than time of echo delay.As seen form multiplication along with echo delay Δ T increases big for the conventional method operand, and as Δ T when very big (as greater than 10ms), arithmetic unit is very big.L ' is a sliding window enhancement mode NLMS method filter order of the present invention, and is irrelevant with Δ T, can get very little value, thereby operand is very little.
3, the convergence of filter coefficient W (n) relatively
Know that by filter coefficient iterative formula W (n+1)=W (n)+u (n) * X (n) filter coefficient W (n) condition of convergence is that u (n) is along with time n levels off to zero.
At sample frequency Fs=8KHz, echo delay Δ T=10ms, input signal x (n) is under the cosine signal condition of unit, the convergence of the inventive method and conventional method u (n) is more as shown in figure 10: conventional method is because u (n) can not converge on zero all the time, so filter coefficient W (n) can not really lock all the time,, input signal x (n) constantly produces residual noise along with changing.The inventive method has exactly overcome the defective of conventional method, and u (n) levels off to zero rapidly, and filter coefficient W (n) can lock rapidly, thereby can not produce residual noise.
4, echo is eliminated convergence rate relatively
At sample frequency Fs=8KHz, echo delay Δ T=10ms, e gets 0.0001, and input signal x (n) is under the cosine signal condition of unit: for conventional method, the step-length constant gets 0.05, and filter order gets 81; To the inventive method, filter order is got 81 (working) under windowless pattern.The two echo is eliminated convergence rate more as shown in figure 11.Obviously, the echo of the inventive method is eliminated convergence rate obviously greater than conventional method.
5, echo is eliminated the result relatively
At sample frequency Fs=8KHz, echo delay Δ T=10ms, e gets 0.0001, and input signal x (n) is under the real speech signal conditioning of unit: for conventional method, the step-length constant gets 0.5, and filter order gets 81; For the inventive method, filter order is got 7 (working) under the sliding window pattern.The two echo is eliminated the result more as shown in figure 12.Obviously, sliding window enhancement mode NLMS method echo elimination ability of the present invention is much better than traditional NLMS method.
Echo under the true talking state of simulation is eliminated quality as shown in figure 13.Wherein, sample frequency Fs=8KHz, echo delay Δ T=10ms, e gets 0.0001, and filter order is got 7 (working) under the sliding window pattern, and input signal x (n) is the real speech signal.
Above-described embodiment of the present invention does not constitute the qualification to protection range of the present invention.Any any modification of being done within the spirit and principles in the present invention, be equal to and replace and improvement etc., all should be included within the claim protection range of the present invention.