Asterisk fxotune


A utility for tuning the various settings on the fxo modules for analog cards.
Supported by Digium TDM400P and clones, TDM800P, TDM2400P, Xorcom Astribank FXO modules and probably some others. Not supported by X100P cards and clones.

fxotune tunes the module to generate less echo in the first place.

Using Fxotune

You need to train fxotune once using fxotune -i, see more below about that. The training will create the file /etc/fxotune.conf . In order to apply the same tuning next time, you need to run:

fxotune -s

after you have loaded the zaptel modules, but before you started Asterisk. Latest Zaptel init script should do that if /etc/fxotune.conf is present.

Fxotune Training

Zaptel 1.2

The version of fxotune included with zaptel 1.2 has a rather simple syntax. It is also slower and less effective than the version in 1.4.
  1. Stop asterisk
  2. Run: fxotune -i 4
  3. Restart asterisk

Asterisk must be stopped or otherwise fxotune would consider the line as busy (in fact, you could instead destroy the relevant zaptel channels, and restart asterisk in the end of the tuninng).

Zaptel 1.4

The rest of the page applies to the version of fxotune from zaptel 1.4 or newer.

From README.fxotune

Q. I have echo problems on my FXO modules and I've tried the different echo cancellation algorithms in zconfig.h, tried tweaking the gains, and still nothing works. What can I do?

A. Use the fxotune utility.

To use:
Just run the fxotune utility with the -i option. (`fxotune -i 4`) It should discover which zap channels are FXO modules and tune them accordingly. Be warned however, it takes a significant amount of time for EACH module to test, I would say somewhere around 2-3 minutes. But you only have to initialize it once for the line. It will write a configuration file to /etc/fxotune.conf. You will need to have your system run fxotune with the -s flag (`fxotune -s`) to set the module with the previously discovered values from fxotune.conf for it to take affect, so essentially if each time you reboot the machine you need to run `fxotune -s`. You might consider putting it in your startup scripts some time after the module loads and before asterisk runs.

NOTE: The digit after the -i option is the digit that will break dialtone on the line.

Matthew Fredrickson


Basically make sure asterisk isnt running and that zaptel and wctdm modules are loaded as fxotune needs direct access to the zap channel

In other words:
  1. amportal stop (Asterisk@Home)
CLI>stop now (just Asterisk)
followed by
  1. /usr/src/zaptel/fxotune -i 4

More info on fxotune:

fxotune optimizes the line characteristics of a TDM device to minimize the *source* of echo. This is generally referred to as 'balancing the hybrid' and is quite important in echo cancellation. Once the hybrid is properly balanced, software echo cancellers will work very nicely. To provide some hard numbers, the echo on lines at one site was about 15% with the default settings on the TDM. The software echo canceller actually did a fairly good job with this - but when we got the hybrid balanced properly, echo on the line dropped to 3%, and then the software echo canceller did a *fantastic* job. At another site, the echo on the line was 60% - this was well beyond what the software echo canceller could handle (it did work, but there was quite a bit of residual echo, etc...). Once we tuned the hybrid, echo dropped to 4%, and the echo canceller was able to work properly.

Note that fxotune does not do anything with the echo canceler algorithms themselves - instead, it optimizes the signal before it gets to the echo canceler, making it easier for the echo canceler to do it's work.

There are two types of tuning that can be performed on the TDM - adjusting line impedence, and adjusting echo coefficients in the digital filter that is part of the hybrid iteself. The current implementation of fxotune *only* balances the line impedence (which does not necessarily result in the best results).

Important Note: The current fxotune application in SVN has a bug that causes it to not properly clear the dialtone of the line during part of it's test. As a result, it measures the dialtone as part of the echo response, which can cause it to 'optimize' to the wrong line impedence.

There is a patch against fxotune that fixes the above bug, and revamps the calibration algorithm to optimize the echo coefficients in addition to the line impedence. It also adds tools for getting a numerical measure of the amount of echo on the line. We have seen echo levels of 60% after tuning only the line impedence, and 3% after doing the full opimization. In addition, due to some frequency domain trickery, the full optimization test actually runs faster than the old one.

To get the echo level of line 3 using the patched fxotune, stop asterisk, then run:

./fxotune -d -b 3

This will return the ratio of echo to input signal (the closer this number is to 0.0 the better. Imperically, we've found that getting this number below 5% is important for proper operation of the software echo cancellers).

The -d option also dumps input and output waveform information to ./fxotune_dump.vals - plotting these in a graph can be very instructive. For example, here is the plot for one of our lines without any tuning at all obtained using the following command (-w 1004 makes the test operate at a single frequency of 1004 Hz instead of multiple frequencies in a single test):

./fxotune -d -b 3 -w 1004

The pink line is the driving signal, the blue line is the measured response reflecting back from the CO into the untuned hybrid.


We then optimize using the *old* fxotune calibration algorithm using the following command ('-t 1' forces fxotune to use the old calibration type 1):

./fxotune -i 5 -t 1

We then re-run ./fxotune -d -b 3 -w 1004, and the results are:


Things have improved, but we still have a bunch of echo - there is no way that the software echo cancellers can handle this.

Finally, we run fxotune using the new calibration:

./fxotune -i 5

The echo results are now:


At this point, the hybrid is pretty well tuned, and the software echo cancellers can get of any residual echo.

In summary, tuning with the patched fxotune is the same as before - if '5' is the keypress that will clear the dialtone, you'd run:

./fxotune -i 5

To set the calibration during boot, run:

./fxotune -s

If the new fxotune helps you out, please be sure to add your comments to the bug tracker!
Created by: SoloFlyer, Last modification: Tue 24 of Jan, 2017 (22:58 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+