[PD] mapping variable-length lists to a fixed length one

Claude Heiland-Allen claude at goto10.org
Tue May 22 07:42:14 CEST 2012


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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: list_resample.pd
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20120522/283e1a62/attachment.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: list_resample-help.pd
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20120522/283e1a62/attachment.asc>


More information about the Pd-list mailing list