Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Oct 20, 2020. It is now read-only.
/atfa-examplesPublic archive

Example algorithms for the ATFA (Real-time testing environment for adaptive filters)

NotificationsYou must be signed in to change notification settings

fofoni/atfa-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ATFA is theAmbiente de Testes para Filtros Adaptativos (Testingenvironment for adaptive filters).

This repository

  • provides examples of adaptive filtering algorithms implemented in C++and C, and exposing the API that ATFA expects;
  • explains how to understand the examples, how to modify them, how towrite your own algorithms, and how to compile them;
  • provides scripts to compile the algorithms into the file format thatATFA expects, namely dynamic shared objects, or DSOs (*.so).

Quick How-To

The algorithms must be compiled and linked into an*.so file. This canbe done manually, or by using the helper scriptbuild.py.Aditionally, the scriptbuild-all.sh can also be used to compileall of the examples at once.

If you just want to compile the examples to use from ATFA, type:

$cd atfa-examples$ bash build-all.sh

Seethe section on using thebuild.py script for more information.

How to write algorithms

ATFA accepts custom adaptive filtering algorithms in the form of dynamicshared object (*.so) files. Each adaptive filter DSO must export thefollowing symbols:

The last two (adapf_title andadapf_listing) are generatedautomatically by thebuild.py script. Below, each of thefunctions to be exported is explained:

Theadapf_* functions

void *adapf_init()

Theadapf_init function initializes (e.g., acquires memory for) thedata structures that the algorithm will use. This data structure mightinclude, for example, the impulse response vector (vector of filtercoefficients), the input vector, and any other kind of parameter thatthe algorithm needs to keep track of.

This function must return a pointer to the initialized data.

void *adapf_restart(void *data)

This function resets the information contained indata (e.g., zeroesout the impulse response that has been learned so far), and returns apointer to the zeroed data. This function might free the memory pointedto by the old data and return a pointer newly allocated-and-initializedmemory.

int adapf_close(void *data)

This function releases the resources acquired inadapf_init. ATFA willcall it before closing the access to the DSO, in order to prevent memoryleaking. The pointer passed toadapf_close is the one returned byadapf_init, and the value returned fromadapf_close should be zeroif it fails and nonzero otherwise.

float adapf_run(void *data, float sample, float y)

This is the function which implements the algorithm itself. Given anaudio sample from the input of the filter (sample) and an audiosample from the desired signal (y),adapf_run should calculatethe filter output, sayy_hat, and then return the errory - y_hat.

This function can read from and write to*data in order to accessand/or update values such as the filter coefficients, the inputvector (with memory), etc.

adapf_run is the only function that's called from within the audiorun-time loop. The other functions are all allowed to requestresources to the OS, and perform slow operations in general, but thisone isn't.

void adapf_getw(void *data, float **begin, unsigned *n)

This function is called by ATFA in order to introspect the filtercoefficients. It must place at*begin a pointer to the first elementof the array of filter coefficients, and at*n the number of elementsthat can be read from that array (that is, the number of coefficients,which isN+1, whereN is the filter order).

const char *adapf_title()

This function should just return a static string containing a short"name" for the adaptive filter algorithm. For example, if the algorithmis an implementation of the NLMS algorithm withmu=0.7 andDelta=1.5, then the returned string could be"NLMS: 0.7, 1.5" ormaybe just"NLMS".

const char *adapf_listing()

This function must return a static string, just likeadapf_title. Thestring returned fromadapf_listing is an algorithmic description ofthe adaptive filter, which is shown to the users when they click the"Show filter code" button in ATFA.

Examples

Inside theLMS/,NLMS/, andAP/ directories,you will find C++ source files implementing these three adaptivefiltering algorithms.

Theno-op/ direcory contains a file for a dummy algorithm,which does nothing at all. The source file insidestatic-w/ implements a static (instead of an adaptive)filter (the filter coefficients are never updated). Both of these canbe used for test purposes.

All of the above are implemented in C++. SeeLMS-C/ for anexample using plain C.

How to compile an algorithm

To compile an algorithm into a DSO file to be used with ATFA, you can doso manually—just generate an*.so that exports all of the functionsmentioned above—, or you can use thebuild.py helper script.

To use this script, open a shell inside the directory containing yoursource file(s), and then run the script. For example, to compile theLMS/ algorithm, type:

$cd atfa-examples$cd LMS$ python3 ../build.py

By default,build.py will compile and link all of the*.c and*.cpp files in the current directory. To use a custom set of sources,just pass them as arguments:

$ python3 ../build.py source1.cpp source2.cpp

The full set of source files specified on the command-line (or presentin the directory, if none is specified) must contain the definitions ofall of the functions mentionedabove, exceptatfa_title andatfa_listing. These will be automatically generated.

By default, the title is made up based on the command line, and thealgorithm listing is just a transcription of the source files. If youwant to use a custom title, use the-t/--title flag. If you want tospecify a custom file containing the listing, use the-l/--listingflag:

$ python3 ../build.py --title"My Algorithm" --listing my_algorithm.txt

If you want to provide theatfa_title oratfa_listing functionsyourself, use the+t or+l flags:

$ python3 ../build.py main_source.cpp title_and_listing.cpp +tl

For more options, type:

$ python3 ../build.py --help

Usingbuild-all.sh

You can also use the convenience scriptbuild-all.sh. This scriptwill just callpython3 ../build.py from inside each subdirectory of thecurrent directory. It will also pass the name of the directory in the--title flag.

About

Example algorithms for the ATFA (Real-time testing environment for adaptive filters)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp