aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormusil <tmusil@users.sourceforge.net>2011-01-14 13:23:58 +0000
committermusil <tmusil@users.sourceforge.net>2011-01-14 13:23:58 +0000
commit02f7eeb2e1225f575516c53128835f8eb6da3f8d (patch)
treeed769c9bffb53c1be4f0b99940b76fb0d753419c
parent1052efc71480893554b6888a3e156a0988061f63 (diff)
now better
svn path=/trunk/externals/iem/iem_adaptfilt/; revision=14741
-rw-r--r--help/NLMSerr_in~-help.pd75
-rw-r--r--src/NLMSerr_in~.c37
2 files changed, 55 insertions, 57 deletions
diff --git a/help/NLMSerr_in~-help.pd b/help/NLMSerr_in~-help.pd
index 328a888..6882aea 100644
--- a/help/NLMSerr_in~-help.pd
+++ b/help/NLMSerr_in~-help.pd
@@ -1,19 +1,19 @@
#N canvas 378 66 925 637 10;
#N canvas 0 22 450 300 (subpatch) 0;
-#X array W 40 float 0;
-#X coords 0 1 39 -1 200 140 1;
-#X restore 545 340 graph;
+#X array W 200 float 0;
+#X coords 0 1 199 -1 200 140 1;
+#X restore 588 339 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 24 tgl 15 0 empty empty empty 0 -6 0 8 -225280 -1 -1 1 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 563 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 text 516 230 2.arg: <float> learn-rate = beta;
+#X obj 225 185 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;
@@ -63,8 +63,8 @@
#X text 29 508 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 566 220 (array-sizes have to be >= then FIR_size);
+#X text 516 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;
@@ -121,14 +121,14 @@
#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 516 250 4.arg: <symbol> table-name of W;
+#X text 516 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
+#X obj 517 187 cnv 15 68 17 empty empty empty 20 12 0 14 -225280 -66577
0;
#N canvas 0 22 499 295 FORMULAS 0;
#X obj 167 52 cnv 15 150 40 empty empty empty 20 12 0 14 -225280 -66577
@@ -157,7 +157,7 @@
#X text 116 55 output:;
#X text 26 210 coefficient iteration:;
#X text 188 211 W(k+1 \, i) = W(k \, i) + my(n)* e(n)* x(n);
-#X restore 455 187 pd FORMULAS;
+#X restore 518 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 - - -;
@@ -166,35 +166,39 @@
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 text 518 169 Normalized Least Mean Square (linear adaptive FIR-filter)
;
-#X text 451 268 (C) 2005 \, m.noisternig & t.musil \, IEM \, Graz \,
+#X text 514 268 (C) 2005 \, m.noisternig & t.musil \, IEM \, Graz \,
Austria;
-#X text 479 281 [noisternig \, musil]_AT_iem.at;
-#X obj 53 450 NLMSerr_in~ 32 0.1 1e-05 W;
-#X obj 20 390 delwrite~ causal_del 2;
-#X msg 756 387 64 44.1;
-#X obj 760 415 /;
-#X obj 760 442 print;
-#X obj 20 411 delread~ causal_del 1.45126;
+#X text 542 281 [noisternig \, musil]_AT_iem.at;
+#X obj 247 211 delwrite~ causal_del 2;
+#X msg 825 34 64 44.1;
+#X obj 829 62 /;
+#X obj 829 89 print;
#X obj 226 475 delwrite~ feedback_del 2;
-#X obj 351 358 delread~ feedback_del 0;
-#X obj 248 415 -~;
+#X obj 301 383 -~;
#X text 249 437 err;
#X text 351 376 filt out;
-#X connect 1 0 72 0;
-#X connect 2 0 72 0;
+#X msg 578 541 \; W const 0;
+#X obj 54 413 delread~ causal_del 1.45126;
+#X obj 351 358 delread~ feedback_del 1.45126;
+#X obj 301 407 *~ -1;
+#X msg 366 424 -1;
+#X msg 412 425 1;
+#X obj 53 450 NLMSerr_in~ 192 0.01 1e-05 W;
+#X connect 1 0 86 0;
+#X connect 2 0 86 0;
#X connect 3 0 4 0;
#X connect 4 0 5 0;
#X connect 4 1 6 0;
+#X connect 9 0 72 0;
#X connect 9 0 24 0;
-#X connect 9 0 73 0;
#X connect 10 0 11 0;
#X connect 11 0 68 0;
-#X connect 13 0 72 0;
+#X connect 13 0 86 0;
#X connect 17 0 18 0;
#X connect 19 0 20 0;
-#X connect 24 0 80 0;
+#X connect 24 0 77 0;
#X connect 25 0 51 0;
#X connect 37 0 36 1;
#X connect 39 0 36 0;
@@ -205,10 +209,13 @@ Austria;
#X connect 64 0 2 0;
#X connect 67 0 13 0;
#X connect 68 0 1 0;
-#X connect 72 0 17 0;
-#X connect 72 0 78 0;
+#X connect 73 0 74 0;
#X connect 74 0 75 0;
-#X connect 75 0 76 0;
-#X connect 77 0 72 0;
-#X connect 79 0 80 1;
-#X connect 80 0 72 1;
+#X connect 77 0 83 0;
+#X connect 81 0 86 0;
+#X connect 82 0 77 1;
+#X connect 83 0 86 1;
+#X connect 84 0 83 1;
+#X connect 85 0 83 1;
+#X connect 86 0 17 0;
+#X connect 86 0 76 0;
diff --git a/src/NLMSerr_in~.c b/src/NLMSerr_in~.c
index 623393c..8c0c6dd 100644
--- a/src/NLMSerr_in~.c
+++ b/src/NLMSerr_in~.c
@@ -6,11 +6,6 @@ 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"
@@ -115,20 +110,16 @@ static void NLMSerr_in_tilde_update(t_NLMSerr_in_tilde *x, t_floatarg f) // down
static t_int *NLMSerr_in_tilde_perform_zero(t_int *w)
{
- t_NLMSerr_in_tilde *x = (t_NLMSerr_in_tilde *)(w[1]);
- t_int n = (t_int)(w[2]);
-
- t_float **io = x->x_io_ptr_beg;
- t_float *out;
+ t_NLMSerr_in_tilde *x = (t_NLMSerr_in_tilde *)(w[4]);
+ t_int n = (t_int)(w[5]);
+ t_float *filt_out = (t_float *)(w[3]);
t_int i;
-
- out = io[2];
for(i=0; i<n; i++)
{
- *out++ = 0.0f;
+ *filt_out++ = 0.0f;
}
- return (w+3);
+ return (w+6);
}
static t_int *NLMSerr_in_tilde_perform(t_int *w)
@@ -146,7 +137,7 @@ static t_int *NLMSerr_in_tilde_perform(t_int *w)
t_float *w_filt_coeff = x->x_w_array_mem_beg;
t_float my, my_err, sum, errin;
t_float beta = x->x_beta;
- t_float gamma = x->x_gamma;
+ t_float gammax = x->x_gamma;
t_int i, j, update_counter;
t_int update = x->x_update;
t_int ord8=n_order&0xfffffff8;
@@ -207,7 +198,7 @@ static t_int *NLMSerr_in_tilde_perform(t_int *w)
}
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
+ sum += gammax * gammax * (float)n_order; // convert gammax corresponding to filter order
my = beta / sum;// calculate mue
@@ -260,7 +251,7 @@ static void *NLMSerr_in_tilde_new(t_symbol *s, t_int argc, t_atom *argv)
t_int i, n_order=39;
t_symbol *w_name;
t_float beta=0.1f;
- t_float gamma=0.00001f;
+ t_float gammax=0.00001f;
if((argc >= 4) &&
IS_A_FLOAT(argv,0) && //IS_A_FLOAT/SYMBOL from iemlib.h
@@ -270,7 +261,7 @@ static void *NLMSerr_in_tilde_new(t_symbol *s, t_int argc, t_atom *argv)
{
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);
+ gammax = (t_float)atom_getfloatarg(2, argc, argv);
w_name = (t_symbol *)atom_getsymbolarg(3, argc, argv);
if(beta < 0.0f)
@@ -278,10 +269,10 @@ static void *NLMSerr_in_tilde_new(t_symbol *s, t_int argc, t_atom *argv)
if(beta > 2.0f)
beta = 2.0f;
- if(gamma < 0.0f)
- gamma = 0.0f;
- if(gamma > 1.0f)
- gamma = 1.0f;
+ if(gammax < 0.0f)
+ gammax = 0.0f;
+ if(gammax > 1.0f)
+ gammax = 1.0f;
if(n_order < 2)
n_order = 2;
@@ -295,7 +286,7 @@ static void *NLMSerr_in_tilde_new(t_symbol *s, t_int argc, t_atom *argv)
x->x_n_order = n_order;
x->x_update = 0;
x->x_beta = beta;
- x->x_gamma = gamma;
+ x->x_gamma = gammax;
// 2 times in and one time err_in memory allocation (history)
x->x_in_hist = (t_float *)getbytes(2*x->x_n_order*sizeof(t_float));