autoCrossCorrelationTableList CrossCorrelationTableList_and_Diagonalizer_diagonalize (CrossCorrelationTableList me, Diagonalizer thee) { try { autoCrossCorrelationTableList him = CrossCorrelationTableList_create (); for (long i = 1; i <= my size; i ++) { CrossCorrelationTable item = my at [i]; autoCrossCorrelationTable ct = CrossCorrelationTable_and_Diagonalizer_diagonalize (item, thee); his addItem_move (ct.move()); } return him; } catch (MelderError) { Melder_throw (U"CrossCorrelationTableList not diagonalized."); } }
/* * Generate n different cct's that have a common diagonalizer. */ autoCrossCorrelationTableList CrossCorrelationTableList_createTestSet (long dimension, long n, int firstPositiveDefinite, double sigma) { try { // Start with a square matrix with random gaussian elements and make its singular value decomposition UDV' // The V matrix will be the common diagonalizer matrix that we use. autoNUMmatrix<double> d (1, dimension, 1, dimension); for (long i = 1; i <= dimension; i ++) { // Generate the rotation matrix for (long j = 1; j <= dimension; j ++) { d [i] [j] = NUMrandomGauss (0.0, 1.0); } } autoNUMmatrix<double> v (1, dimension, 1, dimension); autoSVD svd = SVD_create_d (d.peek(), dimension, dimension); autoCrossCorrelationTableList me = CrossCorrelationTableList_create (); for (long i = 1; i <= dimension; i ++) { for (long j = 1; j <= dimension; j ++) { d [i] [j] = 0.0; } } // Start with a diagonal matrix D and calculate V'DV for (long k = 1; k <= n; k ++) { autoCrossCorrelationTable ct = CrossCorrelationTable_create (dimension); double low = ( k == 1 && firstPositiveDefinite ? 0.1 : -1.0 ); for (long i = 1; i <= dimension; i ++) { d [i] [i] = NUMrandomUniform (low, 1.0); } for (long i = 1; i <= dimension; i++) { for (long j = 1; j <= dimension; j ++) { v [i] [j] = NUMrandomGauss (svd -> v [i] [j], sigma); } } // we need V'DV, however our V has eigenvectors row-wise -> VDV' NUMdmatrices_multiply_VCVp (ct -> data, v.peek(), dimension, dimension, d.peek(), 1); my addItem_move (ct.move()); } return me; } catch (MelderError) { Melder_throw (U"CrossCorrelationTableList test set not created."); } }
autoCrossCorrelationTableList CrossCorrelationTables_to_CrossCorrelationTableList (OrderedOf<structCrossCorrelationTable> *me) { try { autoCrossCorrelationTableList thee = CrossCorrelationTableList_create (); long numberOfRows = 0, numberOfColumns = 0, numberOfSelected = 0; for (long i = 1; i <= my size; i++) { CrossCorrelationTable item = my at [i]; numberOfSelected++; if (numberOfSelected == 1) { numberOfRows = item -> numberOfRows; numberOfColumns = item -> numberOfColumns; } if (item -> numberOfRows != numberOfRows || item -> numberOfColumns != numberOfColumns) { Melder_throw (U"Dimensions of table ", i, U" differs from the rest."); } autoCrossCorrelationTable myc = Data_copy (item); thy addItem_move (myc.move()); } return thee; } catch (MelderError) { Melder_throw (U"No CrossCorrelationTableList created from CrossCorrelationTable(s)"); } }
autoCrossCorrelationTableList Sound_to_CrossCorrelationTableList (Sound me, double startTime, double endTime, double lagStep, long ncovars) { try { if (lagStep < my dx) { lagStep = my dx; } if (endTime <= startTime) { startTime = my xmin; endTime = my xmax; } if (startTime + ncovars * lagStep >= endTime) { Melder_throw (U"Lag time too large."); } autoCrossCorrelationTableList thee = CrossCorrelationTableList_create (); for (long i = 1; i <= ncovars; i ++) { double lag = (i - 1) * lagStep; autoCrossCorrelationTable ct = Sound_to_CrossCorrelationTable (me, startTime, endTime, lag); thy addItem_move (ct.move()); } return thee; } catch (MelderError) { Melder_throw (me, U": no CrossCorrelationTableList created."); } }
autoSound him = Sound_and_PCA_principalComponents (me, thee, GET_INTEGER (U"Number of components")); praat_new (him.move(), my name, U"_pc"); END FORM (Sound_and_PCA_whitenChannels, U"Sound & PCA: To Sound (white channels)", 0) NATURAL (U"Number of components", U"10") OK DO Sound me = FIRST (Sound); PCA thee = FIRST (PCA); autoSound him = Sound_and_PCA_whitenChannels (me, thee, GET_INTEGER (U"Number of components")); praat_new (him.move(), my name, U"_white"); END DIRECT (CrossCorrelationTable_to_CrossCorrelationTableList) autoCrossCorrelationTableList thee = CrossCorrelationTableList_create (); long nrows = 0, ncols = 0, nselected = 0; LOOP { iam (CrossCorrelationTable); nselected++; if (nselected == 1) { nrows = my numberOfRows; ncols = my numberOfColumns; } if (my numberOfRows != nrows || my numberOfColumns != ncols) { Melder_throw (U"Dimensions of table ", IOBJECT, U" differs from the rest."); } autoCrossCorrelationTable myc = Data_copy (me); thy addItem_move (myc.move()); } praat_new (thee.move(), U"ct_", nselected);