# Acoustic Echo Cancellation using LMS algorithm with C++ coding

Started by September 26, 2006
``` Hai all,

I am working on Acoustic Echo Cancellation using LMS
algorithm . Theoretically I went through that thorougly and now I am
implementing that using C++.

I am considering the 16 bit mono with 8KHz sampling
frequency.As it is considered of 16 bits amplitude(intensity) of each
sample should be within the range -32768 to 32767.As we know the
computational equations in that are:

>              Estimated echo sample,n[i] = x[i] * w(i)
where x[i] is farend signal sample.
w(i) is the weight of the filter
corresponding to n[i]

>              Estimated error signal is,e[i] = y[i] - n[i]
where y[i] is the desired signal which is the
combination of farend signal and the near end signal.

>                Weights for the next iteration is, = w(i) + 2 * u *
e[i] * x[i]
where u is the convergence weight factor.

But the problem is when the intensity of the samples of the
signal exceeds 32767 which is the right extreme of the range it is
taking the values from the left extreme . That is if the intensity of a
sample ie 32768 which is greater to the right extreme 32767 by one
number  and hence it is taking the value from the beginning,  that is
it will take -32768. ie.,

for         32768     it will take        -32768
for         32769     it will take        -32767
for         32770     it will take        -32766

in this it will proceed .My doubt is "If it decrease the intensity
values like thie the entire signal changes.So what is the solution? Can
we set in such a manner that if the intensity of sample exceeds 32767
that sample intensity should be maintained at a maximum of 32767
instead of it going to the starting of the range.

Can any one give me the idea regarding this.Can we keep
the value of the sample to be 32767 when it exceeds the right extreme
of the range.

Regards,
Aparna Ram.K.

```
```aparnaram84@yahoo.co.in wrote:

> So what is the solution? Can
> we set in such a manner that if the intensity of sample exceeds 32767
> that sample intensity should be maintained at a maximum of 32767
> instead of it going to the starting of the range.

Yes. It is called saturation. It needs to be applied to extreme
negative
values as well, of course.

How does the intesity of signal increase in your system? Are you
applying
gain factors (AGC, ALC) that can be greater than 1.0?

C

```
```
aparnaram84@yahoo.co.in wrote:

>  Hai all,
>
>           I am working on Acoustic Echo Cancellation using LMS
> algorithm . Theoretically I went through that thorougly and now I am
> implementing that using C++.

Is it a third time you are telling that you have understood everything?
It appears you are missing the basics again.

> Can any one give me the idea regarding this.Can we keep
> the value of the sample to be 32767 when it exceeds the right extreme
> of the range.

Clipping the value to keep it in the valid range is called "saturation".
It is supported by the DSP arithmetics.

However the real problem with the LMS is what to do with the saturated
data...

DSP and Mixed Signal Design Consultant

http://www.abvolt.com
```
```Vladimir Vassilevsky wrote:
>
>
> aparnaram84@yahoo.co.in wrote:
>
>>  Hai all,
>>
>>           I am working on Acoustic Echo Cancellation using LMS
>> algorithm . Theoretically I went through that thorougly and now I am
>> implementing that using C++.
>
>
> Is it a third time you are telling that you have understood everything?
> It appears you are missing the basics again.

I wonder why it is that "I went through that thoroughly" usually seem to
preface something that shows little understanding of the topic. :-)

>> Can any one give me the idea regarding this.Can we keep
>> the value of the sample to be 32767 when it exceeds the right extreme
>> of the range.
>
>
> Clipping the value to keep it in the valid range is called "saturation".
> It is supported by the DSP arithmetics.
>
> However the real problem with the LMS is what to do with the saturated
> data...

This is one of the pains of LMS (well, NLMS, since LMS is useless for
acoustic echo cancellation). If you just let the saturation logic do its
work, things are fast and efficient. However, most machines then give
you no indication that saturation occurred. If you monitor for overflow
it massively slows things down. However, you really do need to detect
saturation and freeze adaption when it occurs.

Steve
```
```Vladimir Vassilevsky wrote:
> aparnaram84@yahoo.co.in wrote:
>
> >  Hai all,
> >
> >           I am working on Acoustic Echo Cancellation using LMS
> > algorithm . Theoretically I went through that thorougly and now I am
> > implementing that using C++.
>
> Is it a third time you are telling that you have understood everything?
> It appears you are missing the basics again.
>
> > >It is a mistake to say that ' I  have understood every thing '.But when I studied and analysed that I got the reason for each and every step So I thought that I understood every thing.But each and every time when I am revising that I am getting some new points and I am getting new doubts. So now  I came to know that this subject is a ocean .  Here after I wont say that' I under stood every thing ' as there is a lot to understand and we will get more ideas on a topic when we think more..
>
> > Can any one give me the idea regarding this.Can we keep
> > the value of the sample to be 32767 when it exceeds the right extreme
> > of the range.
>
> Clipping the value to keep it in the valid range is called "saturation".
> It is supported by the DSP arithmetics.
>
> However the real problem with the LMS is what to do with the saturated
> data...
>
> > > By the way thanks for the reply and I think that this information will help me a lot to proceed further.Can you suggest  me some reference website to proceed regarding this point.I think that it will take time to clip each and every sample if it exceeds the maximum range.Then what is the solution.
>
>
>
> DSP and Mixed Signal Design Consultant
>
> http://www.abvolt.com

```
```Steve Underwood wrote:
> Vladimir Vassilevsky wrote:
> >
> >
> > aparnaram84@yahoo.co.in wrote:
> >
> >>  Hai all,
> >>
> >>           I am working on Acoustic Echo Cancellation using LMS
> >> algorithm . Theoretically I went through that thorougly and now I am
> >> implementing that using C++.
> >
> >
> > Is it a third time you are telling that you have understood everything?
> > It appears you are missing the basics again.
>
> I wonder why it is that "I went through that thoroughly" usually seem to
> preface something that shows little understanding of the topic. :-)
>
> > > > When I read that I got the reason for each and every step so I thought that 'I went through that thoroughly' . But now I came to know my mistake.Here after I wont repeat this.By the way thanks for the reply.
>
> >> Can any one give me the idea regarding this.Can we keep
> >> the value of the sample to be 32767 when it exceeds the right extreme
> >> of the range.
> >
> >
> > Clipping the value to keep it in the valid range is called "saturation".
> > It is supported by the DSP arithmetics.
> >
> > However the real problem with the LMS is what to do with the saturated
> > data...
>
> This is one of the pains of LMS (well, NLMS, since LMS is useless for
> acoustic echo cancellation). If you just let the saturation logic do its
> work, things are fast and efficient. However, most machines then give
> you no indication that saturation occurred. If you monitor for overflow
> it massively slows things down. However, you really do need to detect
> saturation and freeze adaption when it occurs.
>
> Steve

```
```>          I am considering the 16 bit mono with 8KHz sampling
> frequency.As it is considered of 16 bits amplitude(intensity) of each
> sample should be within the range -32768 to 32767.As we know the
> computational equations in that are:
>
>             But the problem is when the intensity of the samples of the
> signal exceeds 32767 which is the right extreme of the range it is
> taking the values from the left extreme . That is if the intensity of a
> sample ie 32768 which is greater to the right extreme 32767 by one
> number  and hence it is taking the value from the beginning,  that is
> it will take -32768. ie.,
>
>
>   for         32768     it will take        -32768
>   for         32769     it will take        -32767
>   for         32770     it will take        -32766
>
>
> in this it will proceed .My doubt is "If it decrease the intensity
> values like thie the entire signal changes.So what is the solution? Can
> we set in such a manner that if the intensity of sample exceeds 32767
> that sample intensity should be maintained at a maximum of 32767
> instead of it going to the starting of the range.
>
>                 Can any one give me the idea regarding this.Can we keep
> the value of the sample to be 32767 when it exceeds the right extreme
> of the range.

Solutions:

1) Adaptive filtering algorithms do not care whatever x(n) is;
2) If x(n) exceeds the ranges that you expect, why not adjust your
amplifer or ADC of the system;
3) if you want to simulate a 16-bit fixed point DSP using C++, saturate
the input data, i.e. forcing it within 0x0000-0xFFFF

Regards,

Leans.

```