On 22/05/12 02:13, tim vets wrote:
I have lists of floats from measurements which vary in length
(they grow with the duration of the measurements)
What would be a good way to map those to a list of, say, 150 items?
In concreto:
-When variable list A has 15 elements and fixed list B is 150 long,
I can simply repeat each value of A 10 times to get a 150 elements list.
-When list A has 1500 elements, and B 150, I could take list A 10 elements
at a time,
and write the averages thereof to list B.
but how do I generalize this for _any_ length of list A?

look into resampling, eg libsamplerate[1]

when #A > #B you want to low pass filter to antialias when downsampling
when #A < #B you want to interpolate     to antialias when   upsampling

and how do I patch this up in pd? :)

very temperamental/buggy version attached, especially the filtering is a bit rubbish in this one - it just uses a couple of simple causal lop[2] instead of doing it properly

for upsampling, tabread4 does one kind of interpolation (but you might want to use a different interpolation function, refer to the list archives about tabread4c etc)

for downsampling, you might want an acausal filter (like an image blur that works in all directions without shifting the image sideways) - most audio filters are causal (one direction only - the direction in this case is time, and the future can't influence the past, so there's some delay)

you might want to store statistics too, depending on the type of data (eg: in an audio scope like audacity you can see long-scale peaks/troughs even though the average antialiased visible signal would be a line at 0 assuming no DC offset) - you might pick up some ideas from the description of zoom-cache[3]

[1] http://www.mega-nerd.com/SRC/
[2] http://en.wikipedia.org/wiki/Low_pass_filter#Discrete-time_realization
[3] http://hackage.haskell.org/package/zoom-cache


