aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <mnoi@users.sourceforge.net>2006-08-02 14:02:28 +0000
committerN.N. <mnoi@users.sourceforge.net>2006-08-02 14:02:28 +0000
commitd056668887fde2dd2a784ef3507ec35e98131439 (patch)
tree43d175f1e7b56ed40c3a5d5c1a4acc55fee87cd5
no messagesvn2git-root
svn path=/trunk/externals/iem/iem_adaptfilt/; revision=5455
-rw-r--r--.DS_Storebin0 -> 6148 bytes
-rw-r--r--AUTHORS.txt2
-rw-r--r--GnuGPL.txt340
-rw-r--r--LICENSE.txt22
-rw-r--r--VERSION.txt1
-rw-r--r--doc/adapt_filt_lib.pdfbin0 -> 791752 bytes
-rw-r--r--help/.DS_Storebin0 -> 6148 bytes
-rw-r--r--help/NLMSCC~-help.pd274
-rw-r--r--help/NLMS~-help.pd199
-rw-r--r--help/n_CLNLMS~-help.pd271
-rw-r--r--help/n_CNLMS~-help.pd261
-rw-r--r--src/.DS_Storebin0 -> 6148 bytes
-rw-r--r--src/iem_adaptfilt.c46
-rw-r--r--src/iemlib.h102
-rw-r--r--src/makefile.txt50
-rw-r--r--src/makefile_lin51
-rw-r--r--src/makefile_win44
-rw-r--r--src/makefile_win.txt43
-rw-r--r--src/sigNLMS.c337
-rw-r--r--src/sigNLMSCC.c390
-rw-r--r--src/sign_CLNLMS.c503
-rw-r--r--src/sign_CNLMS.c482
22 files changed, 3418 insertions, 0 deletions
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..d8f888f
--- /dev/null
+++ b/.DS_Store
Binary files differ
diff --git a/AUTHORS.txt b/AUTHORS.txt
new file mode 100644
index 0000000..85b8e21
--- /dev/null
+++ b/AUTHORS.txt
@@ -0,0 +1,2 @@
+markus noisternig <noisternig AT iem DOT at>
+thomas musil <musil AT iem DOT at>
diff --git a/GnuGPL.txt b/GnuGPL.txt
new file mode 100644
index 0000000..d60c31a
--- /dev/null
+++ b/GnuGPL.txt
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..a22066e
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,22 @@
+iem_adaptfilt - pd-objects for adaptive filtering
+
+Copyright (C) 2004-2006 markus noisternig (noisternig AT iem DOT at)
+Copyright (C) 2004-2006 thomas musil (musil AT iem DOT at)
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+In the official flext distribution, the GNU General Public License is
+in the file GnuGPL.txt
+
diff --git a/VERSION.txt b/VERSION.txt
new file mode 100644
index 0000000..1010473
--- /dev/null
+++ b/VERSION.txt
@@ -0,0 +1 @@
+1.02
diff --git a/doc/adapt_filt_lib.pdf b/doc/adapt_filt_lib.pdf
new file mode 100644
index 0000000..c53821f
--- /dev/null
+++ b/doc/adapt_filt_lib.pdf
Binary files differ
diff --git a/help/.DS_Store b/help/.DS_Store
new file mode 100644
index 0000000..5008ddf
--- /dev/null
+++ b/help/.DS_Store
Binary files differ
diff --git a/help/NLMSCC~-help.pd b/help/NLMSCC~-help.pd
new file mode 100644
index 0000000..78cdff4
--- /dev/null
+++ b/help/NLMSCC~-help.pd
@@ -0,0 +1,274 @@
+#N canvas 284 42 905 668 10;
+#N canvas 0 0 450 300 graph1 0;
+#X array W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 34 496 graph;
+#X msg 26 246 update \$1;
+#X msg 103 256 beta \$1;
+#X obj 273 25 tgl 15 0 empty empty empty 0 -6 0 8 -225280 -1 -1 0 1
+;
+#X obj 273 46 dsp;
+#X floatatom 273 92 5 0 0 0 - - -;
+#X floatatom 286 71 5 0 0 0 - - -;
+#X obj 277 464 bng 15 150 20 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 423 290 2.arg: <float> learn-rate = beta;
+#X obj 54 276 noise~;
+#X obj 26 59 vradio 15 1 0 8 empty empty empty 0 -6 0 8 -225280 -1
+-1 0;
+#N canvas 165 115 464 314 /SUBPATCH/ 0;
+#X obj 76 61 inlet;
+#X msg 32 163 0;
+#X msg 63 159 1;
+#X msg 97 158 2;
+#X msg 132 156 4;
+#X msg 159 157 8;
+#X msg 191 162 16;
+#X msg 219 164 32;
+#X msg 248 165 64;
+#X obj 76 84 sel 0 1 2 3 4 5 6 7;
+#X obj 32 217 outlet;
+#X connect 0 0 9 0;
+#X connect 1 0 10 0;
+#X connect 2 0 10 0;
+#X connect 3 0 10 0;
+#X connect 4 0 10 0;
+#X connect 5 0 10 0;
+#X connect 6 0 10 0;
+#X connect 7 0 10 0;
+#X connect 8 0 10 0;
+#X connect 9 0 1 0;
+#X connect 9 1 2 0;
+#X connect 9 2 3 0;
+#X connect 9 3 4 0;
+#X connect 9 4 5 0;
+#X connect 9 5 6 0;
+#X connect 9 6 7 0;
+#X connect 9 7 8 0;
+#X restore 26 206 pd;
+#X text 35 38 internal downsampling of update;
+#X msg 97 338 gamma \$1;
+#N canvas 0 0 450 300 graph1 0;
+#X array W_top 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 626 495 graph;
+#N canvas 0 0 450 300 graph1 0;
+#X array W_bottom 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 294 495 graph;
+#X text 76 364 input signal;
+#X text 191 363 desired signal;
+#N canvas 0 0 450 300 graph1 0;
+#X array IR 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 372 32 graph;
+#X obj 55 441 unsig~;
+#X floatatom 55 467 9 0 0 0 - - -;
+#X obj 165 440 unsig~;
+#X floatatom 165 466 9 0 0 0 - - -;
+#X text 27 364 x(n);
+#X text 282 363 d(n);
+#X text 30 409 y(n) = W * x(n);
+#X obj 277 292 FIR~ IR 32;
+#X obj 589 135 loadbang;
+#X text 473 280 (array-sizes have to be >= then FIR_size);
+#X text 423 270 1.arg: <float> number of order of FIR-filter;
+#X text 43 72 update every sample;
+#X text 43 57 stop \, no update;
+#X text 43 87 update every 2nd sample;
+#X text 43 102 update every 4th sample;
+#X text 43 117 update every 8th sample;
+#X text 43 132 update every 16th sample;
+#X text 43 147 update every 32nd sample;
+#X text 43 162 update every 64th sample;
+#N canvas 0 0 474 324 /SUBPATCH/ 0;
+#X obj 48 46 inlet;
+#X obj 205 47 inlet;
+#X msg 205 71 \; IR const 0;
+#X msg 48 120 \; IR 0 0 0 0 0.314287 0.8 0.75 0 0 0 0 -0.7 -0.65 0
+0 0 0.157143 0.128572 0 0 -0.128572 -0.1 0 0 0 0 0 0 0 0 0 0 0 0 0
+0 0 0 0 0 0;
+#X obj 92 84 loadbang;
+#X connect 0 0 3 0;
+#X connect 1 0 2 0;
+#X connect 4 0 3 0;
+#X restore 590 110 pd;
+#X obj 603 92 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 620 89 clear;
+#X obj 590 73 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 607 70 load;
+#X text 652 79 IR;
+#X text 5 396 filtered output signal;
+#X text 169 396 error signal;
+#X text 143 408 e(n) = d(n) - W * x(n);
+#X text 294 458 constrain;
+#X text 294 468 coefficients;
+#N canvas 0 0 825 416 /SUBPATCH/ 0;
+#X obj 43 39 inlet;
+#X obj 446 39 inlet;
+#X obj 92 84 loadbang;
+#X msg 54 114 \; W_top 0 1 0.928572 0.885714 0.857142 0.828571 0.799999
+0.785713 0.757141 0.742855 0.72857 0.714284 0.699998 0.685712 0.671426
+0.642854 0.628569 0.599997 0.571425 0.557139 0.528568 0.514282 0.499996
+0.499996 0.48571 0.471424 0.457138 0.428567 0.414281 0.399995 0.385709
+0.371423 0.357137 0.342851 0.328565 0.31428 0.31428 0.31428 0.31428
+0.299994 0.299994;
+#X msg 43 226 \; W_bottom 0 -1 -0.971428 -0.942857 -0.914286 -0.885714
+-0.857143 -0.828572 -0.814286 -0.785715 -0.757143 -0.728572 -0.7 -0.671429
+-0.657143 -0.642858 -0.614286 -0.585715 -0.571429 -0.557144 -0.528572
+-0.514287 -0.500001 -0.485715 -0.471429 -0.457144 -0.442858 -0.428572
+-0.428572 -0.400001 -0.400001 -0.385715 -0.371429 -0.371429 -0.357144
+-0.357144 -0.342858 -0.328572 -0.314287 -0.285715 -0.285715;
+#X msg 446 226 \; W_bottom 0 -1 -0.857143 -0.728572 -0.671429 -0.614286
+-0.585715 -0.557143 -0.514286 -0.485715 -0.471429 -0.471429 -0.442858
+-0.428572 -0.400001 -0.371429 -0.342858 -0.328572 -0.314286 -0.285715
+-0.285715 -0.271429 -0.271429 -0.271429 -0.271429 -0.271429 -0.271429
+-0.257144 -0.242858 -0.228572 -0.214286 -0.214286 -0.214286 -0.200001
+-0.214287 -0.200001 -0.200001 -0.185715 -0.171429 -0.171429 -0.171429
+;
+#X msg 459 113 \; W_top 0 1 0.842856 0.785713 0.699998 0.642854 0.571425
+0.514282 0.457138 0.442852 0.414281 0.385709 0.342851 0.285708 0.257136
+0.214279 0.199993 0.171421 0.157135 0.142849 0.128564 0.142849 0.142849
+0.142849 0.142849 0.142849 0.128564 0.128564 0.128564 0.128564 0.128564
+0.128564 0.142849 0.142849 0.142849 0.142849 0.157135 0.157135 0.157135
+0.142849 0.142849;
+#X connect 0 0 4 0;
+#X connect 0 0 3 0;
+#X connect 1 0 6 0;
+#X connect 1 0 5 0;
+#X connect 2 0 3 0;
+#X connect 2 0 4 0;
+#X restore 506 576 pd;
+#X obj 519 558 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 506 539 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X msg 277 423 0;
+#X obj 277 443 speedlim 100;
+#X text 499 522 top & bottom;
+#X text 523 536 nonconstrained;
+#X text 536 555 constrained;
+#X obj 84 413 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X obj 237 412 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#N canvas 0 0 470 320 /SUBPATCH/ 0;
+#X obj 137 73 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
+;
+#X msg 137 115 39;
+#X msg 137 156 \$1 39;
+#X msg 136 53 1;
+#X obj 137 92 metro 200;
+#X obj 136 24 inlet;
+#X obj 137 135 tabread W;
+#X obj 137 180 tabwrite W;
+#X connect 0 0 4 0;
+#X connect 1 0 6 0;
+#X connect 2 0 7 0;
+#X connect 3 0 0 0;
+#X connect 4 0 1 0;
+#X connect 5 0 3 0;
+#X connect 6 0 2 0;
+#X restore 589 156 pd;
+#X text 614 162 update of W;
+#X text 613 151 graphical;
+#X text 423 310 4.arg: <symbol> table-name of W;
+#X text 423 320 5.arg: <symbol> table-name of lower boundary of W;
+#X text 423 330 6.arg: <symbol> table-name of upper boundary of W;
+#X text 423 300 3.arg: <float> minimum input value gamma;
+#X text 133 318 minimum input value;
+#X msg 103 219 0.1;
+#X msg 97 300 1e-05;
+#X text 156 257 beta [0 .. 2];
+#X text 153 337 gamma [0 .. 1];
+#X obj 458 250 cnv 15 68 17 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#N canvas 0 0 758 363 FORMULAS 0;
+#X obj 168 54 cnv 15 150 40 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 168 125 cnv 15 270 50 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 168 207 cnv 15 510 90 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X text 281 131 beta;
+#X text 232 148 >;
+#X text 233 146 _;
+#X text 233 140 _;
+#X text 278 143 2;
+#X text 341 143 2;
+#X text 312 148 gamma * blocksize);
+#X text 295 148 +;
+#X text 244 148 x[n-i];
+#X text 175 137 my(n) =;
+#X text 224 132 _________________________________;
+#X text 29 138 normalized learn rate:;
+#X text 246 243 <;
+#X text 250 237 |;
+#X text 250 249 |;
+#X text 250 230 |;
+#X text 250 256 |;
+#X text 250 270 |;
+#X text 250 223 |;
+#X text 254 206 _;
+#X text 253 270 _;
+#X text 271 211 W > W_top;
+#X text 265 275 W < W_bottom;
+#X text 260 246 &&(W <= W_top);
+#X text 256 235 (W >= W_bottom);
+#X text 175 243 W(k+1 \, i) =;
+#X text 250 216 |;
+#X text 250 263 |;
+#X text 346 275 ...... W(k+1 \, i) = W_botton(i);
+#X text 334 212 ........ W(k+1 \, i) = W_top(i);
+#X text 174 56 y(n) = W * x(n);
+#X obj 226 58 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 174 74 e(n) = d(n) - W * x(n);
+#X obj 268 76 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 120 75 error:;
+#X text 117 57 output:;
+#X text 27 242 coefficient iteration:;
+#X text 358 243 .... W(k+1 \, i) = W(k \, i) + my(n)* e(n)* x(n);
+#X restore 457 249 pd FORMULAS;
+#X obj 54 380 NLMSCC~ 32 0.1 1e-05 W W_bottom W_top;
+#X obj 103 239 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 103 239 5 0 2 0 - - -;
+#X text 139 238 learn-rate;
+#X obj 97 320 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 97 320 5 0 2 0 - - -;
+#X floatatom 26 227 5 0 0 0 - - -;
+#X text 426 221 Normalized Least Mean Square (linear adaptive FIR-filter)
+;
+#X text 455 232 with Coefficient Constraint;
+#X text 422 350 (C) 2005 \, m.noisternig & t.musil \, IEM \, Graz \,
+Austria;
+#X text 450 363 [noisternig \, musil]_AT_iem.at;
+#X connect 1 0 73 0;
+#X connect 2 0 73 0;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X connect 4 1 6 0;
+#X connect 9 0 26 0;
+#X connect 9 0 73 0;
+#X connect 10 0 11 0;
+#X connect 11 0 79 0;
+#X connect 13 0 73 0;
+#X connect 19 0 20 0;
+#X connect 21 0 22 0;
+#X connect 26 0 73 1;
+#X connect 27 0 59 0;
+#X connect 39 0 38 1;
+#X connect 41 0 38 0;
+#X connect 50 0 49 1;
+#X connect 51 0 49 0;
+#X connect 52 0 53 0;
+#X connect 53 0 7 0;
+#X connect 67 0 75 0;
+#X connect 68 0 78 0;
+#X connect 73 0 19 0;
+#X connect 73 1 21 0;
+#X connect 73 2 52 0;
+#X connect 75 0 2 0;
+#X connect 78 0 13 0;
+#X connect 79 0 1 0;
diff --git a/help/NLMS~-help.pd b/help/NLMS~-help.pd
new file mode 100644
index 0000000..97702f4
--- /dev/null
+++ b/help/NLMS~-help.pd
@@ -0,0 +1,199 @@
+#N canvas 23 7 909 523 10;
+#N canvas 0 0 450 300 graph1 0;
+#X array W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 454 335 graph;
+#X msg 25 245 update \$1;
+#X msg 102 255 beta \$1;
+#X obj 272 24 tgl 15 0 empty empty empty 0 -6 0 8 -225280 -1 -1 0 1
+;
+#X obj 272 45 dsp;
+#X floatatom 272 91 5 0 0 0 - - -;
+#X floatatom 285 70 5 0 0 0 - - -;
+#X obj 276 463 bng 15 150 20 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 453 230 2.arg: <float> learn-rate = beta;
+#X obj 53 275 noise~;
+#X obj 25 58 vradio 15 1 0 8 empty empty empty 0 -6 0 8 -225280 -1
+-1 0;
+#N canvas 165 115 464 314 /SUBPATCH/ 0;
+#X obj 76 61 inlet;
+#X msg 32 163 0;
+#X msg 63 159 1;
+#X msg 97 158 2;
+#X msg 132 156 4;
+#X msg 159 157 8;
+#X msg 191 162 16;
+#X msg 219 164 32;
+#X msg 248 165 64;
+#X obj 76 84 sel 0 1 2 3 4 5 6 7;
+#X obj 32 217 outlet;
+#X connect 0 0 9 0;
+#X connect 1 0 10 0;
+#X connect 2 0 10 0;
+#X connect 3 0 10 0;
+#X connect 4 0 10 0;
+#X connect 5 0 10 0;
+#X connect 6 0 10 0;
+#X connect 7 0 10 0;
+#X connect 8 0 10 0;
+#X connect 9 0 1 0;
+#X connect 9 1 2 0;
+#X connect 9 2 3 0;
+#X connect 9 3 4 0;
+#X connect 9 4 5 0;
+#X connect 9 5 6 0;
+#X connect 9 6 7 0;
+#X connect 9 7 8 0;
+#X restore 25 205 pd;
+#X text 34 37 internal downsampling of update;
+#X msg 96 337 gamma \$1;
+#X text 75 363 input signal;
+#X text 190 362 desired signal;
+#N canvas 0 0 450 300 graph1 0;
+#X array IR 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 367 11 graph;
+#X obj 54 440 unsig~;
+#X floatatom 54 466 9 0 0 0 - - -;
+#X obj 174 439 unsig~;
+#X floatatom 174 465 9 0 0 0 - - -;
+#X text 26 363 x(n);
+#X text 281 362 d(n);
+#X text 29 408 y(n) = W * x(n);
+#X obj 276 291 FIR~ IR 32;
+#X obj 618 73 loadbang;
+#X text 503 220 (array-sizes have to be >= then FIR_size);
+#X text 453 210 1.arg: <float> number of order of FIR-filter;
+#X text 42 71 update every sample;
+#X text 42 56 stop \, no update;
+#X text 42 86 update every 2nd sample;
+#X text 42 101 update every 4th sample;
+#X text 42 116 update every 8th sample;
+#X text 42 131 update every 16th sample;
+#X text 42 146 update every 32nd sample;
+#X text 42 161 update every 64th sample;
+#N canvas 0 0 474 324 /SUBPATCH/ 0;
+#X obj 48 46 inlet;
+#X obj 205 47 inlet;
+#X msg 205 71 \; IR const 0;
+#X msg 48 120 \; IR 0 0 0 0 0.314287 0.8 0.75 0 0 0 0 -0.7 -0.65 0
+0 0 0.157143 0.128572 0 0 -0.128572 -0.1 0 0 0 0 0 0 0 0 0 0 0 0 0
+0 0 0 0 0 0;
+#X obj 92 84 loadbang;
+#X connect 0 0 3 0;
+#X connect 1 0 2 0;
+#X connect 4 0 3 0;
+#X restore 619 48 pd;
+#X obj 632 30 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 649 27 clear;
+#X obj 619 11 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 636 8 load;
+#X text 644 50 IR;
+#X text 4 395 filtered output signal;
+#X text 178 395 error signal;
+#X text 152 407 e(n) = d(n) - W * x(n);
+#X text 293 457 constrain;
+#X text 293 467 coefficients;
+#X msg 276 422 0;
+#X obj 276 442 speedlim 100;
+#X obj 83 412 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X obj 247 411 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#N canvas 0 0 470 320 /SUBPATCH/ 0;
+#X obj 137 73 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
+;
+#X msg 137 115 39;
+#X msg 137 156 \$1 39;
+#X msg 136 53 1;
+#X obj 137 92 metro 200;
+#X obj 136 24 inlet;
+#X obj 137 135 tabread W;
+#X obj 137 180 tabwrite W;
+#X connect 0 0 4 0;
+#X connect 1 0 6 0;
+#X connect 2 0 7 0;
+#X connect 3 0 0 0;
+#X connect 4 0 1 0;
+#X connect 5 0 3 0;
+#X connect 6 0 2 0;
+#X restore 618 94 pd;
+#X text 643 100 update of W;
+#X text 642 89 graphical;
+#X text 453 250 4.arg: <symbol> table-name of W;
+#X text 453 240 3.arg: <float> minimum input value gamma;
+#X text 132 317 minimum input value;
+#X msg 102 218 0.1;
+#X msg 96 299 1e-05;
+#X text 155 256 beta [0 .. 2];
+#X text 152 336 gamma [0 .. 1];
+#X obj 455 187 cnv 15 68 17 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#N canvas 0 0 499 295 FORMULAS 0;
+#X obj 167 52 cnv 15 150 40 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 167 123 cnv 15 270 50 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 167 205 cnv 15 260 30 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X text 280 129 beta;
+#X text 231 146 >;
+#X text 232 144 _;
+#X text 232 138 _;
+#X text 277 141 2;
+#X text 340 141 2;
+#X text 311 146 gamma * blocksize);
+#X text 294 146 +;
+#X text 243 146 x[n-i];
+#X text 174 135 my(n) =;
+#X text 223 130 _________________________________;
+#X text 28 136 normalized learn rate:;
+#X text 173 54 y(n) = W * x(n);
+#X obj 225 56 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 173 72 e(n) = d(n) - W * x(n);
+#X obj 267 74 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 119 73 error:;
+#X text 116 55 output:;
+#X text 26 210 coefficient iteration:;
+#X text 176 213 W(k+1 \, i) = W(k \, i) + my(n)* e(n)* x(n);
+#X restore 455 187 pd FORMULAS;
+#X obj 102 238 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 102 238 5 0 2 0 - - -;
+#X text 138 237 learn-rate;
+#X obj 96 319 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 96 319 5 0 2 0 - - -;
+#X floatatom 25 226 5 0 0 0 - - -;
+#X text 455 169 Normalized Least Mean Square (linear adaptive FIR-filter)
+;
+#X obj 53 379 NLMS~ 32 0.1 1e-05 W;
+#X text 451 268 (C) 2005 \, m.noisternig & t.musil \, IEM \, Graz \,
+Austria;
+#X text 479 281 [noisternig \, musil]_AT_iem.at;
+#X connect 1 0 70 0;
+#X connect 2 0 70 0;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X connect 4 1 6 0;
+#X connect 9 0 24 0;
+#X connect 9 0 70 0;
+#X connect 10 0 11 0;
+#X connect 11 0 68 0;
+#X connect 13 0 70 0;
+#X connect 17 0 18 0;
+#X connect 19 0 20 0;
+#X connect 24 0 70 1;
+#X connect 25 0 51 0;
+#X connect 37 0 36 1;
+#X connect 39 0 36 0;
+#X connect 47 0 48 0;
+#X connect 48 0 7 0;
+#X connect 57 0 64 0;
+#X connect 58 0 67 0;
+#X connect 64 0 2 0;
+#X connect 67 0 13 0;
+#X connect 68 0 1 0;
+#X connect 70 0 17 0;
+#X connect 70 1 19 0;
diff --git a/help/n_CLNLMS~-help.pd b/help/n_CLNLMS~-help.pd
new file mode 100644
index 0000000..ca40d31
--- /dev/null
+++ b/help/n_CLNLMS~-help.pd
@@ -0,0 +1,271 @@
+#N canvas 18 0 998 718 10;
+#N canvas 0 0 450 300 graph1 0;
+#X array 1_W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 49 517 graph;
+#X msg 25 245 update \$1;
+#X msg 102 255 beta \$1;
+#X obj 438 26 tgl 15 0 empty empty empty 0 -6 0 8 -225280 -1 -1 0 1
+;
+#X obj 438 47 dsp;
+#X floatatom 438 93 5 0 0 0 - - -;
+#X floatatom 451 72 5 0 0 0 - - -;
+#X obj 437 461 bng 15 150 20 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 53 275 noise~;
+#X obj 25 58 vradio 15 1 0 8 empty empty empty 0 -6 0 8 -225280 -1
+-1 0;
+#N canvas 165 115 464 314 /SUBPATCH/ 0;
+#X obj 76 61 inlet;
+#X msg 32 163 0;
+#X msg 63 159 1;
+#X msg 97 158 2;
+#X msg 132 156 4;
+#X msg 159 157 8;
+#X msg 191 162 16;
+#X msg 219 164 32;
+#X msg 248 165 64;
+#X obj 76 84 sel 0 1 2 3 4 5 6 7;
+#X obj 32 217 outlet;
+#X connect 0 0 9 0;
+#X connect 1 0 10 0;
+#X connect 2 0 10 0;
+#X connect 3 0 10 0;
+#X connect 4 0 10 0;
+#X connect 5 0 10 0;
+#X connect 6 0 10 0;
+#X connect 7 0 10 0;
+#X connect 8 0 10 0;
+#X connect 9 0 1 0;
+#X connect 9 1 2 0;
+#X connect 9 2 3 0;
+#X connect 9 3 4 0;
+#X connect 9 4 5 0;
+#X connect 9 5 6 0;
+#X connect 9 6 7 0;
+#X connect 9 7 8 0;
+#X restore 25 205 pd;
+#X text 7 39 internal downsampling of update;
+#X msg 60 337 gamma \$1;
+#X text 75 363 input signal;
+#X text 320 362 desired signal;
+#N canvas 0 0 450 300 graph1 0;
+#X array IR 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 225 23 graph;
+#X obj 54 460 unsig~;
+#X floatatom 54 486 9 0 0 0 - - -;
+#X obj 140 460 unsig~;
+#X floatatom 140 486 9 0 0 0 - - -;
+#X text 411 362 d(n);
+#X obj 777 283 loadbang;
+#X text 687 432 (array-sizes have to be >= then FIR_size);
+#X text 42 71 update every sample;
+#X text 42 56 stop \, no update;
+#X text 42 86 update every 2nd sample;
+#X text 42 101 update every 4th sample;
+#X text 42 116 update every 8th sample;
+#X text 42 131 update every 16th sample;
+#X text 42 146 update every 32nd sample;
+#X text 42 161 update every 64th sample;
+#N canvas 0 0 486 336 /SUBPATCH/ 0;
+#X obj 48 46 inlet;
+#X obj 205 47 inlet;
+#X msg 205 71 \; IR const 0;
+#X obj 92 84 loadbang;
+#X msg 48 120 \; IR 0 0 0 0 0 0 0.314287 0.8 0.75 0 0 0 0 -0.7 -0.65
+0 0 0 0.157143 0.128572 0 0 -0.128572 -0.1 0 0 0 0 0 0 0 0 0 0 0 0
+0 0 0 0 0;
+#X connect 0 0 4 0;
+#X connect 1 0 2 0;
+#X connect 3 0 4 0;
+#X restore 778 258 pd;
+#X obj 791 240 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 808 237 clear;
+#X obj 778 221 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 795 218 load;
+#X text 840 227 IR;
+#X text 4 395 filtered output signal;
+#X text 324 394 error signal;
+#X text 454 455 constrain;
+#X text 454 465 coefficients;
+#X msg 437 420 0;
+#X obj 437 440 speedlim 100;
+#X obj 95 412 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#N canvas 0 0 478 328 /SUBPATCH/ 0;
+#X obj 137 73 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
+;
+#X msg 137 115 39;
+#X msg 92 190 \$1 39;
+#X msg 136 53 1;
+#X obj 137 92 metro 200;
+#X obj 136 24 inlet;
+#X obj 92 169 tabread 1_W;
+#X obj 92 214 tabwrite 1_W;
+#X msg 177 192 \$1 39;
+#X msg 260 191 \$1 39;
+#X obj 260 170 tabread 3_W;
+#X obj 260 215 tabwrite 3_W;
+#X obj 177 171 tabread 2_W;
+#X obj 177 216 tabwrite 2_W;
+#X connect 0 0 4 0;
+#X connect 1 0 6 0;
+#X connect 1 0 12 0;
+#X connect 1 0 10 0;
+#X connect 2 0 7 0;
+#X connect 3 0 0 0;
+#X connect 4 0 1 0;
+#X connect 5 0 3 0;
+#X connect 6 0 2 0;
+#X connect 8 0 13 0;
+#X connect 9 0 11 0;
+#X connect 10 0 9 0;
+#X connect 12 0 8 0;
+#X restore 777 304 pd;
+#X text 802 310 update of W;
+#X text 801 299 graphical;
+#X text 96 317 minimum input value;
+#X msg 102 218 0.1;
+#X msg 60 299 1e-05;
+#X text 155 256 beta [0 .. 2];
+#X text 116 336 gamma [0 .. 1];
+#X obj 527 47 cnv 15 68 17 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#N canvas 0 0 499 295 FORMULAS 0;
+#X obj 167 52 cnv 15 150 40 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 167 123 cnv 15 270 50 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 167 205 cnv 15 260 30 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X text 280 129 beta;
+#X text 231 146 >;
+#X text 232 144 _;
+#X text 232 138 _;
+#X text 277 141 2;
+#X text 340 141 2;
+#X text 311 146 gamma * blocksize);
+#X text 294 146 +;
+#X text 243 146 x[n-i];
+#X text 174 135 my(n) =;
+#X text 223 130 _________________________________;
+#X text 8 135 normalized learn rate:;
+#X text 173 54 y(n) = W * x(n);
+#X obj 225 56 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 173 72 e(n) = d(n) - W * x(n);
+#X obj 267 74 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 119 73 error:;
+#X text 116 55 output:;
+#X text 7 210 coefficient iteration:;
+#X text 176 213 W(k+1 \, i) = leakage*W(k \, i) + my(n)* e(n)* x(n)
+;
+#X restore 527 47 pd FORMULAS;
+#X obj 102 238 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 102 238 5 0 2 0 - - -;
+#X text 138 237 learn-rate;
+#X obj 60 319 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 60 319 5 0 1 0 - - -;
+#X floatatom 25 226 5 0 0 0 - - -;
+#X text 526 29 Normalized Least Mean Square (linear adaptive FIR-filter)
+;
+#N canvas 0 0 450 300 graph1 0;
+#X array 2_W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 299 517 graph;
+#N canvas 0 0 450 300 graph1 0;
+#X array 3_W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 549 517 graph;
+#X obj 229 461 unsig~;
+#X floatatom 229 487 9 0 0 0 - - -;
+#X obj 319 459 unsig~;
+#X floatatom 319 485 9 0 0 0 - - -;
+#X obj 253 233 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 253 233 5 0 10000 0 - - -;
+#X msg 253 251 kappa \$1;
+#X msg 253 213 1;
+#X obj 408 291 FIR~ IR 32;
+#X obj 171 291 z~ 2;
+#X obj 289 291 z~ 4;
+#X text 26 363 x1(n);
+#X text 257 363 x3(n);
+#X text 176 362 x2(n);
+#X text 24 408 y1(n) = 1_W * x1(n);
+#X obj 181 427 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X obj 271 401 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 110 423 y2(n) = 2_W * x2(n);
+#X text 200 397 y3(n) = 3_W * x3(n);
+#X obj 360 423 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 326 419 - 1_W * x1(n);
+#X text 297 408 e(n) = d(n);
+#X obj 360 433 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 326 429 - 2_W * x2(n);
+#X obj 360 443 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 326 439 - 3_W * x3(n);
+#X text 526 18 Multi Channel Constraint;
+#X obj 53 380 n_CLNLMS~ 3 32 0.1 1e-05 1 0.95 W ______________________
+;
+#X text 472 230 minimum input value;
+#X obj 436 232 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 436 232 5 0 10000 0 - - -;
+#X msg 436 212 1;
+#X msg 436 250 leakage \$1;
+#X text 516 254 leakage [0 .. 1];
+#X text 520 163 (C) 2005 \, m.noisternig & t.musil \, IEM \, Graz \,
+Austria;
+#X text 548 176 [noisternig \, musil]_AT_iem.at;
+#X text 525 69 1.arg: <float> number of channels n;
+#X text 525 82 2.arg: <float> number of order of FIR-filter;
+#X text 525 96 3.arg: <float> learn-rate = beta;
+#X text 318 250 kappa;
+#X text 289 231 constraint;
+#X text 526 121 5.arg: <float> constraint = kappa;
+#X text 525 108 4.arg: <float> regularization parameter = gamma;
+#X text 526 133 6.arg: <float> leakage;
+#X text 526 146 7.arg: <symbol> table-name of W;
+#X connect 1 0 90 0;
+#X connect 2 0 90 0;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X connect 4 1 6 0;
+#X connect 8 0 71 0;
+#X connect 8 0 72 0;
+#X connect 8 0 73 0;
+#X connect 8 0 90 0;
+#X connect 9 0 10 0;
+#X connect 10 0 59 0;
+#X connect 12 0 90 0;
+#X connect 16 0 17 0;
+#X connect 18 0 19 0;
+#X connect 21 0 44 0;
+#X connect 32 0 31 1;
+#X connect 34 0 31 0;
+#X connect 41 0 42 0;
+#X connect 42 0 7 0;
+#X connect 48 0 55 0;
+#X connect 49 0 58 0;
+#X connect 55 0 2 0;
+#X connect 58 0 12 0;
+#X connect 59 0 1 0;
+#X connect 63 0 64 0;
+#X connect 65 0 66 0;
+#X connect 68 0 69 0;
+#X connect 69 0 90 0;
+#X connect 70 0 68 0;
+#X connect 71 0 90 3;
+#X connect 72 0 90 1;
+#X connect 73 0 90 2;
+#X connect 90 0 16 0;
+#X connect 90 1 18 0;
+#X connect 90 2 63 0;
+#X connect 90 3 65 0;
+#X connect 90 4 41 0;
+#X connect 93 0 95 0;
+#X connect 94 0 93 0;
+#X connect 95 0 90 0;
diff --git a/help/n_CNLMS~-help.pd b/help/n_CNLMS~-help.pd
new file mode 100644
index 0000000..15c42c9
--- /dev/null
+++ b/help/n_CNLMS~-help.pd
@@ -0,0 +1,261 @@
+#N canvas 170 22 1021 882 10;
+#N canvas 0 0 450 300 graph1 0;
+#X array 1_W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 64 519 graph;
+#X msg 40 247 update \$1;
+#X msg 117 257 beta \$1;
+#X obj 456 26 tgl 15 0 empty empty empty 0 -6 0 8 -225280 -1 -1 0 1
+;
+#X obj 456 47 dsp;
+#X floatatom 456 93 5 0 0 0 - - -;
+#X floatatom 469 72 5 0 0 0 - - -;
+#X obj 452 463 bng 15 150 20 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X obj 68 277 noise~;
+#X obj 40 60 vradio 15 1 0 8 empty empty empty 0 -6 0 8 -225280 -1
+-1 0;
+#N canvas 165 115 464 314 /SUBPATCH/ 0;
+#X obj 76 61 inlet;
+#X msg 32 163 0;
+#X msg 63 159 1;
+#X msg 97 158 2;
+#X msg 132 156 4;
+#X msg 159 157 8;
+#X msg 191 162 16;
+#X msg 219 164 32;
+#X msg 248 165 64;
+#X obj 76 84 sel 0 1 2 3 4 5 6 7;
+#X obj 32 217 outlet;
+#X connect 0 0 9 0;
+#X connect 1 0 10 0;
+#X connect 2 0 10 0;
+#X connect 3 0 10 0;
+#X connect 4 0 10 0;
+#X connect 5 0 10 0;
+#X connect 6 0 10 0;
+#X connect 7 0 10 0;
+#X connect 8 0 10 0;
+#X connect 9 0 1 0;
+#X connect 9 1 2 0;
+#X connect 9 2 3 0;
+#X connect 9 3 4 0;
+#X connect 9 4 5 0;
+#X connect 9 5 6 0;
+#X connect 9 6 7 0;
+#X connect 9 7 8 0;
+#X restore 40 207 pd;
+#X text 22 41 internal downsampling of update;
+#X msg 75 339 gamma \$1;
+#X text 90 365 input signal;
+#X text 335 364 desired signal;
+#N canvas 0 0 450 300 graph1 0;
+#X array IR 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 240 25 graph;
+#X obj 69 462 unsig~;
+#X floatatom 69 488 9 0 0 0 - - -;
+#X obj 155 462 unsig~;
+#X floatatom 155 488 9 0 0 0 - - -;
+#X text 426 364 d(n);
+#X obj 516 270 loadbang;
+#X text 704 47 (array-sizes have to be >= then FIR_size);
+#X text 654 37 1.arg: <float> number of order of FIR-filter;
+#X text 57 73 update every sample;
+#X text 57 58 stop \, no update;
+#X text 57 88 update every 2nd sample;
+#X text 57 103 update every 4th sample;
+#X text 57 118 update every 8th sample;
+#X text 57 133 update every 16th sample;
+#X text 57 148 update every 32nd sample;
+#X text 57 163 update every 64th sample;
+#N canvas 0 0 486 336 /SUBPATCH/ 0;
+#X obj 48 46 inlet;
+#X obj 205 47 inlet;
+#X msg 205 71 \; IR const 0;
+#X obj 92 84 loadbang;
+#X msg 48 120 \; IR 0 0 0 0 0 0 0.314287 0.8 0.75 0 0 0 0 -0.7 -0.65
+0 0 0 0.157143 0.128572 0 0 -0.128572 -0.1 0 0 0 0 0 0 0 0 0 0 0 0
+0 0 0 0 0;
+#X connect 0 0 4 0;
+#X connect 1 0 2 0;
+#X connect 3 0 4 0;
+#X restore 517 245 pd;
+#X obj 530 227 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 547 224 clear;
+#X obj 517 208 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 534 205 load;
+#X text 579 214 IR;
+#X text 19 397 filtered output signal;
+#X text 339 396 error signal;
+#X text 469 457 constrain;
+#X text 469 467 coefficients;
+#X msg 452 422 0;
+#X obj 452 442 speedlim 100;
+#X obj 110 414 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#N canvas 0 0 482 332 /SUBPATCH/ 0;
+#X obj 137 73 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
+;
+#X msg 137 115 39;
+#X msg 92 190 \$1 39;
+#X msg 136 53 1;
+#X obj 137 92 metro 200;
+#X obj 136 24 inlet;
+#X obj 92 169 tabread 1_W;
+#X obj 92 214 tabwrite 1_W;
+#X msg 177 192 \$1 39;
+#X msg 260 191 \$1 39;
+#X obj 260 170 tabread 3_W;
+#X obj 260 215 tabwrite 3_W;
+#X obj 177 171 tabread 2_W;
+#X obj 177 216 tabwrite 2_W;
+#X connect 0 0 4 0;
+#X connect 1 0 6 0;
+#X connect 1 0 12 0;
+#X connect 1 0 10 0;
+#X connect 2 0 7 0;
+#X connect 3 0 0 0;
+#X connect 4 0 1 0;
+#X connect 5 0 3 0;
+#X connect 6 0 2 0;
+#X connect 8 0 13 0;
+#X connect 9 0 11 0;
+#X connect 10 0 9 0;
+#X connect 12 0 8 0;
+#X restore 516 291 pd;
+#X text 541 297 update of W;
+#X text 540 286 graphical;
+#X text 111 319 minimum input value;
+#X msg 117 220 0.1;
+#X msg 75 301 1e-05;
+#X text 170 258 beta [0 .. 2];
+#X text 131 338 gamma [0 .. 1];
+#X obj 574 38 cnv 15 68 17 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#N canvas 0 0 568 372 FORMULAS 0;
+#X obj 167 52 cnv 15 150 40 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 167 123 cnv 15 270 50 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X obj 167 205 cnv 15 260 30 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X text 280 129 beta;
+#X text 231 146 >;
+#X text 232 144 _;
+#X text 232 138 _;
+#X text 277 141 2;
+#X text 340 141 2;
+#X text 311 146 gamma * blocksize);
+#X text 294 146 +;
+#X text 243 146 x[n-i];
+#X text 174 135 my(n) =;
+#X text 223 130 _________________________________;
+#X text 6 135 normalized learn rate:;
+#X text 173 54 y(n) = W * x(n);
+#X obj 225 56 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 173 72 e(n) = d(n) - W * x(n);
+#X obj 267 74 cnv 11 1 1 empty empty * 0 9 0 14 -225280 -1 0;
+#X text 119 73 error:;
+#X text 116 55 output:;
+#X text 7 212 coefficient iteration:;
+#X text 176 213 W(k+1 \, i) = W(k \, i) + my(n)* e(n)* x(n);
+#X restore 573 39 pd FORMULAS;
+#X obj 117 240 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 117 240 5 0 2 0 - - -;
+#X text 153 239 learn-rate;
+#X obj 75 321 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 75 321 5 0 1 0 - - -;
+#X floatatom 40 228 5 0 0 0 - - -;
+#X text 572 14 Normalized Least Mean Square (linear adaptive FIR-filter)
+;
+#N canvas 0 0 450 300 graph1 0;
+#X array 2_W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 314 519 graph;
+#N canvas 0 0 450 300 graph1 0;
+#X array 3_W 40 float 0;
+#X coords 0 1 39 -1 200 140 1;
+#X restore 564 519 graph;
+#X obj 68 382 n_CNLMS~ 3 32 0.1 1e-05 1 W _______________________________
+;
+#X obj 244 463 unsig~;
+#X floatatom 244 489 9 0 0 0 - - -;
+#X obj 334 461 unsig~;
+#X floatatom 334 487 9 0 0 0 - - -;
+#X text 304 233 minimum input value;
+#X obj 268 235 cnv 14 31 14 empty empty empty 20 12 0 14 -225280 -66577
+0;
+#X floatatom 268 235 5 0 10000 0 - - -;
+#X msg 268 253 kappa \$1;
+#X text 324 252 kappa [0 .. 1];
+#X msg 268 215 1;
+#X obj 423 293 FIR~ IR 32;
+#X obj 186 293 z~ 2;
+#X obj 304 293 z~ 4;
+#X text 41 365 x1(n);
+#X text 272 365 x3(n);
+#X text 191 364 x2(n);
+#X text 39 410 y1(n) = 1_W * x1(n);
+#X obj 196 429 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X obj 286 403 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 125 425 y2(n) = 2_W * x2(n);
+#X text 215 399 y3(n) = 3_W * x3(n);
+#X obj 375 425 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 341 421 - 1_W * x1(n);
+#X text 312 410 e(n) = d(n);
+#X obj 375 435 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 341 431 - 2_W * x2(n);
+#X obj 375 445 cnv 8 1 1 empty empty * 0 7 0 14 -262144 -1 0;
+#X text 341 441 - 3_W * x3(n);
+#X text 572 3 Multi Channel Constraint;
+#X msg 463 139 \; 1_W const 0 \; 2_W const 0 \; 3_W const 0;
+#X text 462 117 RESET TABLES;
+#X text 654 150 (C) 2005 \, m.noisternig & t.musil \, IEM \, Graz \,
+Austria;
+#X text 682 163 [noisternig \, musil]_AT_iem.at;
+#X text 655 64 2.arg: <float> number of order of FIR-filter;
+#X text 655 78 3.arg: <float> learn-rate = beta;
+#X text 656 103 5.arg: <float> constraint = kappa;
+#X text 655 90 4.arg: <float> regularization parameter = gamma;
+#X text 656 118 6.arg: <symbol> table-name of W;
+#X connect 1 0 64 0;
+#X connect 2 0 64 0;
+#X connect 3 0 4 0;
+#X connect 4 0 5 0;
+#X connect 4 1 6 0;
+#X connect 8 0 75 0;
+#X connect 8 0 64 0;
+#X connect 8 0 76 0;
+#X connect 8 0 77 0;
+#X connect 9 0 10 0;
+#X connect 10 0 60 0;
+#X connect 12 0 64 0;
+#X connect 16 0 17 0;
+#X connect 18 0 19 0;
+#X connect 21 0 45 0;
+#X connect 33 0 32 1;
+#X connect 35 0 32 0;
+#X connect 42 0 43 0;
+#X connect 43 0 7 0;
+#X connect 49 0 56 0;
+#X connect 50 0 59 0;
+#X connect 56 0 2 0;
+#X connect 59 0 12 0;
+#X connect 60 0 1 0;
+#X connect 64 0 16 0;
+#X connect 64 1 18 0;
+#X connect 64 2 65 0;
+#X connect 64 3 67 0;
+#X connect 64 4 42 0;
+#X connect 65 0 66 0;
+#X connect 67 0 68 0;
+#X connect 71 0 72 0;
+#X connect 72 0 64 0;
+#X connect 74 0 71 0;
+#X connect 75 0 64 3;
+#X connect 76 0 64 1;
+#X connect 77 0 64 2;
diff --git a/src/.DS_Store b/src/.DS_Store
new file mode 100644
index 0000000..5008ddf
--- /dev/null
+++ b/src/.DS_Store
Binary files differ
diff --git a/src/iem_adaptfilt.c b/src/iem_adaptfilt.c
new file mode 100644
index 0000000..11381ee
--- /dev/null
+++ b/src/iem_adaptfilt.c
@@ -0,0 +1,46 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iem_adaptfilt written by Markus Noisternig & Thomas Musil
+noisternig_AT_iem.at; musil_AT_iem.at
+(c) Institute of Electronic Music and Acoustics, Graz Austria 2005 */
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+
+static t_class *iem_adaptfilt_class;
+
+static void *iem_adaptfilt_new(void)
+{
+ t_object *x = (t_object *)pd_new(iem_adaptfilt_class);
+
+ return (x);
+}
+
+void sigNLMS_setup(void);
+void sigNLMSCC_setup(void);
+void sign_CNLMS_setup(void);
+void sign_CLNLMS_setup(void);
+
+/* ------------------------ setup routine ------------------------- */
+
+void iem_adaptfilt_setup(void)
+{
+ sigNLMS_setup();
+ sigNLMSCC_setup();
+ sign_CNLMS_setup();
+ sign_CLNLMS_setup();
+
+ post("----------------------------------------------");
+ post("iem_adaptfilt (R-1.02) library loaded!");
+ post("(c) Markus Noisternig, Thomas Musil");
+ post(" {noisternig, musil}_AT_iem.at");
+ post(" IEM Graz, Austria");
+ post("----------------------------------------------");
+}
diff --git a/src/iemlib.h b/src/iemlib.h
new file mode 100644
index 0000000..0de2d9d
--- /dev/null
+++ b/src/iemlib.h
@@ -0,0 +1,102 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2004 */
+
+#ifndef __IEMLIB_H__
+#define __IEMLIB_H__
+
+
+#define IS_A_POINTER(atom,index) ((atom+index)->a_type == A_POINTER)
+#define IS_A_FLOAT(atom,index) ((atom+index)->a_type == A_FLOAT)
+#define IS_A_SYMBOL(atom,index) ((atom+index)->a_type == A_SYMBOL)
+#define IS_A_DOLLAR(atom,index) ((atom+index)->a_type == A_DOLLAR)
+#define IS_A_DOLLSYM(atom,index) ((atom+index)->a_type == A_DOLLSYM)
+#define IS_A_SEMI(atom,index) ((atom+index)->a_type == A_SEMI)
+#define IS_A_COMMA(atom,index) ((atom+index)->a_type == A_COMMA)
+
+
+#ifdef NT
+int sys_noloadbang;
+//t_symbol *iemgui_key_sym=0;
+#include <io.h>
+#else
+extern int sys_noloadbang;
+//extern t_symbol *iemgui_key_sym;
+#include <unistd.h>
+#endif
+
+#define DEFDELVS 64
+#define XTRASAMPS 4
+#define SAMPBLK 4
+
+
+#define UNITBIT32 1572864. /* 3*2^19; bit 32 has place value 1 */
+
+/* machine-dependent definitions. These ifdefs really
+should have been by CPU type and not by operating system! */
+#ifdef IRIX
+/* big-endian. Most significant byte is at low address in memory */
+#define HIOFFSET 0 /* word offset to find MSB */
+#define LOWOFFSET 1 /* word offset to find LSB */
+#define int32 long /* a data type that has 32 bits */
+#else
+#ifdef MSW
+/* little-endian; most significant byte is at highest address */
+#define HIOFFSET 1
+#define LOWOFFSET 0
+#define int32 long
+#else
+#ifdef __FreeBSD__
+#include <machine/endian.h>
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define HIOFFSET 1
+#define LOWOFFSET 0
+#else
+#define HIOFFSET 0 /* word offset to find MSB */
+#define LOWOFFSET 1 /* word offset to find LSB */
+#endif /* BYTE_ORDER */
+#include <sys/types.h>
+#define int32 int32_t
+#endif
+#ifdef __linux__
+
+#include <endian.h>
+
+#if !defined(__BYTE_ORDER) || !defined(__LITTLE_ENDIAN)
+#error No byte order defined
+#endif
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define HIOFFSET 1
+#define LOWOFFSET 0
+#else
+#define HIOFFSET 0 /* word offset to find MSB */
+#define LOWOFFSET 1 /* word offset to find LSB */
+#endif /* __BYTE_ORDER */
+
+#include <sys/types.h>
+#define int32 int32_t
+
+#else
+#ifdef __APPLE__
+#define HIOFFSET 0 /* word offset to find MSB */
+#define LOWOFFSET 1 /* word offset to find LSB */
+#define int32 int /* a data type that has 32 bits */
+
+#endif /* __APPLE__ */
+#endif /* __linux__ */
+#endif /* MSW */
+#endif /* SGI */
+
+union tabfudge
+{
+ double tf_d;
+ int32 tf_i[2];
+};
+
+#define IEM_DENORMAL(f) ((((*(unsigned int*)&(f))&0x60000000)==0) || \
+(((*(unsigned int*)&(f))&0x60000000)==0x60000000))
+/* more stringent test: anything not between 1e-19 and 1e19 in absolute val */
+
+#endif
diff --git a/src/makefile.txt b/src/makefile.txt
new file mode 100644
index 0000000..6654843
--- /dev/null
+++ b/src/makefile.txt
@@ -0,0 +1,50 @@
+current: all
+
+.SUFFIXES: .pd_linux
+
+INCLUDE = -I. -I/usr/local/src/pd-0.37-1/src
+
+LDFLAGS = -export-dynamic -shared
+LIB = -ldl -lm -lpthread
+
+#select either the DBG and OPT compiler flags below:
+
+CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \
+ -Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer \
+ -DDL_OPEN
+
+SYSTEM = $(shell uname -m)
+
+# the sources
+
+SRC = sigNLMS.c \
+ sigNLMSCC.c \
+ sign_CNLMS.c \
+ iem_adaptfilt.c
+
+TARGET = iem_adaptfilt.pd_linux
+
+
+OBJ = $(SRC:.c=.o)
+
+#
+# ------------------ targets ------------------------------------
+#
+
+clean:
+ rm $(TARGET)
+ rm *.o
+
+all: $(OBJ)
+ @echo :: $(OBJ)
+ ld $(LDFLAGS) -o $(TARGET) *.o $(LIB)
+ strip --strip-unneeded $(TARGET)
+ rm *.o
+
+$(OBJ) : %.o : %.c
+ touch $*.c
+ cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
+
+
+
+
diff --git a/src/makefile_lin b/src/makefile_lin
new file mode 100644
index 0000000..1e6a625
--- /dev/null
+++ b/src/makefile_lin
@@ -0,0 +1,51 @@
+current: all
+
+.SUFFIXES: .pd_linux
+
+INCLUDE = -I. -I/usr/local/src/pd-0.37-1/src
+
+LDFLAGS = -export-dynamic -shared
+LIB = -ldl -lm -lpthread
+
+#select either the DBG and OPT compiler flags below:
+
+CFLAGS = -DPD -DUNIX -W -Werror -Wno-unused \
+ -Wno-parentheses -Wno-switch -O6 -funroll-loops -fomit-frame-pointer \
+ -DDL_OPEN
+
+SYSTEM = $(shell uname -m)
+
+# the sources
+
+SRC = sigNLMS.c \
+ sigNLMSCC.c \
+ sign_CNLMS.c \
+ sign_CLNLMS.c \
+ iem_adaptfilt.c
+
+TARGET = iem_adaptfilt.pd_linux
+
+
+OBJ = $(SRC:.c=.o)
+
+#
+# ------------------ targets ------------------------------------
+#
+
+clean:
+ rm ../../lib/$(TARGET)
+ rm *.o
+
+all: $(OBJ)
+ @echo :: $(OBJ)
+ ld $(LDFLAGS) -o $(TARGET) *.o $(LIB)
+ strip --strip-unneeded $(TARGET)
+ rm *.o
+
+$(OBJ) : %.o : %.c
+ touch $*.c
+ cc $(CFLAGS) $(INCLUDE) -c -o $*.o $*.c
+
+
+
+
diff --git a/src/makefile_win b/src/makefile_win
new file mode 100644
index 0000000..fe10c99
--- /dev/null
+++ b/src/makefile_win
@@ -0,0 +1,44 @@
+
+all: iem_adaptfilt.dll
+
+VIS_CPP_PATH = "C:\Programme\Microsoft Visual Studio\Vc98"
+
+PD_INST_PATH = "C:\Programme\pd-0.37-3"
+
+PD_WIN_INCLUDE_PATH = /I. /I$(PD_INST_PATH)\src /I$(VIS_CPP_PATH)\include
+
+PD_WIN_C_FLAGS = /nologo /W3 /WX /DMSW /DNT /DPD /DWIN32 /DWINDOWS /Ox -DPA_LITTLE_ENDIAN
+
+PD_WIN_L_FLAGS = /nologo
+
+PD_WIN_LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel /NODEFAULTLIB:uuid \
+ $(VIS_CPP_PATH)\lib\libc.lib \
+ $(VIS_CPP_PATH)\lib\oldnames.lib \
+ $(VIS_CPP_PATH)\lib\kernel32.lib \
+ $(VIS_CPP_PATH)\lib\wsock32.lib \
+ $(VIS_CPP_PATH)\lib\winmm.lib \
+ $(PD_INST_PATH)\bin\pthreadVC.lib \
+ $(PD_INST_PATH)\bin\pd.lib
+
+
+SRC = sigNLMS.c \
+ sigNLMSCC.c \
+ sign_CNLMS.c \
+ sign_CLNLMS.c \
+ iem_adaptfilt.c
+
+
+OBJ = $(SRC:.c=.obj)
+
+.c.obj:
+ cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c
+
+iem_adaptfilt.dll: $(OBJ)
+ link $(PD_WIN_L_FLAGS) /dll /export:iem_adaptfilt_setup \
+ /out:iem_adaptfilt.dll $(OBJ) $(PD_WIN_LIB)
+
+
+clean:
+ del *.obj
+
+
diff --git a/src/makefile_win.txt b/src/makefile_win.txt
new file mode 100644
index 0000000..bfbedf8
--- /dev/null
+++ b/src/makefile_win.txt
@@ -0,0 +1,43 @@
+
+all: iem_adaptfilt.dll
+
+VIS_CPP_PATH = "C:\Programme\Microsoft Visual Studio\Vc98"
+
+PD_INST_PATH = "C:\Programme\pd-0.37-1"
+
+PD_WIN_INCLUDE_PATH = /I. /I$(PD_INST_PATH)\src /I$(VIS_CPP_PATH)\include
+
+PD_WIN_C_FLAGS = /nologo /W3 /WX /DMSW /DNT /DPD /DWIN32 /DWINDOWS /Ox -DPA_LITTLE_ENDIAN
+
+PD_WIN_L_FLAGS = /nologo
+
+PD_WIN_LIB = /NODEFAULTLIB:libc /NODEFAULTLIB:oldnames /NODEFAULTLIB:kernel /NODEFAULTLIB:uuid \
+ $(VIS_CPP_PATH)\lib\libc.lib \
+ $(VIS_CPP_PATH)\lib\oldnames.lib \
+ $(VIS_CPP_PATH)\lib\kernel32.lib \
+ $(VIS_CPP_PATH)\lib\wsock32.lib \
+ $(VIS_CPP_PATH)\lib\winmm.lib \
+ $(PD_INST_PATH)\bin\pthreadVC.lib \
+ $(PD_INST_PATH)\bin\pd.lib
+
+
+SRC = sigNLMS.c \
+ sigNLMSCC.c \
+ sign_CNLMS.c \
+ sign_CLNLMS.c \
+ iem_adaptfilt.c
+
+
+OBJ = $(SRC:.c=.obj)
+
+.c.obj:
+ cl $(PD_WIN_C_FLAGS) $(PD_WIN_INCLUDE_PATH) /c $*.c
+
+iem_adaptfilt.dll: $(OBJ)
+ link $(PD_WIN_L_FLAGS) /dll /export:iem_adaptfilt_setup \
+ /out:iem_adaptfilt.dll $(OBJ) $(PD_WIN_LIB)
+ copy iem_adaptfilt.dll ..\..\lib\iem_adaptfilt.dll
+ copy iem_adaptfilt.dll ..\..\..\iem_adaptfilt.dll
+
+clean:
+ del *.obj
diff --git a/src/sigNLMS.c b/src/sigNLMS.c
new file mode 100644
index 0000000..53ab284
--- /dev/null
+++ b/src/sigNLMS.c
@@ -0,0 +1,337 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+NLMS normalized least mean square (LMS) algorithm
+lib iem_adaptfilt written by Markus Noisternig & Thomas Musil
+noisternig_AT_iem.at; musil_AT_iem.at
+(c) Institute of Electronic Music and Acoustics, Graz Austria 2005 */
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+
+
+/* ----------------------- NLMS~ ------------------------------ */
+/* -- Normalized Least Mean Square (linear adaptive FIR-filter) -- */
+/* -- first input: reference signal -- */
+/* -- second input: desired signal -- */
+/* -- -- */
+
+/* for further information on adaptive filter design we refer to */
+/* [1] Haykin, "Adaptive Filter Theory", 4th ed, Prentice Hall */
+/* [2] Benesty, "Adaptive Signal Processing", Springer */
+
+
+typedef struct sigNLMS
+{
+ t_object x_obj;
+ t_symbol *x_w_array_sym_name;
+ t_float *x_w_array_mem_beg;
+ t_float *x_io_ptr_beg[4];// memory: 2 sig-in and 2 sig-out vectors
+ t_float *x_in_hist;// start point double buffer for sig-in history
+ t_int x_rw_index;// read-write-index
+ t_int x_n_order;// order of filter
+ t_int x_update;// 2^n rounded value, downsampling of update speed
+ t_float x_beta;// learn rate [0 .. 2]
+ t_float x_gamma;// regularization
+ t_float x_msi;
+} t_sigNLMS;
+
+t_class *sigNLMS_class;
+
+static t_float *sigNLMS_check_array(t_symbol *array_sym_name, t_int length)
+{
+ t_int n_points;
+ t_garray *a;
+ t_float *vec;
+
+ if(!(a = (t_garray *)pd_findbyclass(array_sym_name, garray_class)))
+ {
+ error("%s: no such array for NLMS~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(!garray_getfloatarray(a, &n_points, &vec))
+ {
+ error("%s: bad template for NLMS~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(n_points < length)
+ {
+ error("%s: bad array-size for NLMS~: %d", array_sym_name->s_name, n_points);
+ return((t_float *)0);
+ }
+ else
+ {
+ return(vec);
+ }
+}
+
+static void sigNLMS_beta(t_sigNLMS *x, t_floatarg f) // learn rate
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 2.0f)
+ f = 2.0f;
+
+ x->x_beta = f;
+}
+
+static void sigNLMS_gamma(t_sigNLMS *x, t_floatarg f) // regularization factor (dither)
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 1.0f)
+ f = 1.0f;
+
+ x->x_gamma = f;
+}
+
+
+static void sigNLMS_update(t_sigNLMS *x, t_floatarg f) // downsample learn-rate
+{
+ t_int i=1, u = (t_int)f;
+
+ if(u < 0)
+ u = 0;
+ else
+ {
+ while(i <= u) // convert u for 2^N
+ i *= 2; // round downwards
+ i /= 2;
+ u = i;
+ }
+ x->x_update = u;
+}
+
+/* ============== DSP ======================= */
+
+static t_int *sigNLMS_perform_zero(t_int *w)
+{
+ t_sigNLMS *x = (t_sigNLMS *)(w[1]);
+ t_int n = (t_int)(w[2]);
+
+ t_float **io = x->x_io_ptr_beg;
+ t_float *out;
+ t_int i, j;
+
+ for(j=0; j<2; j++)/* output-vector-row */
+ {
+ out = io[j+2];
+ for(i=0; i<n; i++)
+ {
+ *out++ = 0.0f;
+ }
+ }
+ return (w+3);
+}
+
+static t_int *sigNLMS_perform(t_int *w)
+{
+ t_sigNLMS *x = (t_sigNLMS *)(w[1]);
+ t_int n = (t_int)(w[2]);
+ t_int n_order = x->x_n_order; /* number of filter-order */
+ t_int rw_index = x->x_rw_index;
+ t_float *in = x->x_io_ptr_beg[0];// first sig in
+ t_float *desired_in = x->x_io_ptr_beg[1], din;// second sig in
+ t_float *filt_out = x->x_io_ptr_beg[2];// first sig out
+ t_float *err_out = x->x_io_ptr_beg[3], eout;// second sig out
+ t_float *write_in_hist1 = x->x_in_hist;
+ t_float *write_in_hist2 = write_in_hist1+n_order;
+ t_float *read_in_hist = write_in_hist2;
+ t_float *w_filt_coeff = x->x_w_array_mem_beg;
+ t_float my, my_err, sum;
+ t_float beta = x->x_beta;
+ t_float gamma = x->x_gamma;
+ t_int i, j, update_counter;
+ t_int update = x->x_update;
+ t_int ord8=n_order&0xfffffff8;
+ t_int ord_residual=n_order&0x7;
+
+ if(!w_filt_coeff)
+ goto sigNLMSperfzero;// this is quick&dirty Musil/Miller style
+
+ for(i=0, update_counter=0; i<n; i++)// store history and convolve
+ {
+ write_in_hist1[rw_index] = in[i]; // save inputs to variable & history
+ write_in_hist2[rw_index] = in[i];
+ din = desired_in[i];
+
+ // begin convolution
+ sum = 0.0f;
+ w_filt_coeff = x->x_w_array_mem_beg; // Musil's special convolution buffer struct
+ read_in_hist = &write_in_hist2[rw_index];
+ for(j=0; j<ord8; j+=8) // loop unroll 8 taps
+ {
+ sum += w_filt_coeff[0] * read_in_hist[0];
+ sum += w_filt_coeff[1] * read_in_hist[-1];
+ sum += w_filt_coeff[2] * read_in_hist[-2];
+ sum += w_filt_coeff[3] * read_in_hist[-3];
+ sum += w_filt_coeff[4] * read_in_hist[-4];
+ sum += w_filt_coeff[5] * read_in_hist[-5];
+ sum += w_filt_coeff[6] * read_in_hist[-6];
+ sum += w_filt_coeff[7] * read_in_hist[-7];
+ w_filt_coeff += 8;
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // for filter order < 2^N
+ sum += w_filt_coeff[j] * read_in_hist[-j];
+
+ filt_out[i] = sum;
+ eout = din - filt_out[i]; // buffer-struct for further use
+ err_out[i] = eout;
+
+ if(update) // downsampling for learn rate
+ {
+ update_counter++;
+ if(update_counter >= update)
+ {
+ update_counter = 0;
+
+ sum = 0.0f;// calculate energy for last n-order samples in filter
+ read_in_hist = &write_in_hist2[rw_index];
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ sum += read_in_hist[0] * read_in_hist[0];
+ sum += read_in_hist[-1] * read_in_hist[-1];
+ sum += read_in_hist[-2] * read_in_hist[-2];
+ sum += read_in_hist[-3] * read_in_hist[-3];
+ sum += read_in_hist[-4] * read_in_hist[-4];
+ sum += read_in_hist[-5] * read_in_hist[-5];
+ sum += read_in_hist[-6] * read_in_hist[-6];
+ sum += read_in_hist[-7] * read_in_hist[-7];
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ sum += read_in_hist[-j] * read_in_hist[-j]; // [-j] only valid for Musil's double buffer structure
+ sum += gamma * gamma * (float)n_order; // convert gamma corresponding to filter order
+ my = beta / sum;// calculate mue
+
+
+ my_err = my * eout;
+ w_filt_coeff = x->x_w_array_mem_beg; // coefficient constraints
+ read_in_hist = &write_in_hist2[rw_index];
+ for(j=0; j<n_order; j++) // without unroll
+ w_filt_coeff[j] += read_in_hist[-j] * my_err;
+ }
+ }
+ rw_index++;
+ if(rw_index >= n_order)
+ rw_index -= n_order;
+ }
+
+ x->x_rw_index = rw_index; // back to start
+
+ return(w+3);
+
+sigNLMSperfzero:
+
+ while(n--)
+ {
+ *filt_out++ = 0.0f;
+ *err_out++ = 0.0f;
+ }
+ return(w+3);
+}
+
+static void sigNLMS_dsp(t_sigNLMS *x, t_signal **sp)
+{
+ t_int i, n = sp[0]->s_n;
+
+ for(i=0; i<4; i++) // store io_vec
+ x->x_io_ptr_beg[i] = sp[i]->s_vec;
+
+ x->x_w_array_mem_beg = sigNLMS_check_array(x->x_w_array_sym_name, x->x_n_order);
+
+ if(!x->x_w_array_mem_beg)
+ dsp_add(sigNLMS_perform_zero, 2, x, n);
+ else
+ dsp_add(sigNLMS_perform, 2, x, n);
+}
+
+
+/* setup/setdown things */
+
+static void sigNLMS_free(t_sigNLMS *x)
+{
+ freebytes(x->x_in_hist, 2*x->x_n_order*sizeof(t_float));
+}
+
+static void *sigNLMS_new(t_symbol *s, t_int argc, t_atom *argv)
+{
+ t_sigNLMS *x = (t_sigNLMS *)pd_new(sigNLMS_class);
+ t_int i, n_order=39;
+ t_symbol *w_name;
+ t_float beta=0.1f;
+ t_float gamma=0.00001f;
+
+ if((argc >= 4) &&
+ IS_A_FLOAT(argv,0) && //IS_A_FLOAT/SYMBOL from iemlib.h
+ IS_A_FLOAT(argv,1) &&
+ IS_A_FLOAT(argv,2) &&
+ IS_A_SYMBOL(argv,3))
+ {
+ n_order = (t_int)atom_getintarg(0, argc, argv);
+ beta = (t_float)atom_getfloatarg(1, argc, argv);
+ gamma = (t_float)atom_getfloatarg(2, argc, argv);
+ w_name = (t_symbol *)atom_getsymbolarg(3, argc, argv);
+
+ if(beta < 0.0f)
+ beta = 0.0f;
+ if(beta > 2.0f)
+ beta = 2.0f;
+
+ if(gamma < 0.0f)
+ gamma = 0.0f;
+ if(gamma > 1.0f)
+ gamma = 1.0f;
+
+ if(n_order < 2)
+ n_order = 2;
+ if(n_order > 11111)
+ n_order = 11111;
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+
+ x->x_msi = 0;
+ x->x_n_order = n_order;
+ x->x_update = 0;
+ x->x_beta = beta;
+ x->x_gamma = gamma;
+ // 2 times in and one time desired_in memory allocation (history)
+ x->x_in_hist = (t_float *)getbytes(2*x->x_n_order*sizeof(t_float));
+
+ // table-symbols will be linked to their memory in future (dsp_routine)
+ x->x_w_array_sym_name = gensym(w_name->s_name);
+ x->x_w_array_mem_beg = (t_float *)0;
+
+ return(x);
+ }
+ else
+ {
+ post("NLMS~-ERROR: need 3 float- + 1 symbol-arguments:");
+ post(" order_of_filter + learnrate_beta + security_value + array_name_taps");
+ return(0);
+ }
+}
+
+void sigNLMS_setup(void)
+{
+ sigNLMS_class = class_new(gensym("NLMS~"), (t_newmethod)sigNLMS_new, (t_method)sigNLMS_free,
+ sizeof(t_sigNLMS), 0, A_GIMME, 0);
+ CLASS_MAINSIGNALIN(sigNLMS_class, t_sigNLMS, x_msi);
+ class_addmethod(sigNLMS_class, (t_method)sigNLMS_dsp, gensym("dsp"), 0);
+ class_addmethod(sigNLMS_class, (t_method)sigNLMS_update, gensym("update"), A_FLOAT, 0); // method: downsampling factor of learning (multiple of 2^N)
+ class_addmethod(sigNLMS_class, (t_method)sigNLMS_beta, gensym("beta"), A_FLOAT, 0); //method: normalized learning rate
+ class_addmethod(sigNLMS_class, (t_method)sigNLMS_gamma, gensym("gamma"), A_FLOAT, 0); // method: dithering noise related to signal
+ class_sethelpsymbol(sigNLMS_class, gensym("iemhelp2/NLMS~"));
+}
diff --git a/src/sigNLMSCC.c b/src/sigNLMSCC.c
new file mode 100644
index 0000000..553e595
--- /dev/null
+++ b/src/sigNLMSCC.c
@@ -0,0 +1,390 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+NLMSCC normalized LMS algorithm with coefficient constraints
+lib iem_adaptfilt written by Markus Noisternig & Thomas Musil
+noisternig_AT_iem.at; musil_AT_iem.at
+(c) Institute of Electronic Music and Acoustics, Graz Austria 2005 */
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+
+
+/* ----------------------- NLMSCC~ ------------------------------ */
+/* -- Normalized Least Mean Square (linear adaptive FIR-filter) -- */
+/* -- with Coefficient Constraint
+/* -- first input: reference signal -- */
+/* -- second input: desired signal -- */
+/* -- -- */
+/* for further information on adaptive filter design we refer to */
+/* [1] Haykin, "Adaptive Filter Theory", 4th ed, Prentice Hall */
+/* [2] Benesty, "Adaptive Signal Processing", Springer */
+/* */
+
+
+typedef struct sigNLMSCC
+{
+ t_object x_obj;
+ t_symbol *x_w_array_sym_name;
+ t_float *x_w_array_mem_beg;
+ t_symbol *x_wmin_array_sym_name;
+ t_float *x_wmin_array_mem_beg;
+ t_symbol *x_wmax_array_sym_name;
+ t_float *x_wmax_array_mem_beg;
+ t_float *x_io_ptr_beg[4];// memory: 2 sig-in and 2 sig-out vectors
+ t_float *x_in_hist;// start point double buffer for sig-in history
+ t_int x_rw_index;// read-write-index
+ t_int x_n_order;// order of filter
+ t_int x_update;// 2^n rounded value, downsampling of update speed
+ t_float x_beta;// learn rate [0 .. 2]
+ t_float x_gamma;// regularization
+ t_outlet *x_out_clipping_bang;
+ t_clock *x_clock;
+ t_float x_msi;
+} t_sigNLMSCC;
+
+t_class *sigNLMSCC_class;
+
+static void sigNLMSCC_tick(t_sigNLMSCC *x)
+{
+ outlet_bang(x->x_out_clipping_bang);
+}
+
+static t_float *sigNLMSCC_check_array(t_symbol *array_sym_name, t_int length)
+{
+ t_int n_points;
+ t_garray *a;
+ t_float *vec;
+
+ if(!(a = (t_garray *)pd_findbyclass(array_sym_name, garray_class)))
+ {
+ error("%s: no such array for NLMSCC~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(!garray_getfloatarray(a, &n_points, &vec))
+ {
+ error("%s: bad template for NLMSCC~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(n_points < length)
+ {
+ error("%s: bad array-size for NLMSCC~: %d", array_sym_name->s_name, n_points);
+ return((t_float *)0);
+ }
+ else
+ {
+ return(vec);
+ }
+}
+
+static void sigNLMSCC_beta(t_sigNLMSCC *x, t_floatarg f) // learn rate
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 2.0f)
+ f = 2.0f;
+
+ x->x_beta = f;
+}
+
+static void sigNLMSCC_gamma(t_sigNLMSCC *x, t_floatarg f) // regularization factor (dither)
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 1.0f)
+ f = 1.0f;
+
+ x->x_gamma = f;
+}
+
+
+static void sigNLMSCC_update(t_sigNLMSCC *x, t_floatarg f) // downsample of learn-rate
+{
+ t_int i=1, u = (t_int)f;
+
+ if(u < 0)
+ u = 0;
+ else
+ {
+ while(i <= u) // convert u for 2^N
+ i *= 2; // round downwards
+ i /= 2;
+ u = i;
+ }
+ x->x_update = u;
+}
+
+/* ============== DSP ======================= */
+
+static t_int *sigNLMSCC_perform_zero(t_int *w)
+{
+ t_sigNLMSCC *x = (t_sigNLMSCC *)(w[1]);
+ t_int n = (t_int)(w[2]);
+
+ t_float **io = x->x_io_ptr_beg;
+ t_float *out;
+ t_int i, j;
+
+ for(j=0; j<2; j++)/* output-vector-row */
+ {
+ out = io[j+2];
+ for(i=0; i<n; i++)
+ {
+ *out++ = 0.0f;
+ }
+ }
+ return (w+3);
+}
+
+static t_int *sigNLMSCC_perform(t_int *w)
+{
+ t_sigNLMSCC *x = (t_sigNLMSCC *)(w[1]);
+ t_int n = (t_int)(w[2]);
+ t_int n_order = x->x_n_order; /* filter-order */
+ t_int rw_index = x->x_rw_index;
+ t_float *in = x->x_io_ptr_beg[0];// first sig in
+ t_float *desired_in = x->x_io_ptr_beg[1], din;// second sig in
+ t_float *filt_out = x->x_io_ptr_beg[2];// first sig out
+ t_float *err_out = x->x_io_ptr_beg[3], eout;// second sig out
+ t_float *write_in_hist1 = x->x_in_hist;
+ t_float *write_in_hist2 = write_in_hist1+n_order;
+ t_float *read_in_hist = write_in_hist2;
+ t_float *w_filt_coeff = x->x_w_array_mem_beg;
+ t_float *wmin_filt_coeff = x->x_wmin_array_mem_beg;
+ t_float *wmax_filt_coeff = x->x_wmax_array_mem_beg;
+ t_float my, my_err, sum;
+ t_float beta = x->x_beta;
+ t_float gamma = x->x_gamma;
+ t_int i, j, update_counter;
+ t_int update = x->x_update;
+ t_int ord8=n_order&0xfffffff8;
+ t_int ord_residual=n_order&0x7;
+ t_int clipped = 0;
+
+ if(!w_filt_coeff)
+ goto sigNLMSCCperfzero;// this is Musil/Miller style
+ if(!wmin_filt_coeff)
+ goto sigNLMSCCperfzero;
+ if(!wmax_filt_coeff)
+ goto sigNLMSCCperfzero;// if not constrained, perform zero
+
+ for(i=0, update_counter=0; i<n; i++)// store in history and convolve
+ {
+ write_in_hist1[rw_index] = in[i]; // save inputs into variabel & history
+ write_in_hist2[rw_index] = in[i];
+ din = desired_in[i];
+
+ // begin convolution
+ sum = 0.0f;
+ w_filt_coeff = x->x_w_array_mem_beg; // Musil's special convolution buffer struct
+ read_in_hist = &write_in_hist2[rw_index];
+ for(j=0; j<ord8; j+=8) // loop unroll 8 taps
+ {
+ sum += w_filt_coeff[0] * read_in_hist[0];
+ sum += w_filt_coeff[1] * read_in_hist[-1];
+ sum += w_filt_coeff[2] * read_in_hist[-2];
+ sum += w_filt_coeff[3] * read_in_hist[-3];
+ sum += w_filt_coeff[4] * read_in_hist[-4];
+ sum += w_filt_coeff[5] * read_in_hist[-5];
+ sum += w_filt_coeff[6] * read_in_hist[-6];
+ sum += w_filt_coeff[7] * read_in_hist[-7];
+ w_filt_coeff += 8;
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // for filter order < 2^N
+ sum += w_filt_coeff[j] * read_in_hist[-j];
+
+ filt_out[i] = sum;
+ eout = din - filt_out[i]; // buffer-struct for further use
+ err_out[i] = eout;
+
+ if(update) // downsampling for learn rate
+ {
+ update_counter++;
+ if(update_counter >= update)
+ {
+ update_counter = 0;
+
+ sum = 0.0f;// calculate energy for last n-order samples in filter
+ read_in_hist = &write_in_hist2[rw_index];
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ sum += read_in_hist[0] * read_in_hist[0];
+ sum += read_in_hist[-1] * read_in_hist[-1];
+ sum += read_in_hist[-2] * read_in_hist[-2];
+ sum += read_in_hist[-3] * read_in_hist[-3];
+ sum += read_in_hist[-4] * read_in_hist[-4];
+ sum += read_in_hist[-5] * read_in_hist[-5];
+ sum += read_in_hist[-6] * read_in_hist[-6];
+ sum += read_in_hist[-7] * read_in_hist[-7];
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ sum += read_in_hist[-j] * read_in_hist[-j]; // [-j] only valid for Musil's double buffer structure
+ sum += gamma * gamma * (float)n_order; // convert gamma corresponding to filter order
+ my = beta / sum;// calculate mue
+
+
+ my_err = my * eout;
+ w_filt_coeff = x->x_w_array_mem_beg; // coefficient constraints
+ wmin_filt_coeff = x->x_wmin_array_mem_beg;
+ wmax_filt_coeff = x->x_wmax_array_mem_beg;
+ read_in_hist = &write_in_hist2[rw_index];
+ for(j=0; j<n_order; j++) // without unroll
+ {
+ w_filt_coeff[j] += read_in_hist[-j] * my_err;
+ if(w_filt_coeff[j] > wmax_filt_coeff[j])
+ {
+ w_filt_coeff[j] = wmax_filt_coeff[j];
+ clipped = 1;
+ }
+ else if(w_filt_coeff[j] < wmin_filt_coeff[j])
+ {
+ w_filt_coeff[j] = wmin_filt_coeff[j];
+ clipped = 1;
+ }
+ }
+ }
+ }
+ rw_index++;
+ if(rw_index >= n_order)
+ rw_index -= n_order;
+ }
+
+ x->x_rw_index = rw_index; // back to start
+
+ if(clipped)
+ clock_delay(x->x_clock, 0);
+ return(w+3);
+
+sigNLMSCCperfzero:
+
+ while(n--)
+ {
+ *filt_out++ = 0.0f;
+ *err_out++ = 0.0f;
+ }
+ return(w+3);
+}
+
+static void sigNLMSCC_dsp(t_sigNLMSCC *x, t_signal **sp)
+{
+ t_int i, n = sp[0]->s_n;
+
+ for(i=0; i<4; i++) // store io_vec
+ x->x_io_ptr_beg[i] = sp[i]->s_vec;
+
+ x->x_w_array_mem_beg = sigNLMSCC_check_array(x->x_w_array_sym_name, x->x_n_order);
+ x->x_wmin_array_mem_beg = sigNLMSCC_check_array(x->x_wmin_array_sym_name, x->x_n_order);
+ x->x_wmax_array_mem_beg = sigNLMSCC_check_array(x->x_wmax_array_sym_name, x->x_n_order);
+
+ if(!(x->x_w_array_mem_beg && x->x_wmin_array_mem_beg && x->x_wmax_array_mem_beg))
+ dsp_add(sigNLMSCC_perform_zero, 2, x, n);
+ else
+ dsp_add(sigNLMSCC_perform, 2, x, n);
+}
+
+
+/* setup/setdown things */
+
+static void sigNLMSCC_free(t_sigNLMSCC *x)
+{
+
+ freebytes(x->x_in_hist, 2*x->x_n_order*sizeof(t_float));
+
+ clock_free(x->x_clock);
+}
+
+static void *sigNLMSCC_new(t_symbol *s, t_int argc, t_atom *argv)
+{
+ t_sigNLMSCC *x = (t_sigNLMSCC *)pd_new(sigNLMSCC_class);
+ t_int i, n_order=39;
+ t_symbol *w_name;
+ t_symbol *wmin_name;
+ t_symbol *wmax_name;
+ t_float beta=0.1f;
+ t_float gamma=0.00001f;
+
+ if((argc >= 6) &&
+ IS_A_FLOAT(argv,0) && //IS_A_FLOAT/SYMBOL from iemlib.h
+ IS_A_FLOAT(argv,1) &&
+ IS_A_FLOAT(argv,2) &&
+ IS_A_SYMBOL(argv,3) &&
+ IS_A_SYMBOL(argv,4) &&
+ IS_A_SYMBOL(argv,5))
+ {
+ n_order = (t_int)atom_getintarg(0, argc, argv);
+ beta = (t_float)atom_getfloatarg(1, argc, argv);
+ gamma = (t_float)atom_getfloatarg(2, argc, argv);
+ w_name = (t_symbol *)atom_getsymbolarg(3, argc, argv);
+ wmin_name = (t_symbol *)atom_getsymbolarg(4, argc, argv);
+ wmax_name = (t_symbol *)atom_getsymbolarg(5, argc, argv);
+
+ if(beta < 0.0f)
+ beta = 0.0f;
+ if(beta > 2.0f)
+ beta = 2.0f;
+
+ if(gamma < 0.0f)
+ gamma = 0.0f;
+ if(gamma > 1.0f)
+ gamma = 1.0f;
+
+ if(n_order < 2)
+ n_order = 2;
+ if(n_order > 11111)
+ n_order = 11111;
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ outlet_new(&x->x_obj, &s_signal);
+ x->x_out_clipping_bang = outlet_new(&x->x_obj, &s_bang);
+
+ x->x_msi = 0;
+ x->x_n_order = n_order;
+ x->x_update = 0;
+ x->x_beta = beta;
+ x->x_gamma = gamma;
+ // 2 times in and one time desired_in memory allocation (history)
+ x->x_in_hist = (t_float *)getbytes(2*x->x_n_order*sizeof(t_float));
+
+ // table-symbols will be linked to their memory in future (dsp_routine)
+ x->x_w_array_sym_name = gensym(w_name->s_name);
+ x->x_w_array_mem_beg = (t_float *)0;
+ x->x_wmin_array_sym_name = gensym(wmin_name->s_name);
+ x->x_wmin_array_mem_beg = (t_float *)0;
+ x->x_wmax_array_sym_name = gensym(wmax_name->s_name);
+ x->x_wmax_array_mem_beg = (t_float *)0;
+
+ x->x_clock = clock_new(x, (t_method)sigNLMSCC_tick);
+
+ return(x);
+ }
+ else
+ {
+ post("NLMSCC~-ERROR: need 3 float- + 3 symbol-arguments:");
+ post(" order_of_filter + learnrate_beta + security_value + array_name_taps + array_name_tap_min + array_name_tap_max");
+ return(0);
+ }
+}
+
+void sigNLMSCC_setup(void)
+{
+ sigNLMSCC_class = class_new(gensym("NLMSCC~"), (t_newmethod)sigNLMSCC_new, (t_method)sigNLMSCC_free,
+ sizeof(t_sigNLMSCC), 0, A_GIMME, 0);
+ CLASS_MAINSIGNALIN(sigNLMSCC_class, t_sigNLMSCC, x_msi);
+ class_addmethod(sigNLMSCC_class, (t_method)sigNLMSCC_dsp, gensym("dsp"), 0);
+ class_addmethod(sigNLMSCC_class, (t_method)sigNLMSCC_update, gensym("update"), A_FLOAT, 0); // method: downsampling factor of learning (multiple of 2^N)
+ class_addmethod(sigNLMSCC_class, (t_method)sigNLMSCC_beta, gensym("beta"), A_FLOAT, 0); //method: normalized learning rate
+ class_addmethod(sigNLMSCC_class, (t_method)sigNLMSCC_gamma, gensym("gamma"), A_FLOAT, 0); // method: dithering noise related to signal
+ class_sethelpsymbol(sigNLMSCC_class, gensym("iemhelp2/NLMSCC~"));
+}
diff --git a/src/sign_CLNLMS.c b/src/sign_CLNLMS.c
new file mode 100644
index 0000000..e1c1c0a
--- /dev/null
+++ b/src/sign_CLNLMS.c
@@ -0,0 +1,503 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+n_CLNLMS multichannel-constrained leaky normalized LMS algorithm
+lib iem_adaptfilt written by Markus Noisternig & Thomas Musil
+noisternig_AT_iem.at; musil_AT_iem.at
+(c) Institute of Electronic Music and Acoustics, Graz Austria 2005 */
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+
+
+/* ----------------------- n_CLNLMS~ ------------------------------ */
+/* -- multiple Constraint LEAKY Normalized Least Mean Square (linear adaptive FIR-filter) -- */
+
+//* -- first input: reference signal -- */
+/* -- second input: desired signal -- */
+/* -- -- */
+
+/* for further information on adaptive filter design we refer to */
+/* [1] Haykin, "Adaptive Filter Theory", 4th ed, Prentice Hall */
+/* [2] Benesty, "Adaptive Signal Processing", Springer */
+
+typedef struct sign_CLNLMS_kern
+{
+ t_symbol *x_w_array_sym_name;
+ t_float *x_w_array_mem_beg;
+ t_float *x_in_ptr_beg;// memory: sig-in vector
+ t_float *x_out_ptr_beg;// memory: sig-out vector
+ t_float *x_in_hist;// start point double buffer for sig-in history
+} t_sign_CLNLMS_kern;
+
+
+typedef struct sign_CLNLMS
+{
+ t_object x_obj;
+ t_sign_CLNLMS_kern *x_my_kern;
+ t_float *x_des_in_ptr_beg;// memory: desired-in vector
+ t_float *x_err_out_ptr_beg;// memory: error-out vector
+ t_int x_n_io;// number of in-channels and filtered out-channels
+ t_int x_rw_index;// read-write-index
+ t_int x_n_order;// filter order
+ t_int x_update;// rounded by 2^n, yields downsampling of learn-rate
+ t_float x_beta;// learn rate [0 .. 2]
+ t_float x_gamma;// normalization
+ t_float x_kappa;// constreint: treshold of energy (clipping)
+ t_float x_leakage;// leakage-Faktor for NLMS
+ t_outlet *x_out_compressing_bang;
+ t_clock *x_clock;
+ t_float x_msi;
+} t_sign_CLNLMS;
+
+t_class *sign_CLNLMS_class;
+
+static void sign_CLNLMS_tick(t_sign_CLNLMS *x)
+{
+ outlet_bang(x->x_out_compressing_bang);
+}
+
+static t_float *sign_CLNLMS_check_array(t_symbol *array_sym_name, t_int length)
+{
+ t_int n_points;
+ t_garray *a;
+ t_float *vec;
+
+ if(!(a = (t_garray *)pd_findbyclass(array_sym_name, garray_class)))
+ {
+ error("%s: no such array for n_CLNLMS~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(!garray_getfloatarray(a, &n_points, &vec))
+ {
+ error("%s: bad template for n_CLNLMS~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(n_points < length)
+ {
+ error("%s: bad array-size for n_CLNLMS~: %d", array_sym_name->s_name, n_points);
+ return((t_float *)0);
+ }
+ else
+ {
+ return(vec);
+ }
+}
+
+static void sign_CLNLMS_beta(t_sign_CLNLMS *x, t_floatarg f) // learn rate
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 2.0f)
+ f = 2.0f;
+
+ x->x_beta = f;
+}
+
+static void sign_CLNLMS_gamma(t_sign_CLNLMS *x, t_floatarg f) // regularization (dither)
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 1.0f)
+ f = 1.0f;
+
+ x->x_gamma = f;
+}
+
+static void sign_CLNLMS_kappa(t_sign_CLNLMS *x, t_floatarg f) // threshold for w_coeff
+{
+ if(f < 0.0001f)
+ f = 0.0001f;
+ if(f > 10000.0f)
+ f = 10000.0f;
+
+ x->x_kappa = f;
+}
+
+static void sign_CLNLMS_leakage(t_sign_CLNLMS *x, t_floatarg f) // leakage of NLMS
+{
+ if(f < 0.0001f)
+ f = 0.0001f;
+ if(f > 1.0f)
+ f = 1.0f;
+
+ x->x_leakage = f;
+}
+
+static void sign_CLNLMS_update(t_sign_CLNLMS *x, t_floatarg f) // downsample learn rate
+{
+ t_int i=1, u = (t_int)f;
+
+ if(u < 0)
+ u = 0;
+ else
+ {
+ while(i <= u) // convert u for 2^N
+ i *= 2; // round down
+ i /= 2;
+ u = i;
+ }
+ x->x_update = u;
+}
+
+/* ============== DSP ======================= */
+
+static t_int *sign_CLNLMS_perform_zero(t_int *w)
+{
+ t_sign_CLNLMS *x = (t_sign_CLNLMS *)(w[1]);
+ t_int n = (t_int)(w[2]);
+
+ t_int n_io = x->x_n_io;
+ t_float *out;
+ t_int i, j;
+
+ out = x->x_err_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *out++ = 0.0f;
+ for(j=0; j<n_io; j++)
+ {
+ out = x->x_my_kern[j].x_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *out++ = 0.0f;
+ }
+ return (w+3);
+}
+
+static t_int *sign_CLNLMS_perform(t_int *w)
+{
+ t_sign_CLNLMS *x = (t_sign_CLNLMS *)(w[1]);
+ t_int n = (t_int)(w[2]);
+ t_int n_order = x->x_n_order; /* number of filter-order */
+ t_int rw_index2, rw_index = x->x_rw_index;
+ t_int n_io = x->x_n_io;
+ t_float *in;// first sig in
+ t_float din;// second sig in
+ t_float *filt_out;// first sig out
+ t_float *err_out, err_sum;// second sig out
+ t_float *read_in_hist;
+ t_float *w_filt_coeff;
+ t_float my, my_err, sum;
+ t_float beta = x->x_beta;
+ t_float hgamma, gamma = x->x_gamma;
+ t_float hkappa, kappa = x->x_kappa;
+ t_float hleakage, leakage = x->x_leakage;
+ t_int i, j, k, update_counter;
+ t_int update = x->x_update;
+ t_int ord8=n_order&0xfffffff8;
+ t_int ord_residual=n_order&0x7;
+ t_int compressed = 0;
+
+ for(k=0; k<n_io; k++)
+ {
+ if(!x->x_my_kern[k].x_w_array_mem_beg)
+ goto sign_CLNLMSperfzero;// this is Musil/Miller style
+ }
+
+ hgamma = gamma * gamma * (float)n_order;
+ //hkappa = kappa * kappa * (float)n_order;
+ hkappa = kappa; // kappa regards to energy value, else use line above
+
+ for(i=0, update_counter=0; i<n; i++)// history and (block-)convolution
+ {
+ rw_index2 = rw_index + n_order;
+
+ for(k=0; k<n_io; k++)// times n_io
+ {
+ x->x_my_kern[k].x_in_hist[rw_index] = x->x_my_kern[k].x_in_ptr_beg[i]; // save inputs into variabel & history
+ x->x_my_kern[k].x_in_hist[rw_index+n_order] = x->x_my_kern[k].x_in_ptr_beg[i];
+ }
+ din = x->x_des_in_ptr_beg[i];
+
+// begin convolution
+ err_sum = din;
+ for(k=0; k<n_io; k++)// times n_io
+ {
+ sum = 0.0f;
+ w_filt_coeff = x->x_my_kern[k].x_w_array_mem_beg; // Musil's special convolution buffer struct
+ read_in_hist = &x->x_my_kern[k].x_in_hist[rw_index2];
+ for(j=0; j<ord8; j+=8) // loop unroll 8 taps
+ {
+ sum += w_filt_coeff[0] * read_in_hist[0];
+ sum += w_filt_coeff[1] * read_in_hist[-1];
+ sum += w_filt_coeff[2] * read_in_hist[-2];
+ sum += w_filt_coeff[3] * read_in_hist[-3];
+ sum += w_filt_coeff[4] * read_in_hist[-4];
+ sum += w_filt_coeff[5] * read_in_hist[-5];
+ sum += w_filt_coeff[6] * read_in_hist[-6];
+ sum += w_filt_coeff[7] * read_in_hist[-7];
+ w_filt_coeff += 8;
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // for filter order < 2^N
+ sum += w_filt_coeff[j] * read_in_hist[-j];
+
+ x->x_my_kern[k].x_out_ptr_beg[i] = sum;
+ err_sum -= sum;
+ }
+ x->x_err_out_ptr_beg[i] = err_sum;
+// end convolution
+
+ if(update) // downsampling of learn rate
+ {
+ update_counter++;
+ if(update_counter >= update)
+ {
+ update_counter = 0;
+
+ for(k=0; k<n_io; k++)// times n_io
+ {
+ sum = 0.0f;// calculate energy for last n-order samples in filter
+ read_in_hist = &x->x_my_kern[k].x_in_hist[rw_index2];
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ sum += read_in_hist[0] * read_in_hist[0];
+ sum += read_in_hist[-1] * read_in_hist[-1];
+ sum += read_in_hist[-2] * read_in_hist[-2];
+ sum += read_in_hist[-3] * read_in_hist[-3];
+ sum += read_in_hist[-4] * read_in_hist[-4];
+ sum += read_in_hist[-5] * read_in_hist[-5];
+ sum += read_in_hist[-6] * read_in_hist[-6];
+ sum += read_in_hist[-7] * read_in_hist[-7];
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ sum += read_in_hist[-j] * read_in_hist[-j]; // [-j] only valid for Musil's double buffer structure
+ sum += hgamma; // convert gamma corresponding to filter order
+ my = beta / sum;// calculate mue
+
+ my_err = my * err_sum;
+ w_filt_coeff = x->x_my_kern[k].x_w_array_mem_beg;
+ read_in_hist = &x->x_my_kern[k].x_in_hist[rw_index2];
+ sum = 0.0f;
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ w_filt_coeff[0] = leakage * w_filt_coeff[0] + read_in_hist[0] * my_err;
+ sum += w_filt_coeff[0] * w_filt_coeff[0];
+ w_filt_coeff[1] = leakage * w_filt_coeff[1] + read_in_hist[-1] * my_err;
+ sum += w_filt_coeff[1] * w_filt_coeff[1];
+ w_filt_coeff[2] = leakage * w_filt_coeff[2] + read_in_hist[-2] * my_err;
+ sum += w_filt_coeff[2] * w_filt_coeff[2];
+ w_filt_coeff[3] = leakage * w_filt_coeff[3] + read_in_hist[-3] * my_err;
+ sum += w_filt_coeff[3] * w_filt_coeff[3];
+ w_filt_coeff[4] = leakage * w_filt_coeff[4] + read_in_hist[-4] * my_err;
+ sum += w_filt_coeff[4] * w_filt_coeff[4];
+ w_filt_coeff[5] = leakage * w_filt_coeff[5] + read_in_hist[-5] * my_err;
+ sum += w_filt_coeff[5] * w_filt_coeff[5];
+ w_filt_coeff[6] = leakage * w_filt_coeff[6] + read_in_hist[-6] * my_err;
+ sum += w_filt_coeff[6] * w_filt_coeff[6];
+ w_filt_coeff[7] = leakage * w_filt_coeff[7] + read_in_hist[-7] * my_err;
+ sum += w_filt_coeff[7] * w_filt_coeff[7];
+ w_filt_coeff += 8;
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ {
+ w_filt_coeff[j] = leakage * w_filt_coeff[j] + read_in_hist[-j] * my_err;
+ sum += w_filt_coeff[j] * w_filt_coeff[j];
+ }
+ if(sum > hkappa)
+ {
+ compressed = 1;
+ my = sqrt(hkappa/sum);
+ w_filt_coeff = x->x_my_kern[k].x_w_array_mem_beg;
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ w_filt_coeff[0] *= my;
+ w_filt_coeff[1] *= my;
+ w_filt_coeff[2] *= my;
+ w_filt_coeff[3] *= my;
+ w_filt_coeff[4] *= my;
+ w_filt_coeff[5] *= my;
+ w_filt_coeff[6] *= my;
+ w_filt_coeff[7] *= my;
+ w_filt_coeff += 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ w_filt_coeff[j] *= my;
+ }
+ }
+ }
+ }
+ rw_index++;
+ if(rw_index >= n_order)
+ rw_index -= n_order;
+ }
+
+
+ x->x_rw_index = rw_index; // wieder in die garage stellen
+
+ if(compressed)
+ clock_delay(x->x_clock, 0);
+
+ return(w+3);
+
+sign_CLNLMSperfzero:
+
+ err_out = x->x_err_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *err_out++ = 0.0f;
+ for(j=0; j<n_io; j++)
+ {
+ filt_out = x->x_my_kern[j].x_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *filt_out++ = 0.0f;
+ }
+
+ return(w+3);
+}
+
+static void sign_CLNLMS_dsp(t_sign_CLNLMS *x, t_signal **sp)
+{
+ t_int i, n = sp[0]->s_n;
+ t_int ok_w = 1;
+ t_int m = x->x_n_io;
+
+ for(i=0; i<m; i++)
+ x->x_my_kern[i].x_in_ptr_beg = sp[i]->s_vec;
+ x->x_des_in_ptr_beg = sp[m]->s_vec;
+ for(i=0; i<m; i++)
+ x->x_my_kern[i].x_out_ptr_beg = sp[i+m+1]->s_vec;
+ x->x_err_out_ptr_beg = sp[2*m+1]->s_vec;
+
+ for(i=0; i<m; i++)
+ {
+ x->x_my_kern[i].x_w_array_mem_beg = sign_CLNLMS_check_array(x->x_my_kern[i].x_w_array_sym_name, x->x_n_order);
+ if(!x->x_my_kern[i].x_w_array_mem_beg)
+ ok_w = 0;
+ }
+
+ if(!ok_w)
+ dsp_add(sign_CLNLMS_perform_zero, 2, x, n);
+ else
+ dsp_add(sign_CLNLMS_perform, 2, x, n);
+}
+
+
+/* setup/setdown things */
+
+static void sign_CLNLMS_free(t_sign_CLNLMS *x)
+{
+ t_int i, n_io=x->x_n_io, n_order=x->x_n_order;
+
+ for(i=0; i<n_io; i++)
+ freebytes(x->x_my_kern[i].x_in_hist, 2*x->x_n_order*sizeof(t_float));
+ freebytes(x->x_my_kern, n_io*sizeof(t_sign_CLNLMS_kern));
+
+ clock_free(x->x_clock);
+}
+
+static void *sign_CLNLMS_new(t_symbol *s, t_int argc, t_atom *argv)
+{
+ t_sign_CLNLMS *x = (t_sign_CLNLMS *)pd_new(sign_CLNLMS_class);
+ char buffer[400];
+ t_int i, n_order=39, n_io=1;
+ t_symbol *w_name;
+ t_float beta=0.1f;
+ t_float gamma=0.00001f;
+ t_float kappa = 1.0f;
+ t_float leakage = 0.99f;
+
+ if((argc >= 7) &&
+ IS_A_FLOAT(argv,0) && //IS_A_FLOAT/SYMBOL from iemlib.h
+ IS_A_FLOAT(argv,1) &&
+ IS_A_FLOAT(argv,2) &&
+ IS_A_FLOAT(argv,3) &&
+ IS_A_FLOAT(argv,4) &&
+ IS_A_FLOAT(argv,5) &&
+ IS_A_SYMBOL(argv,6))
+ {
+ n_io = (t_int)atom_getintarg(0, argc, argv);
+ n_order = (t_int)atom_getintarg(1, argc, argv);
+ beta = (t_float)atom_getfloatarg(2, argc, argv);
+ gamma = (t_float)atom_getfloatarg(3, argc, argv);
+ kappa = (t_float)atom_getfloatarg(4, argc, argv);
+ leakage = (t_float)atom_getfloatarg(5, argc, argv);
+ w_name = (t_symbol *)atom_getsymbolarg(6, argc, argv);
+
+ if(beta < 0.0f)
+ beta = 0.0f;
+ if(beta > 2.0f)
+ beta = 2.0f;
+
+ if(gamma < 0.0f)
+ gamma = 0.0f;
+ if(gamma > 1.0f)
+ gamma = 1.0f;
+
+ if(kappa < 0.0001f)
+ kappa = 0.0001f;
+ if(kappa > 10000.0f)
+ kappa = 10000.0f;
+
+ if(leakage < 0.0001f)
+ leakage = 0.0001f;
+ if(leakage > 1.0f)
+ leakage = 1.0f;
+
+ if(n_order < 2)
+ n_order = 2;
+ if(n_order > 11111)
+ n_order = 11111;
+
+ if(n_io < 1)
+ n_io = 1;
+ if(n_io > 60)
+ n_io = 60;
+
+ for(i=0; i<n_io; i++)
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ for(i=0; i<=n_io; i++)
+ outlet_new(&x->x_obj, &s_signal);
+
+ x->x_out_compressing_bang = outlet_new(&x->x_obj, &s_bang);
+
+ x->x_msi = 0;
+ x->x_n_io = n_io;
+ x->x_n_order = n_order;
+ x->x_update = 0;
+ x->x_beta = beta;
+ x->x_gamma = gamma;
+ x->x_kappa = kappa;
+ x->x_leakage = leakage;
+ x->x_my_kern = (t_sign_CLNLMS_kern *)getbytes(x->x_n_io*sizeof(t_sign_CLNLMS_kern));
+ for(i=0; i<n_io; i++)
+ {
+ sprintf(buffer, "%d_%s", i+1, w_name->s_name);
+ x->x_my_kern[i].x_w_array_sym_name = gensym(buffer);
+ x->x_my_kern[i].x_w_array_mem_beg = (t_float *)0;
+ x->x_my_kern[i].x_in_hist = (t_float *)getbytes(2*x->x_n_order*sizeof(t_float));
+ }
+ x->x_clock = clock_new(x, (t_method)sign_CLNLMS_tick);
+
+ return(x);
+ }
+ else
+ {
+ post("n_CLNLMSC~-ERROR: need 6 float- + 1 symbol-arguments:");
+ post(" number_of_filters + order_of_filters + learnrate_beta + security_value_gamma + threshold_kappa + leakage_factor_lambda + array_name_taps");
+ return(0);
+ }
+}
+
+void sign_CLNLMS_setup(void)
+{
+ sign_CLNLMS_class = class_new(gensym("n_CLNLMS~"), (t_newmethod)sign_CLNLMS_new, (t_method)sign_CLNLMS_free,
+ sizeof(t_sign_CLNLMS), 0, A_GIMME, 0);
+ CLASS_MAINSIGNALIN(sign_CLNLMS_class, t_sign_CLNLMS, x_msi);
+ class_addmethod(sign_CLNLMS_class, (t_method)sign_CLNLMS_dsp, gensym("dsp"), 0);
+ class_addmethod(sign_CLNLMS_class, (t_method)sign_CLNLMS_update, gensym("update"), A_FLOAT, 0); // method: downsampling factor of learning (multiple of 2^N)
+ class_addmethod(sign_CLNLMS_class, (t_method)sign_CLNLMS_beta, gensym("beta"), A_FLOAT, 0); //method: normalized learning rate
+ class_addmethod(sign_CLNLMS_class, (t_method)sign_CLNLMS_gamma, gensym("gamma"), A_FLOAT, 0); // method: dithering noise related to signal
+ class_addmethod(sign_CLNLMS_class, (t_method)sign_CLNLMS_kappa, gensym("kappa"), A_FLOAT, 0); // method: threshold for compressing w_coeff
+ class_addmethod(sign_CLNLMS_class, (t_method)sign_CLNLMS_leakage, gensym("leakage"), A_FLOAT, 0); // method: leakage factor [0 1] for w update
+ class_sethelpsymbol(sign_CLNLMS_class, gensym("iemhelp2/n_CLNLMS~"));
+}
diff --git a/src/sign_CNLMS.c b/src/sign_CNLMS.c
new file mode 100644
index 0000000..a97c1ed
--- /dev/null
+++ b/src/sign_CNLMS.c
@@ -0,0 +1,482 @@
+/* For information on usage and redistribution, and for a DISCLAIMER OF ALL
+* WARRANTIES, see the file, "LICENSE.txt," in this distribution.
+
+n_CNLMS multichannel-constrained (non leaky) normalized LMS algorithm
+lib iem_adaptfilt written by Markus Noisternig & Thomas Musil
+noisternig_AT_iem.at; musil_AT_iem.at
+(c) Institute of Electronic Music and Acoustics, Graz Austria 2005 */
+
+#ifdef NT
+#pragma warning( disable : 4244 )
+#pragma warning( disable : 4305 )
+#endif
+
+
+#include "m_pd.h"
+#include "iemlib.h"
+#include <math.h>
+#include <stdio.h>
+#include <string.h>
+
+
+/* ----------------------- n_CNLMS~ ------------------------------ */
+/* -- multi-channel Constraint Normalized Least Mean Square (linear adaptive FIR-filter) -- */
+
+/* -- first input: reference signal -- */
+/* -- second input: desired signal -- */
+/* -- -- */
+
+/* for further information on adaptive filter design we refer to */
+/* [1] Haykin, "Adaptive Filter Theory", 4th ed, Prentice Hall */
+/* [2] Benesty, "Adaptive Signal Processing", Springer */
+
+typedef struct sign_CNLMS_kern
+{
+ t_symbol *x_w_array_sym_name;
+ t_float *x_w_array_mem_beg;
+ t_float *x_in_ptr_beg;// memory: sig-in vector
+ t_float *x_out_ptr_beg;// memory: sig-out vector
+ t_float *x_in_hist;// start point double buffer for sig-in history
+} t_sign_CNLMS_kern;
+
+
+typedef struct sign_CNLMS
+{
+ t_object x_obj;
+ t_sign_CNLMS_kern *x_my_kern;
+ t_float *x_des_in_ptr_beg;// memory: desired-in vector
+ t_float *x_err_out_ptr_beg;// memory: error-out vector
+ t_int x_n_io;// number of in-channels and filtered out-channels
+ t_int x_rw_index;// read-write-index
+ t_int x_n_order;// filter order
+ t_int x_update;// rounded by 2^n, yields downsampling of update rate
+ t_float x_beta;// learn rate [0 .. 2]
+ t_float x_gamma;// normalization
+ t_float x_kappa;// constraint: threshold of energy (clipping)
+ t_outlet *x_out_compressing_bang;
+ t_clock *x_clock;
+ t_float x_msi;
+} t_sign_CNLMS;
+
+t_class *sign_CNLMS_class;
+
+static void sign_CNLMS_tick(t_sign_CNLMS *x)
+{
+ outlet_bang(x->x_out_compressing_bang);
+}
+
+static t_float *sign_CNLMS_check_array(t_symbol *array_sym_name, t_int length)
+{
+ t_int n_points;
+ t_garray *a;
+ t_float *vec;
+
+ if(!(a = (t_garray *)pd_findbyclass(array_sym_name, garray_class)))
+ {
+ error("%s: no such array for n_CNLMS~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(!garray_getfloatarray(a, &n_points, &vec))
+ {
+ error("%s: bad template for n_CNLMS~", array_sym_name->s_name);
+ return((t_float *)0);
+ }
+ else if(n_points < length)
+ {
+ error("%s: bad array-size for n_CNLMS~: %d", array_sym_name->s_name, n_points);
+ return((t_float *)0);
+ }
+ else
+ {
+ return(vec);
+ }
+}
+
+static void sign_CNLMS_beta(t_sign_CNLMS *x, t_floatarg f) // learn rate
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 2.0f)
+ f = 2.0f;
+
+ x->x_beta = f;
+}
+
+static void sign_CNLMS_gamma(t_sign_CNLMS *x, t_floatarg f) // regularization (dither)
+{
+ if(f < 0.0f)
+ f = 0.0f;
+ if(f > 1.0f)
+ f = 1.0f;
+
+ x->x_gamma = f;
+}
+
+static void sign_CNLMS_kappa(t_sign_CNLMS *x, t_floatarg f) // threshold for w_coeff
+{
+ if(f < 0.0001f)
+ f = 0.0001f;
+ if(f > 10000.0f)
+ f = 10000.0f;
+
+ x->x_kappa = f;
+}
+
+
+static void sign_CNLMS_update(t_sign_CNLMS *x, t_floatarg f) // downsampling of learn rate
+{
+ t_int i=1, u = (t_int)f;
+
+ if(u < 0)
+ u = 0;
+ else
+ {
+ while(i <= u) // convert u for 2^N
+ i *= 2; // round downward
+ i /= 2;
+ u = i;
+ }
+ x->x_update = u;
+}
+
+/* ============== DSP ======================= */
+
+static t_int *sign_CNLMS_perform_zero(t_int *w)
+{
+ t_sign_CNLMS *x = (t_sign_CNLMS *)(w[1]);
+ t_int n = (t_int)(w[2]);
+
+ t_int n_io = x->x_n_io;
+ t_float *out;
+ t_int i, j;
+
+ out = x->x_err_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *out++ = 0.0f;
+ for(j=0; j<n_io; j++)
+ {
+ out = x->x_my_kern[j].x_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *out++ = 0.0f;
+ }
+ return (w+3);
+}
+
+static t_int *sign_CNLMS_perform(t_int *w)
+{
+ t_sign_CNLMS *x = (t_sign_CNLMS *)(w[1]);
+ t_int n = (t_int)(w[2]);
+ t_int n_order = x->x_n_order; /* filter-order */
+ t_int rw_index2, rw_index = x->x_rw_index;
+ t_int n_io = x->x_n_io;
+ t_float *in;// first sig in
+ t_float din;// second sig in
+ t_float *filt_out;// first sig out
+ t_float *err_out, err_sum;// second sig out
+ t_float *read_in_hist;
+ t_float *w_filt_coeff;
+ t_float my, my_err, sum;
+ t_float beta = x->x_beta;
+ t_float hgamma, gamma = x->x_gamma;
+ t_float hkappa, kappa = x->x_kappa;
+ t_int i, j, k, update_counter;
+ t_int update = x->x_update;
+ t_int ord8=n_order&0xfffffff8;
+ t_int ord_residual=n_order&0x7;
+ t_int compressed = 0;
+
+ for(k=0; k<n_io; k++)
+ {
+ if(!x->x_my_kern[k].x_w_array_mem_beg)
+ goto sign_CNLMSperfzero;// this is Musil/Miller style
+ }
+
+ hgamma = gamma * gamma * (float)n_order;
+ //hkappa = kappa * kappa * (float)n_order;
+ hkappa = kappa;// kappa regards to energy value, else use line above
+
+ for(i=0, update_counter=0; i<n; i++)// history and (block-)convolution
+ {
+ rw_index2 = rw_index + n_order;
+
+ for(k=0; k<n_io; k++)// times n_io
+ {
+ x->x_my_kern[k].x_in_hist[rw_index] = x->x_my_kern[k].x_in_ptr_beg[i]; // save inputs into variabel & history
+ x->x_my_kern[k].x_in_hist[rw_index+n_order] = x->x_my_kern[k].x_in_ptr_beg[i];
+ }
+ din = x->x_des_in_ptr_beg[i];
+
+// begin convolution
+ err_sum = din;
+ for(k=0; k<n_io; k++)// times n_io
+ {
+ sum = 0.0f;
+ w_filt_coeff = x->x_my_kern[k].x_w_array_mem_beg; // Musil's special convolution buffer struct
+ read_in_hist = &x->x_my_kern[k].x_in_hist[rw_index2];
+ for(j=0; j<ord8; j+=8) // loop unroll 8 taps
+ {
+ sum += w_filt_coeff[0] * read_in_hist[0];
+ sum += w_filt_coeff[1] * read_in_hist[-1];
+ sum += w_filt_coeff[2] * read_in_hist[-2];
+ sum += w_filt_coeff[3] * read_in_hist[-3];
+ sum += w_filt_coeff[4] * read_in_hist[-4];
+ sum += w_filt_coeff[5] * read_in_hist[-5];
+ sum += w_filt_coeff[6] * read_in_hist[-6];
+ sum += w_filt_coeff[7] * read_in_hist[-7];
+ w_filt_coeff += 8;
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // for filter order < 2^N
+ sum += w_filt_coeff[j] * read_in_hist[-j];
+
+ x->x_my_kern[k].x_out_ptr_beg[i] = sum;
+ err_sum -= sum;
+ }
+ x->x_err_out_ptr_beg[i] = err_sum;
+// end convolution
+
+ if(update) // downsampling of learn rate
+ {
+ update_counter++;
+ if(update_counter >= update)
+ {
+ update_counter = 0;
+
+ for(k=0; k<n_io; k++)// times n_io
+ {
+ sum = 0.0f;// calculate energy for last n-order samples in filter
+ read_in_hist = &x->x_my_kern[k].x_in_hist[rw_index2];
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ sum += read_in_hist[0] * read_in_hist[0];
+ sum += read_in_hist[-1] * read_in_hist[-1];
+ sum += read_in_hist[-2] * read_in_hist[-2];
+ sum += read_in_hist[-3] * read_in_hist[-3];
+ sum += read_in_hist[-4] * read_in_hist[-4];
+ sum += read_in_hist[-5] * read_in_hist[-5];
+ sum += read_in_hist[-6] * read_in_hist[-6];
+ sum += read_in_hist[-7] * read_in_hist[-7];
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ sum += read_in_hist[-j] * read_in_hist[-j]; // [-j] only valid for Musil's double buffer structure
+ sum += hgamma; // convert gamma corresponding to filter order
+ my = beta / sum;// calculate mue
+
+ my_err = my * err_sum;
+ w_filt_coeff = x->x_my_kern[k].x_w_array_mem_beg;
+ read_in_hist = &x->x_my_kern[k].x_in_hist[rw_index2];
+ sum = 0.0f;
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ w_filt_coeff[0] += read_in_hist[0] * my_err;
+ sum += w_filt_coeff[0] * w_filt_coeff[0];
+ w_filt_coeff[1] += read_in_hist[-1] * my_err;
+ sum += w_filt_coeff[1] * w_filt_coeff[1];
+ w_filt_coeff[2] += read_in_hist[-2] * my_err;
+ sum += w_filt_coeff[2] * w_filt_coeff[2];
+ w_filt_coeff[3] += read_in_hist[-3] * my_err;
+ sum += w_filt_coeff[3] * w_filt_coeff[3];
+ w_filt_coeff[4] += read_in_hist[-4] * my_err;
+ sum += w_filt_coeff[4] * w_filt_coeff[4];
+ w_filt_coeff[5] += read_in_hist[-5] * my_err;
+ sum += w_filt_coeff[5] * w_filt_coeff[5];
+ w_filt_coeff[6] += read_in_hist[-6] * my_err;
+ sum += w_filt_coeff[6] * w_filt_coeff[6];
+ w_filt_coeff[7] += read_in_hist[-7] * my_err;
+ sum += w_filt_coeff[7] * w_filt_coeff[7];
+ w_filt_coeff += 8;
+ read_in_hist -= 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ {
+ w_filt_coeff[j] += read_in_hist[-j] * my_err;
+ sum += w_filt_coeff[j] * w_filt_coeff[j];
+ }
+ if(sum > hkappa)
+ {
+ compressed = 1;
+ my = sqrt(hkappa/sum);
+ w_filt_coeff = x->x_my_kern[k].x_w_array_mem_beg;
+ for(j=0; j<ord8; j+=8) // unrolling quadrature calc
+ {
+ w_filt_coeff[0] *= my;
+ w_filt_coeff[1] *= my;
+ w_filt_coeff[2] *= my;
+ w_filt_coeff[3] *= my;
+ w_filt_coeff[4] *= my;
+ w_filt_coeff[5] *= my;
+ w_filt_coeff[6] *= my;
+ w_filt_coeff[7] *= my;
+ w_filt_coeff += 8;
+ }
+ for(j=0; j<ord_residual; j++) // residual
+ w_filt_coeff[j] *= my;
+ }
+ }
+ }
+ }
+ rw_index++;
+ if(rw_index >= n_order)
+ rw_index -= n_order;
+ }
+
+
+ x->x_rw_index = rw_index; // back to start
+
+ if(compressed)
+ clock_delay(x->x_clock, 0);
+
+ return(w+3);
+
+sign_CNLMSperfzero:
+
+ err_out = x->x_err_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *err_out++ = 0.0f;
+ for(j=0; j<n_io; j++)
+ {
+ filt_out = x->x_my_kern[j].x_out_ptr_beg;
+ for(i=0; i<n; i++)
+ *filt_out++ = 0.0f;
+ }
+
+ return(w+3);
+}
+
+static void sign_CNLMS_dsp(t_sign_CNLMS *x, t_signal **sp)
+{
+ t_int i, n = sp[0]->s_n;
+ t_int ok_w = 1;
+ t_int m = x->x_n_io;
+
+ for(i=0; i<m; i++)
+ x->x_my_kern[i].x_in_ptr_beg = sp[i]->s_vec;
+ x->x_des_in_ptr_beg = sp[m]->s_vec;
+ for(i=0; i<m; i++)
+ x->x_my_kern[i].x_out_ptr_beg = sp[i+m+1]->s_vec;
+ x->x_err_out_ptr_beg = sp[2*m+1]->s_vec;
+
+ for(i=0; i<m; i++)
+ {
+ x->x_my_kern[i].x_w_array_mem_beg = sign_CNLMS_check_array(x->x_my_kern[i].x_w_array_sym_name, x->x_n_order);
+ if(!x->x_my_kern[i].x_w_array_mem_beg)
+ ok_w = 0;
+ }
+
+ if(!ok_w)
+ dsp_add(sign_CNLMS_perform_zero, 2, x, n);
+ else
+ dsp_add(sign_CNLMS_perform, 2, x, n);
+}
+
+
+/* setup/setdown things */
+
+static void sign_CNLMS_free(t_sign_CNLMS *x)
+{
+ t_int i, n_io=x->x_n_io, n_order=x->x_n_order;
+
+ for(i=0; i<n_io; i++)
+ freebytes(x->x_my_kern[i].x_in_hist, 2*x->x_n_order*sizeof(t_float));
+ freebytes(x->x_my_kern, n_io*sizeof(t_sign_CNLMS_kern));
+
+ clock_free(x->x_clock);
+}
+
+static void *sign_CNLMS_new(t_symbol *s, t_int argc, t_atom *argv)
+{
+ t_sign_CNLMS *x = (t_sign_CNLMS *)pd_new(sign_CNLMS_class);
+ char buffer[400];
+ t_int i, n_order=39, n_io=1;
+ t_symbol *w_name;
+ t_float beta=0.1f;
+ t_float gamma=0.00001f;
+ t_float kappa = 1.0f;
+
+ if((argc >= 6) &&
+ IS_A_FLOAT(argv,0) && //IS_A_FLOAT/SYMBOL from iemlib.h
+ IS_A_FLOAT(argv,1) &&
+ IS_A_FLOAT(argv,2) &&
+ IS_A_FLOAT(argv,3) &&
+ IS_A_FLOAT(argv,4) &&
+ IS_A_SYMBOL(argv,5))
+ {
+ n_io = (t_int)atom_getintarg(0, argc, argv);
+ n_order = (t_int)atom_getintarg(1, argc, argv);
+ beta = (t_float)atom_getfloatarg(2, argc, argv);
+ gamma = (t_float)atom_getfloatarg(3, argc, argv);
+ kappa = (t_float)atom_getfloatarg(4, argc, argv);
+ w_name = (t_symbol *)atom_getsymbolarg(5, argc, argv);
+
+ if(beta < 0.0f)
+ beta = 0.0f;
+ if(beta > 2.0f)
+ beta = 2.0f;
+
+ if(gamma < 0.0f)
+ gamma = 0.0f;
+ if(gamma > 1.0f)
+ gamma = 1.0f;
+
+ if(kappa < 0.0001f)
+ kappa = 0.0001f;
+ if(kappa > 10000.0f)
+ kappa = 10000.0f;
+
+ if(n_order < 2)
+ n_order = 2;
+ if(n_order > 11111)
+ n_order = 11111;
+
+ if(n_io < 1)
+ n_io = 1;
+ if(n_io > 60)
+ n_io = 60;
+
+ for(i=0; i<n_io; i++)
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
+ for(i=0; i<=n_io; i++)
+ outlet_new(&x->x_obj, &s_signal);
+
+ x->x_out_compressing_bang = outlet_new(&x->x_obj, &s_bang);
+
+ x->x_msi = 0;
+ x->x_n_io = n_io;
+ x->x_n_order = n_order;
+ x->x_update = 0;
+ x->x_beta = beta;
+ x->x_gamma = gamma;
+ x->x_kappa = kappa;
+ x->x_my_kern = (t_sign_CNLMS_kern *)getbytes(x->x_n_io*sizeof(t_sign_CNLMS_kern));
+ for(i=0; i<n_io; i++)
+ {
+ sprintf(buffer, "%d_%s", i+1, w_name->s_name);
+ x->x_my_kern[i].x_w_array_sym_name = gensym(buffer);
+ x->x_my_kern[i].x_w_array_mem_beg = (t_float *)0;
+ x->x_my_kern[i].x_in_hist = (t_float *)getbytes(2*x->x_n_order*sizeof(t_float));
+ }
+ x->x_clock = clock_new(x, (t_method)sign_CNLMS_tick);
+
+ return(x);
+ }
+ else
+ {
+ post("n_CNLMSC~-ERROR: need 5 float- + 1 symbol-arguments:");
+ post(" number_of_filters + order_of_filters + learnrate_beta + security_value_gamma + threshold_kappa + array_name_taps");
+ return(0);
+ }
+}
+
+void sign_CNLMS_setup(void)
+{
+ sign_CNLMS_class = class_new(gensym("n_CNLMS~"), (t_newmethod)sign_CNLMS_new, (t_method)sign_CNLMS_free,
+ sizeof(t_sign_CNLMS), 0, A_GIMME, 0);
+ CLASS_MAINSIGNALIN(sign_CNLMS_class, t_sign_CNLMS, x_msi);
+ class_addmethod(sign_CNLMS_class, (t_method)sign_CNLMS_dsp, gensym("dsp"), 0);
+ class_addmethod(sign_CNLMS_class, (t_method)sign_CNLMS_update, gensym("update"), A_FLOAT, 0); // method: downsampling factor of learning (multiple of 2^N)
+ class_addmethod(sign_CNLMS_class, (t_method)sign_CNLMS_beta, gensym("beta"), A_FLOAT, 0); //method: normalized learning rate
+ class_addmethod(sign_CNLMS_class, (t_method)sign_CNLMS_gamma, gensym("gamma"), A_FLOAT, 0); // method: dithering noise related to signal
+ class_addmethod(sign_CNLMS_class, (t_method)sign_CNLMS_kappa, gensym("kappa"), A_FLOAT, 0); // method: threshold for compressing w_coeff
+ class_sethelpsymbol(sign_CNLMS_class, gensym("iemhelp2/n_CNLMS~"));
+}