aboutsummaryrefslogtreecommitdiff
path: root/adaptive/examples/02.persistent_excitation.pd
diff options
context:
space:
mode:
Diffstat (limited to 'adaptive/examples/02.persistent_excitation.pd')
-rwxr-xr-xadaptive/examples/02.persistent_excitation.pd396
1 files changed, 396 insertions, 0 deletions
diff --git a/adaptive/examples/02.persistent_excitation.pd b/adaptive/examples/02.persistent_excitation.pd
new file mode 100755
index 0000000..9bafbba
--- /dev/null
+++ b/adaptive/examples/02.persistent_excitation.pd
@@ -0,0 +1,396 @@
+#N struct num float x float y float col;
+#N canvas 21 113 829 606 10;
+#X obj 34 430 tgl 20 0 audio_io empty empty 0 -6 0 8 -262144 -1 -1
+1 1;
+#X text 59 432 <- Audio IO;
+#X text 122 266 x[n];
+#X text 251 316 d[n];
+#X text 104 379 y[n];
+#X obj 75 495 bng 20 250 50 0 clear empty empty 0 -6 0 8 -262144 -1
+-1;
+#X text 104 497 <- clear coefficients \, so adaptation will start again
+;
+#X text 542 496 unknown system:;
+#X text 571 520 d[n] =;
+#X floatatom 178 383 5 0 0 1 c0 - C0;
+#X floatatom 242 383 8 0 0 1 c1 - C1;
+#X text 31 471 adaptive filter:;
+#X floatatom 75 523 8 0 0 0 - mur mu;
+#X text 137 523 <- step size parameter mu (learning rate);
+#N canvas 215 124 617 210 init 0;
+#X msg 43 99 2;
+#X obj 269 45 loadbang;
+#X obj 43 122 s init_tlp;
+#X msg 138 98 0.33;
+#X msg 179 99 0.33;
+#X msg 223 100 0.33;
+#X obj 138 121 s a0r;
+#X obj 178 122 s a1r;
+#X obj 223 123 s a2r;
+#X obj 295 123 s mur;
+#X msg 515 103 \; pd dsp \$1;
+#X obj 515 78 r audio_io;
+#X obj 381 123 s signalr;
+#X msg 380 98 0;
+#X obj 182 180 s A1r;
+#X obj 142 179 s A0r;
+#X msg 183 157 2;
+#X msg 142 156 1;
+#X msg 294 99 0.001;
+#X connect 0 0 2 0;
+#X connect 1 0 0 0;
+#X connect 1 0 3 0;
+#X connect 1 0 4 0;
+#X connect 1 0 5 0;
+#X connect 1 0 18 0;
+#X connect 1 0 13 0;
+#X connect 1 0 17 0;
+#X connect 1 0 16 0;
+#X connect 3 0 6 0;
+#X connect 4 0 7 0;
+#X connect 5 0 8 0;
+#X connect 11 0 10 0;
+#X connect 13 0 12 0;
+#X connect 16 0 14 0;
+#X connect 17 0 15 0;
+#X connect 18 0 9 0;
+#X restore 644 578 pd init;
+#X floatatom 623 521 4 0 1.5 0 - A0r A0;
+#X text 657 521 x[n] +;
+#N canvas 425 56 483 381 PROBLEM_DESCRIPTION 0;
+#X text 35 188 unknown system:;
+#X text 35 259 adaptive system:;
+#X text 77 292 step-size parameter mu;
+#X text 74 209 FIR Filter: h=(1 \, 2) \, order = 2;
+#X text 75 225 d[n] = h0*x[n] + h1*x[n-1] (N=M);
+#X text 77 278 nlms2~ \, 2 coefficients (c0 \, c1);
+#X text 34 124 The unknown system is a FIR filter of order 2 and the
+adaptive system is an adaptive transversal filter using the NLMS algorithm
+(see nlms2~ help-patch) with 2 coefficients.;
+#X text 35 89 In this exmaple the adaptation path is beeing visualized
+in the c[n]-plane.;
+#X text 33 340 When can the unknown system be identified successfully
+?;
+#X text 32 42 PERSISTENT EXCITATION;
+#X restore 34 94 pd PROBLEM_DESCRIPTION;
+#N canvas 663 87 465 688 OBSERVATIONS 0;
+#X text 24 20 OBSERVATIONS;
+#X text 24 60 input signals 1 + 4:;
+#X text 48 77 The unknown system can be identified successfully.;
+#X text 24 103 input signals 2:;
+#X text 54 119 Adaptation doesn't work at all.;
+#X text 21 149 input signals 3:;
+#X text 51 165 Adaptation works \, but with an offset.;
+#X text 23 225 EXPLANATION;
+#X text 26 256 The unknown system can be identified \, if the Wiener-Hopf
+equation can be solved:;
+#X text 69 297 c_opt = R_x^-1 * p;
+#X text 257 294 (Wiener-Hopf equation);
+#X text 27 323 c_opt ... optimal coefficient vector c0 \, c1 \, c2
+\, ...;
+#X text 28 338 R_x ... autocorrelation matrix of the input signal x[n]
+;
+#X text 156 429 det(R_x) != 0;
+#X text 27 393 The Wiener-Hopf equation can only be solved \, if the
+determinant of R_x is not singular:;
+#X text 45 511 x[n] = sin(theta*n + phi);
+#X text 45 530 -> for N=2:;
+#X text 133 557 R_x =;
+#X text 275 547 cos(theta);
+#X text 236 566 cos(theta);
+#X text 221 567 [;
+#X text 220 547 [;
+#X text 355 547 ];
+#X text 355 566 ];
+#X text 175 558 0.5 *;
+#X text 239 548 1;
+#X text 331 567 1;
+#X text 40 622 -> det(R_x) = 0 \, if theta = 0 \, pi \, 2*pi \, ...
+;
+#X text 40 606 -> det(R_x) = 1 - cos^2(theta);
+#X text 24 639 (which is the case with input signal 2 = critical sampling)
+;
+#X text 26 483 In our example (signal 1+2):;
+#X text 28 352 p ... crosscorrelation vector between the desired output
+d[n] and the input signal x[n];
+#X restore 34 120 pd OBSERVATIONS;
+#X text 33 72 ReadMe:;
+#X obj 114 166 vradio 15 1 1 4 empty empty empty 0 -6 0 8 -262144 -1
+-1 2;
+#X floatatom 709 521 4 0 2 0 - A1r A1;
+#X text 743 521 x[n-1];
+#X text 132 197 3) x[n]=cos[pi*n]+2;
+#X text 132 212 4) white noise;
+#X text 132 164 1) x[n]=cos[0.5*pi*n] -> f=samplerate/4;
+#X text 132 181 2) x[n]=cos[pi*n] -> f=samplerate/2;
+#N canvas 0 0 450 300 c-plane 0;
+#X scalar num 100 200 600 \;;
+#X scalar num 132.83 181.096 841 \;;
+#X coords -100 300 200 -100 300 300 1;
+#X restore 486 131 pd c-plane;
+#N canvas 220 179 544 257 c-plane-stuff 0;
+#N canvas 118 400 523 253 num 0;
+#X text 104 54 float with x \, y values \; col for color \;;
+#X text 97 157 visualization of the float \, col is the color \;;
+#X obj 101 88 struct num float x float y float col;
+#X obj 90 184 filledpolygon col col 0 0 0 0 0 9 9 9 0 0 9;
+#X restore 27 36 pd num;
+#N canvas 663 380 461 298 init 0;
+#X msg 329 146 clear;
+#X obj 258 241 pointer;
+#X msg 223 91 bang;
+#X obj 137 22 loadbang;
+#X text 263 93 Initialization;
+#X obj 212 150 t b b b;
+#X msg 159 91 bang;
+#X obj 221 120 t b b;
+#X text 74 90 add another;
+#X obj 329 172 s pd-c-plane;
+#X msg 250 216 traverse pd-c-plane \, bang;
+#X obj 168 264 append num x y;
+#X obj 137 46 t b b b;
+#X obj 34 130 s \$0-initp;
+#X text 29 153 init pointers;
+#X msg 162 218 0;
+#X msg 201 220 0;
+#X connect 0 0 9 0;
+#X connect 1 0 11 2;
+#X connect 2 0 7 0;
+#X connect 3 0 12 0;
+#X connect 5 0 15 0;
+#X connect 5 1 16 0;
+#X connect 5 2 10 0;
+#X connect 6 0 5 0;
+#X connect 7 0 5 0;
+#X connect 7 1 0 0;
+#X connect 10 0 1 0;
+#X connect 12 0 13 0;
+#X connect 12 1 6 0;
+#X connect 12 2 2 0;
+#X connect 15 0 11 0;
+#X connect 16 0 11 1;
+#X restore 28 75 pd init;
+#X text 80 37 <- graphical representation of a number;
+#N canvas 944 527 415 326 coef_h 0;
+#X obj 219 222 pointer;
+#X msg 219 147 traverse pd-c-plane \, next;
+#X obj 175 24 r \$0-initp;
+#X obj 113 275 set num x y col;
+#X obj 100 186 * 100;
+#X obj 146 185 * 100;
+#X obj 100 159 r A0;
+#X obj 175 48 t b b b;
+#X obj 84 240 f 0;
+#X obj 130 239 f 0;
+#X msg 84 80 1;
+#X obj 84 124 t b b;
+#X obj 146 159 r A1;
+#X obj 84 101 metro 50;
+#X msg 197 249 600;
+#X connect 0 0 3 3;
+#X connect 1 0 0 0;
+#X connect 2 0 7 0;
+#X connect 4 0 8 1;
+#X connect 5 0 9 1;
+#X connect 6 0 4 0;
+#X connect 7 0 10 0;
+#X connect 7 1 14 0;
+#X connect 7 2 1 0;
+#X connect 8 0 3 0;
+#X connect 9 0 3 1;
+#X connect 10 0 13 0;
+#X connect 11 0 8 0;
+#X connect 11 1 9 0;
+#X connect 12 0 5 0;
+#X connect 13 0 11 0;
+#X connect 14 0 3 2;
+#X restore 26 137 pd coef_h;
+#N canvas 796 564 451 326 coef_c 0;
+#X obj 219 222 pointer;
+#X obj 175 24 r \$0-initp;
+#X obj 113 275 set num x y col;
+#X obj 100 186 * 100;
+#X obj 146 185 * 100;
+#X obj 84 240 f 0;
+#X obj 130 239 f 0;
+#X msg 84 80 1;
+#X obj 84 124 t b b;
+#X obj 100 159 r C0;
+#X obj 146 159 r C1;
+#X obj 175 48 t b b b;
+#X msg 219 147 traverse pd-c-plane \, next \, next;
+#X obj 84 101 metro 50;
+#X msg 197 249 841;
+#X connect 0 0 2 3;
+#X connect 1 0 11 0;
+#X connect 3 0 5 1;
+#X connect 4 0 6 1;
+#X connect 5 0 2 0;
+#X connect 6 0 2 1;
+#X connect 7 0 13 0;
+#X connect 8 0 5 0;
+#X connect 8 1 6 0;
+#X connect 9 0 3 0;
+#X connect 10 0 4 0;
+#X connect 11 0 7 0;
+#X connect 11 1 14 0;
+#X connect 11 2 12 0;
+#X connect 12 0 0 0;
+#X connect 13 0 8 0;
+#X connect 14 0 2 2;
+#X restore 27 107 pd coef_c;
+#X msg 165 126 \; . xticks 0 0.1 5;
+#X msg 165 164 \; . yticks 0 0.1 5;
+#X msg 303 128 \; . xlabel -1.15 -1 0 1 2;
+#X msg 302 163 \; . ylabel -1.1 -1 0 1 2 3;
+#X obj 165 80 loadbang;
+#X connect 9 0 5 0;
+#X connect 9 0 6 0;
+#X connect 9 0 7 0;
+#X connect 9 0 8 0;
+#X restore 698 578 pd c-plane-stuff;
+#N canvas 0 0 450 300 graph2 0;
+#X array . 1 float 3;
+#A 0 -0.97332;
+#X coords -1 3 2 -1 300 300 1;
+#X restore 486 131 graph;
+#X text 479 112 c1;
+#X text 790 423 c0;
+#X text 521 87 orange: adaptive system (c0 \, c1);
+#N canvas 771 151 438 319 input_signal~ 0;
+#X obj 175 34 inlet;
+#X obj 188 281 outlet~;
+#X msg 296 64 print else;
+#X obj 235 162 noise~;
+#X obj 262 188 *~;
+#X obj 190 183 +~ 2;
+#X obj 190 161 osc~;
+#X obj 35 39 samplerate~;
+#X obj 116 160 osc~;
+#X obj 35 17 loadbang;
+#X obj 115 194 *~;
+#X obj 35 157 osc~;
+#X obj 34 197 *~;
+#X obj 189 212 *~;
+#X obj 175 56 sel 0 1 2 3;
+#N canvas 264 424 366 206 distribute_msg 0;
+#X obj 66 26 inlet;
+#X obj 108 26 inlet;
+#X obj 154 26 inlet;
+#X obj 206 28 inlet;
+#X msg 114 91 0;
+#X msg 166 94 0;
+#X msg 215 93 0;
+#X msg 108 66 1;
+#X msg 154 66 1;
+#X msg 70 91 0;
+#X obj 54 124 outlet;
+#X obj 111 126 outlet;
+#X obj 165 124 outlet;
+#X obj 217 124 outlet;
+#X msg 206 65 0.3;
+#X msg 64 67 0.3;
+#X connect 0 0 15 0;
+#X connect 0 0 4 0;
+#X connect 0 0 5 0;
+#X connect 0 0 6 0;
+#X connect 1 0 7 0;
+#X connect 1 0 9 0;
+#X connect 1 0 5 0;
+#X connect 1 0 6 0;
+#X connect 2 0 8 0;
+#X connect 2 0 9 0;
+#X connect 2 0 4 0;
+#X connect 2 0 6 0;
+#X connect 3 0 14 0;
+#X connect 3 0 9 0;
+#X connect 3 0 4 0;
+#X connect 3 0 5 0;
+#X connect 4 0 11 0;
+#X connect 5 0 12 0;
+#X connect 6 0 13 0;
+#X connect 7 0 11 0;
+#X connect 8 0 12 0;
+#X connect 9 0 10 0;
+#X connect 14 0 13 0;
+#X connect 15 0 10 0;
+#X restore 175 86 pd distribute_msg;
+#X obj 35 133 / 4;
+#X obj 116 133 / 2;
+#X obj 190 133 / 2;
+#X connect 0 0 14 0;
+#X connect 3 0 4 0;
+#X connect 4 0 1 0;
+#X connect 5 0 13 0;
+#X connect 6 0 5 0;
+#X connect 7 0 16 0;
+#X connect 7 0 17 0;
+#X connect 7 0 18 0;
+#X connect 8 0 10 0;
+#X connect 9 0 7 0;
+#X connect 10 0 1 0;
+#X connect 11 0 12 0;
+#X connect 12 0 1 0;
+#X connect 13 0 1 0;
+#X connect 14 0 15 0;
+#X connect 14 1 15 1;
+#X connect 14 2 15 2;
+#X connect 14 3 15 3;
+#X connect 14 4 2 0;
+#X connect 15 0 12 1;
+#X connect 15 1 10 1;
+#X connect 15 2 13 1;
+#X connect 15 3 4 1;
+#X connect 16 0 11 0;
+#X connect 17 0 8 0;
+#X connect 18 0 6 0;
+#X restore 114 233 pd input_signal~;
+#N canvas 10 567 359 314 unknown_system~ 0;
+#X obj 26 26 inlet~;
+#X obj 26 268 outlet~;
+#X obj 26 113 fexpr~ $f2*$x1 + $f3*$x1[-1];
+#X obj 217 92 r A1r;
+#X obj 121 88 r A0r;
+#X connect 0 0 2 0;
+#X connect 2 0 1 0;
+#X connect 3 0 2 2;
+#X connect 4 0 2 1;
+#X restore 243 292 pd unknown_system~;
+#N canvas 523 194 390 347 adaptive_filter~ 0;
+#X obj 37 35 inlet~;
+#X text 22 15 input signal;
+#X obj 143 35 inlet~;
+#X text 122 15 desired signal;
+#X obj 38 275 outlet~;
+#X msg 249 63 adaptation 1;
+#X obj 249 42 loadbang;
+#X obj 249 141 r clear;
+#X msg 248 162 clear;
+#X obj 123 249 outlet;
+#X obj 188 249 outlet;
+#X obj 249 94 r mu;
+#X msg 249 116 mu \$1;
+#X obj 123 221 unpack f f;
+#X obj 37 156 nlms2~ 2 0.01;
+#X connect 0 0 14 0;
+#X connect 2 0 14 1;
+#X connect 5 0 14 0;
+#X connect 6 0 5 0;
+#X connect 7 0 8 0;
+#X connect 8 0 14 0;
+#X connect 11 0 12 0;
+#X connect 12 0 14 0;
+#X connect 13 0 9 0;
+#X connect 13 1 10 0;
+#X connect 14 0 4 0;
+#X connect 14 2 13 0;
+#X restore 114 360 pd adaptive_filter~;
+#X text 484 47 Visualization in the c-plane:;
+#X text 33 32 PERSISTENT EXCITATION;
+#X text 521 74 red: unknown system (h0 \, h1);
+#X connect 20 0 33 0;
+#X connect 33 0 35 0;
+#X connect 33 0 34 0;
+#X connect 34 0 35 1;
+#X connect 35 1 9 0;
+#X connect 35 2 10 0;