Claude
#N canvas 0 0 485 714 10;
#X text 15 12 list_resample.pd by Claude Heiland-Allen 2012-05-22T02:48:37+0100
;
#X obj 15 61 inlet;
#X obj 76 109 list length;
#X obj 76 130 t a a;
#X msg 125 130 resize \$1;
#X obj 15 82 t a a;
#X obj 15 150 t b a;
#X obj 65 189 list prepend 0;
#X obj 64 209 s \$0-input;
#X obj 125 151 s \$0-input;
#X obj 56 62 table \$0-input;
#X obj 238 62 inlet;
#X obj 308 359 f;
#X obj 360 360 + 1;
#X msg 341 283 0;
#X obj 42 335 f;
#X obj 76 336 + 1;
#X obj 41 369 moses;
#X obj 41 308 t b b;
#X obj 121 337 f;
#X obj 156 338 +;
#X obj 213 251 /;
#X obj 41 437 f;
#X obj 308 380 tabread \$0-input;
#X obj 306 440 +;
#X obj 345 439 * 0.5;
#X obj 307 403 * 0.5;
#X obj 350 402 tabread \$0-input;
#X obj 19 240 t b b b;
#X obj 38 262 f;
#X obj 38 283 until;
#X msg 36 520 add2 \$1;
#X obj 16 575 outlet;
#X obj 104 366 b;
#X msg 106 517 set;
#X obj 236 164 max 1;
#X text 307 340 step through input;
#X obj 268 359 until;
#X obj 269 336 max 1;
#X text 66 265 step through output;
#X text 91 381 done;
#X obj 44 392 b;
#X text 46 421 current interpolated value;
#X text 315 421 interpolating lop filter;
#X text 339 265 rewind;
#X text 199 289 input/output rate;
#X obj 397 215 inlet;
#X msg 389 439 1 \$1;
#X obj 389 460 -;
#X obj 56 490 +;
#X obj 95 489 * 0.5;
#X obj 57 457 * 0.5;
#X msg 139 493 1 \$1;
#X obj 139 514 -;
#X text 68 473 reconstructing lop filter;
#X obj 323 216 inlet;
#X msg 18 547;
#X obj 156 359 moses 1;
#X obj 152 386 expr $f1 - floor($f1 \, 0) \; floor($f1 \, 0);
#X msg 134 310 1;
#X connect 1 0 5 0;
#X connect 2 0 3 0;
#X connect 3 0 21 0;
#X connect 3 1 4 0;
#X connect 4 0 9 0;
#X connect 5 0 6 0;
#X connect 5 1 2 0;
#X connect 6 0 28 0;
#X connect 6 1 7 0;
#X connect 7 0 8 0;
#X connect 11 0 35 0;
#X connect 12 0 13 0;
#X connect 12 0 23 0;
#X connect 13 0 12 1;
#X connect 14 0 12 1;
#X connect 14 0 15 1;
#X connect 14 0 27 0;
#X connect 15 0 16 0;
#X connect 15 0 17 0;
#X connect 16 0 15 1;
#X connect 17 0 41 0;
#X connect 17 1 33 0;
#X connect 18 0 15 0;
#X connect 18 1 19 0;
#X connect 19 0 20 0;
#X connect 20 0 57 0;
#X connect 21 0 20 1;
#X connect 22 0 51 0;
#X connect 23 0 26 0;
#X connect 24 0 25 0;
#X connect 24 0 22 1;
#X connect 25 0 24 1;
#X connect 26 0 24 0;
#X connect 27 0 25 0;
#X connect 27 0 50 0;
#X connect 27 0 22 1;
#X connect 28 0 56 0;
#X connect 28 1 29 0;
#X connect 28 2 14 0;
#X connect 28 2 34 0;
#X connect 28 2 59 0;
#X connect 29 0 30 0;
#X connect 30 0 18 0;
#X connect 31 0 56 0;
#X connect 33 0 30 1;
#X connect 34 0 56 0;
#X connect 35 0 17 1;
#X connect 35 0 29 1;
#X connect 35 0 21 1;
#X connect 37 0 12 0;
#X connect 38 0 37 0;
#X connect 41 0 22 0;
#X connect 46 0 26 1;
#X connect 46 0 47 0;
#X connect 47 0 48 0;
#X connect 48 0 25 1;
#X connect 49 0 50 0;
#X connect 49 0 31 0;
#X connect 50 0 49 1;
#X connect 51 0 49 0;
#X connect 52 0 53 0;
#X connect 53 0 50 1;
#X connect 55 0 52 0;
#X connect 55 0 51 1;
#X connect 56 0 32 0;
#X connect 57 0 19 1;
#X connect 57 1 58 0;
#X connect 58 0 19 1;
#X connect 58 1 38 0;
#X connect 59 0 19 1;
#N canvas 0 0 450 300 10;
#X text 14 12 list_resample-help.pd by Claude Heiland-Allen 
2012-05-22T03:30:37+0100
;
#X msg 170 100 16;
#X msg 135 100 8;
#X obj 59 182 print input;
#X obj 51 224 print output;
#X obj 49 159 t a a;
#X msg 49 82 1 2 3 4;
#X msg 34 62 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4;
#X msg 347 188 0.5;
#X msg 347 209 0.25;
#X msg 349 166 0.75;
#X msg 351 145 0.9;
#X msg 344 232 0.1;
#X text 149 83 output length;
#X text 60 45 input list;
#X msg 201 99 32;
#X obj 51 203 list_resample;
#X msg 264 173 0.5;
#X msg 264 194 0.25;
#X msg 266 151 0.75;
#X msg 268 130 0.9;
#X msg 261 217 0.1;
#X text 265 86 output sharpness;
#X text 349 100 input sharpness;
#X msg 269 108 0.99;
#X msg 351 125 0.99;
#X connect 1 0 16 1;
#X connect 2 0 16 1;
#X connect 5 0 16 0;
#X connect 5 1 3 0;
#X connect 6 0 5 0;
#X connect 7 0 5 0;
#X connect 8 0 16 3;
#X connect 9 0 16 3;
#X connect 10 0 16 3;
#X connect 11 0 16 3;
#X connect 12 0 16 3;
#X connect 15 0 16 1;
#X connect 16 0 4 0;
#X connect 17 0 16 2;
#X connect 18 0 16 2;
#X connect 19 0 16 2;
#X connect 20 0 16 2;
#X connect 21 0 16 2;
#X connect 24 0 16 2;
#X connect 25 0 16 3;
_______________________________________________
Pd-list@iem.at mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to