Search code examples
puredata

pure data [hist] implementation


No idea how to use [hist] in Pure Data. And the three arguments of [hist] is:

  • the value of first class,
  • the value of last class,
  • the number of classes.

I cannot figure out the first and second argument meaning? And how am I going to pass the output of [hist] to [tabwrite] and generate an array diagram in Pure Data.


Solution

  • It seems you are using the [hist] object from smlib.

    The histogram will contain <number of classes> bins of equal size, with the first bin being equivalent to the <value of first class> and the last bin being equivalent to <value of last class>-1 (the offset is arguably a bug).

    So, the value of first class is the minimum expected input value (x>=min), and the value of last class is the maximum expected input value (x<<max). Any input value exceeding those boundaries will be clipped.

    Examples:

    [3, absolute(
    |
    [hist 2 5 3]
    |
    [print]
    

    This will create a 3-bin histogram, with the bins 2±0.5 (with clipping this means x<2.5), 3±0.5 and 4±0.5 (with clipping that is 3.5<x). The input 3 will be filed into the second bin, so the absolute histogram is 0 1 0.

    Similarily:
    [3, absolute(
    |
    [hist 3 6 3]
    |
    [print]
    

    This will create a 3-bin histogram, with the bins 3±0.5, 4±0.5 and 5±0.5. The input 3 will be now filed into the first bin, so the absolute histogram is 1 0 0.

    Displaying the histogram:

    You can set the table-values by sending a list of number to the table, prefixed with the starting index:

    [relative(
    |
    [hist 0 100 100]
    |
    [list prepend 0]
    |
    [s $0-histo]
    
    [table $0-histo 100]
    

    Alternatively check the [array] object (which also can be accessed via [tabread] and the like)