plugins/qm-dsp/dsp/segmentation/cluster_segmenter.c
/* return histograms h[nx*m] of data x[nx] into m bins using a sliding window of length h_len (MUST BE ODD) */
/* NB h is a vector in row major order, as required by cluster_melt() */
/* for historical reasons we normalise the histograms by their norm (not to sum to one) */
return histograms h[nx*m] of data x[nx] into m bins using a sliding window of length h_len (MUST BE ODD)
NB h is a vector in row major order, as required by cluster_melt()
for historical reasons we normalise the histograms by their norm (not to sum to one)
return histograms h [ nx * m ] of data x [ nx ] into m bins using a sliding window of length h_len ( MUST BE ODD ) NB h is a vector in row major order as required by cluster_melt () for historical reasons we normalise the histograms by their norm ( not to sum to one )
void create_histograms(int* x, int nx, int m, int hlen, double* h)
{
    int i, j, t;
    double norm;
    for (i = 0; i < nx*m; i++) {
        h[i] = 0;
    }
    for (i = hlen/2; i < nx-hlen/2; i++) {
        for (j = 0; j < m; j++) {
            h[i*m+j] = 0;
        }
        for (t = i-hlen/2; t <= i+hlen/2; t++) {
            ++h[i*m+x[t]];
        }
        norm = 0;
        for (j = 0; j < m; j++) {
            norm += h[i*m+j] * h[i*m+j];
        }
        for (j = 0; j < m; j++) {
            h[i*m+j] /= norm;
        }
    }
    for (i = 0; i < hlen/2; i++) {
        for (j = 0; j < m; j++) {
            h[i*m+j] = h[hlen/2*m+j];
        }
    }
    for (i = nx-hlen/2; i < nx; i++) {
        for (j = 0; j < m; j++) {
            h[i*m+j] = h[(nx-hlen/2-1)*m+j];
        }
    }
}
void create_histograms ( int * x , int nx , int m , int hlen , double * h ) { int i , j , t ; double norm ; for ( i = 0 ; i < nx * m ; i ++ ) { h [ i ] = 0 ; } for ( i = hlen / 2 ; i < nx - hlen / 2 ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { h [ i * m + j ] = 0 ; } for ( t = i - hlen / 2 ; t <= i + hlen / 2 ; t ++ ) { ++ h [ i * m + x [ t ] ] ; } norm = 0 ; for ( j = 0 ; j < m ; j ++ ) { norm += h [ i * m + j ] * h [ i * m + j ] ; } for ( j = 0 ; j < m ; j ++ ) { h [ i * m + j ] /= norm ; } } for ( i = 0 ; i < hlen / 2 ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { h [ i * m + j ] = h [ hlen / 2 * m + j ] ; } } for ( i = nx - hlen / 2 ; i < nx ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { h [ i * m + j ] = h [ ( nx - hlen / 2 - 1 ) * m + j ] ; } } }
return histograms h[nx*m] of data x[nx] into m bins using a sliding window of length h_len (MUST BE ODD)
NB h is a vector in row major order, as required by cluster_melt()
for historical reasons we normalise the histograms by their norm (not to sum to one)
return histograms h [ nx * m ] of data x [ nx ] into m bins using a sliding window of length h_len ( MUST BE ODD ) NB h is a vector in row major order as required by cluster_melt () for historical reasons we normalise the histograms by their norm ( not to sum to one )
/* duplicate histograms at beginning and end to create one histogram for each data value supplied */