praat_BSS_init.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /* praat_BSS_init.cpp
  2. *
  3. * Copyright (C) 2010-2017 David Weenink, 2015,2018 Paul Boersma
  4. *
  5. * This code is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This code is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this work. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "praat.h"
  19. #include "praat_TimeFunction.h"
  20. #include "EEG_extensions.h"
  21. #include "ICA.h"
  22. #include "praat_TimeFunction.h"
  23. #include "Sound_and_MixingMatrix.h"
  24. #include "Sound_and_PCA.h"
  25. void praat_SSCP_as_TableOfReal_init (ClassInfo klas);
  26. void praat_TableOfReal_init3 (ClassInfo klas);
  27. /******************** EEG ********************************************/
  28. FORM (NEW_EEG_to_CrossCorrelationTable, U"EEG: To CrossCorrelationTable", U"EEG: To CrossCorrelationTable...") {
  29. praat_TimeFunction_RANGE (fromTime, toTime)
  30. REAL (lagTime, U"Lag time (s)", U"0.05")
  31. TEXTFIELD (channels, U"Channels:", U"1:64")
  32. LABEL (U"To supply rising or falling ranges, use e.g. 2:6 or 5:3.")
  33. OK
  34. DO
  35. CONVERT_EACH (EEG)
  36. autoCrossCorrelationTable result = EEG_to_CrossCorrelationTable (me, fromTime, toTime, lagTime, channels);
  37. CONVERT_EACH_END (my name.get(), U"_", Melder_iround (lagTime * 1000.0))
  38. }
  39. FORM (NEW_EEG_to_Covariance, U"EEG: To Covariance", U"EEG: To Covariance...") {
  40. praat_TimeFunction_RANGE (fromTime, toTime)
  41. TEXTFIELD (channels, U"Channels:", U"1:64")
  42. LABEL (U"To supply rising or falling ranges, use e.g. 2:6 or 5:3.")
  43. OK
  44. DO
  45. CONVERT_EACH (EEG)
  46. autoCovariance result = EEG_to_Covariance (me, fromTime, toTime, channels);
  47. CONVERT_EACH_END (my name.get())
  48. }
  49. FORM (NEW_EEG_to_CrossCorrelationTableList, U"EEG: To CrossCorrelationTableList", U"EEG: To CrossCorrelationTableList...") {
  50. praat_TimeFunction_RANGE (fromTime, toTime)
  51. NATURAL (numberOfCrossCorrelations, U"Number of cross-correlations", U"40")
  52. POSITIVE (lagStep, U"Lag step (s)", U"0.002")
  53. TEXTFIELD (channels, U"Channels:", U"1:64")
  54. LABEL (U"To supply rising or falling ranges, use e.g. 2:6 or 5:3.")
  55. OK
  56. DO
  57. CONVERT_EACH (EEG)
  58. autoCrossCorrelationTableList result = EEG_to_CrossCorrelationTableList (me, fromTime, toTime,
  59. numberOfCrossCorrelations, lagStep, channels);
  60. CONVERT_EACH_END (my name.get())
  61. }
  62. FORM (NEW_EEG_to_EEG_bss, U"EEG: To EEG (bss)", U"EEG: To EEG (bss)...") {
  63. praat_TimeFunction_RANGE (fromTime, toTime)
  64. NATURAL (numberOfCrossCorrelations, U"Number of cross-correlations", U"40")
  65. POSITIVE (lagStep, U"Lag step (s)", U"0.002")
  66. TEXTFIELD (channels, U"Channels:", U"1:64")
  67. LABEL (U"To supply rising or falling ranges, use e.g. 2:6 or 5:3.")
  68. LABEL (U"Pre-whitening parameters")
  69. OPTIONMENUx (whiteningMethod, U"Whitening method", 1, 0)
  70. OPTION (U"No whitening")
  71. OPTION (U"Covariance")
  72. OPTION (U"Correlation")
  73. LABEL (U"Iteration parameters")
  74. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  75. POSITIVE (tolerance, U"Tolerance", U"0.001")
  76. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  77. OPTION (U"qdiag")
  78. OPTION (U"ffdiag")
  79. OK
  80. DO
  81. LOOP {
  82. iam_LOOP (EEG);
  83. autoEEG resultingEEG;
  84. autoMixingMatrix resultingMixingMatrix;
  85. EEG_to_EEG_bss (me, fromTime, toTime, numberOfCrossCorrelations, lagStep, channels,
  86. whiteningMethod, diagonalizationMethod, maximumNumberOfIterations, tolerance,
  87. & resultingEEG, & resultingMixingMatrix);
  88. praat_new (resultingEEG.move(), my name.get(), U"_bss");
  89. praat_new (resultingMixingMatrix.move(), my name.get());
  90. }
  91. END
  92. }
  93. FORM (NEW_EEG_to_PCA, U"EEG: To PCA", U"EEG: To PCA...") {
  94. praat_TimeFunction_RANGE (fromTime, toTime)
  95. TEXTFIELD (channels, U"Channels:", U"1:64")
  96. LABEL (U"To supply rising or falling ranges, use e.g. 2:6 or 5:3.")
  97. OPTIONMENU (method, U"Method", 1)
  98. OPTION (U"Covariance")
  99. OPTION (U"Correlation")
  100. OK
  101. DO
  102. CONVERT_EACH (EEG)
  103. autoPCA result = EEG_to_PCA (me, fromTime, toTime, channels, (method == 2));
  104. CONVERT_EACH_END (my name.get())
  105. }
  106. FORM (NEW1_EEG_PCA_to_EEG_principalComponents, U"EEG & PCA: To EEG (principal components)", U"EEG & PCA: To EEG (principal components)...") {
  107. INTEGER (numberOfComponents, U"Number of components", U"0 (= all)")
  108. OK
  109. DO
  110. CONVERT_TWO (EEG, PCA)
  111. autoEEG result = EEG_PCA_to_EEG_principalComponents (me, you, numberOfComponents);
  112. CONVERT_TWO_END (my name.get(), U"_pc")
  113. }
  114. FORM (NEW1_EEG_PCA_to_EEG_whiten, U"EEG & PCA: To EEG (whiten)", U"EEG & PCA: To EEG (whiten)...") {
  115. INTEGER (numberOfComponents, U"Number of components", U"0 (= all)")
  116. OK
  117. DO
  118. CONVERT_TWO (EEG, PCA)
  119. autoEEG result = EEG_PCA_to_EEG_whiten (me, you, numberOfComponents);
  120. CONVERT_TWO_END (my name.get(), U"_white");
  121. }
  122. FORM (NEW_EEG_to_Sound_modulated, U"EEG: To Sound (modulated)", nullptr) {
  123. POSITIVE (baseFrequency, U"Base frequency (Hz)", U"100.0")
  124. POSITIVE (channelBandwidth, U"Channel bandwidth (Hz)", U"100.0")
  125. TEXTFIELD (channels, U"Channels:", U"1:64")
  126. LABEL (U"To supply rising or falling ranges, use e.g. 2:6 or 5:3.")
  127. OK
  128. DO
  129. CONVERT_EACH (EEG)
  130. autoSound result = EEG_to_Sound_modulated (me, baseFrequency, channelBandwidth, channels);
  131. CONVERT_EACH_END (my name.get())
  132. }
  133. FORM (NEW_EEG_to_Sound_frequencyShifted, U"EEG: To Sound (frequency shifted)", 0) {
  134. NATURAL (channel, U"Channel", U"1")
  135. POSITIVE (frequencyShift, U"Frequency shift (Hz)", U"100.0")
  136. POSITIVE (samplingFrequency, U"Sampling frequecy (Hz)", U"11025.0")
  137. REAL (maximumAmplitude, U"Maximum amplitude", U"0.99")
  138. OK
  139. DO
  140. CONVERT_EACH (EEG)
  141. autoSound result = EEG_to_Sound_frequencyShifted (me, channel, frequencyShift, samplingFrequency, maximumAmplitude);
  142. CONVERT_EACH_END (my name.get(), U"_ch", channel)
  143. }
  144. /********************** CrossCorrelationTable(s) ******************/
  145. FORM (NEW1_CrossCorrelationTableList_createTestSet, U"CrossCorrelationTableList: Create test set", U"CrossCorrelationTableList: Create test set...") {
  146. WORD (name, U"Name", U"5x5")
  147. NATURAL (matrixDimension, U"Matrix dimension", U"5")
  148. NATURAL (numberOfMatrices, U"Number of matrices", U"20")
  149. BOOLEAN (firstIsPositiveDefinite, U"First is positive definite", true)
  150. REAL (sigma, U"Sigma", U"0.02")
  151. OK
  152. DO
  153. CREATE_ONE
  154. autoCrossCorrelationTableList result = CrossCorrelationTableList_createTestSet (matrixDimension, numberOfMatrices, firstIsPositiveDefinite, sigma);
  155. CREATE_ONE_END (name)
  156. }
  157. FORM (NEW1_CrossCorrelationTable_createSimple, U"Create simple CrossCorrelationTable", nullptr) {
  158. WORD (name, U"Name", U"ct")
  159. SENTENCE (crosscorrelations_string, U"Cross correlations", U"1.0 0.0 1.0")
  160. SENTENCE (centroid_string, U"Centroid", U"0.0 0.0")
  161. NATURAL (numberOfSamples, U"Number of samples", U"100")
  162. OK
  163. DO
  164. CREATE_ONE
  165. autoCrossCorrelationTable result = CrossCorrelationTable_createSimple (crosscorrelations_string, centroid_string, numberOfSamples);
  166. CREATE_ONE_END (name)
  167. }
  168. DIRECT (HELP_MixingMatrix_help) {
  169. HELP (U"MixingMatrix");
  170. }
  171. FORM (NEW1_MixingMatrix_createSimple, U"Create simple MixingMatrix", U"Create simple MixingMatrix...") {
  172. WORD (name, U"Name", U"mm")
  173. NATURAL (numberOfInputs, U"Number of inputs", U"2")
  174. NATURAL (numberOfOutputs, U"Number of outputs", U"2")
  175. SENTENCE (mixingCoefficients_string, U"Mixing coefficients", U"1.0 0.0 0.0 1.0")
  176. OK
  177. DO
  178. CREATE_ONE
  179. autoMixingMatrix result = MixingMatrix_createSimple (numberOfOutputs, numberOfInputs, mixingCoefficients_string);
  180. CREATE_ONE_END (name)
  181. }
  182. DIRECT (HELP_CrossCorrelationTable_help) {
  183. HELP (U"CrossCorrelationTable");
  184. }
  185. FORM (NEW1_Sound_PCA_principalComponents, U"Sound & PCA: To Sound (principal components)", nullptr) {
  186. NATURAL (numberOfComponents, U"Number of components", U"10")
  187. OK
  188. DO
  189. CONVERT_TWO (Sound, PCA)
  190. autoSound result = Sound_PCA_principalComponents (me, you, numberOfComponents);
  191. CONVERT_TWO_END (my name.get(), U"_pc")
  192. }
  193. FORM (NEW1_Sound_PCA_whitenChannels, U"Sound & PCA: To Sound (white channels)", nullptr) {
  194. NATURAL (numberOfComponents, U"Number of components", U"10")
  195. OK
  196. DO
  197. CONVERT_TWO (Sound, PCA)
  198. autoSound result = Sound_PCA_whitenChannels (me, you, numberOfComponents);
  199. CONVERT_TWO_END (my name.get(), U"_white")
  200. }
  201. DIRECT (NEW1_CrossCorrelationTables_to_CrossCorrelationTableList) {
  202. CONVERT_LIST (CrossCorrelationTable)
  203. autoCrossCorrelationTableList result = CrossCorrelationTables_to_CrossCorrelationTableList (& list);
  204. CONVERT_LIST_END (U"ct_", result -> size)
  205. }
  206. FORM (NEW_Sound_to_Covariance_channels, U"Sound: To Covariance (channels)", U"Sound: To Covariance (channels)...") {
  207. praat_TimeFunction_RANGE (fromTime, toTime)
  208. OK
  209. DO
  210. CONVERT_EACH (Sound)
  211. autoCovariance result = Sound_to_Covariance_channels (me, fromTime, toTime);
  212. CONVERT_EACH_END (my name.get())
  213. }
  214. FORM (NEW_Sound_to_CrossCorrelationTable, U"Sound: To CrossCorrelationTable", U"Sound: To CrossCorrelationTable...") {
  215. praat_TimeFunction_RANGE (fromTime, toTime)
  216. REAL (lagStep, U"Lag step (s)", U"0.0")
  217. OK
  218. DO
  219. CONVERT_EACH (Sound)
  220. autoCrossCorrelationTable result = Sound_to_CrossCorrelationTable (me, fromTime, toTime, lagStep);
  221. CONVERT_EACH_END (my name.get())
  222. }
  223. FORM (NEW1_Sounds_to_CrossCorrelationTable_combined, U"Sound: To CrossCorrelationTable (combined)", nullptr) {
  224. praat_TimeFunction_RANGE (fromTime, toTime)
  225. REAL (lagStep, U"Lag step (s)", U"0.0")
  226. OK
  227. DO
  228. CONVERT_COUPLE (Sound)
  229. autoCrossCorrelationTable result = Sounds_to_CrossCorrelationTable_combined (me, you, fromTime, toTime, lagStep);
  230. CONVERT_COUPLE_END (my name.get(), U"_", your name.get(), U"_cc")
  231. }
  232. DIRECT (HELP_CrossCorrelationTableList_help) {
  233. HELP (U"CrossCorrelationTableList")
  234. }
  235. FORM (REAL_CrossCorrelationTableList_getDiagonalityMeasure, U"CrossCorrelationTableList: Get diagonality measure", U"CrossCorrelationTableList: Get diagonality measure...") {
  236. NATURAL (fromTable, U"First table", U"1")
  237. NATURAL (toTable, U"Last table", U"100")
  238. OK
  239. DO
  240. NUMBER_ONE (CrossCorrelationTableList)
  241. double result = CrossCorrelationTableList_getDiagonalityMeasure (me, 0, fromTable, toTable);
  242. NUMBER_ONE_END (U" (= average sum of squared off-diagonal elements)")
  243. }
  244. FORM (NEW_CrossCorrelationTableList_extractCrossCorrelationTable, U"CrossCorrelationTableList: Extract one CrossCorrelationTable", nullptr) {
  245. NATURAL (index, U"Index", U"1")
  246. OK
  247. DO
  248. CONVERT_EACH (CrossCorrelationTableList)
  249. if (index > my size) {
  250. Melder_throw (U"Index too large.");
  251. }
  252. autoCrossCorrelationTable result = Data_copy (my at [index]);
  253. CONVERT_EACH_END (my name.get(), U"_", index)
  254. }
  255. FORM (NEW_CrossCorrelationTableList_to_Diagonalizer, U"CrossCorrelationTableList: To Diagonalizer", nullptr) {
  256. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  257. POSITIVE (tolerance, U"Tolerance", U"0.001")
  258. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  259. OPTION (U"qdiag")
  260. OPTION (U"ffdiag")
  261. OK
  262. DO
  263. CONVERT_EACH (CrossCorrelationTableList)
  264. autoDiagonalizer result = CrossCorrelationTableList_to_Diagonalizer (me, maximumNumberOfIterations, tolerance, diagonalizationMethod);
  265. CONVERT_EACH_END (my name.get())
  266. }
  267. FORM (MODIFY_Diagonalizer_CrossCorrelationTableList_improveDiagonality, U"Diagonalizer & CrossCorrelationTableList: Improve diagonality", nullptr) {
  268. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  269. POSITIVE (tolerance, U"Tolerance", U"0.001")
  270. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  271. OPTION (U"qdiag")
  272. OPTION (U"ffdiag")
  273. OK
  274. DO
  275. MODIFY_FIRST_OF_TWO (Diagonalizer, CrossCorrelationTableList)
  276. Diagonalizer_CrossCorrelationTableList_improveDiagonality (me, you, maximumNumberOfIterations, tolerance, diagonalizationMethod);
  277. MODIFY_FIRST_OF_TWO_END
  278. }
  279. FORM (REAL_CrossCorrelationTableList_Diagonalizer_getDiagonalityMeasure, U"CrossCorrelationTableList & Diagonalizer: Get diagonality measure", nullptr) {
  280. NATURAL (fromTable, U"First table", U"1")
  281. NATURAL (toTable, U"Last table", U"100")
  282. OK
  283. DO
  284. NUMBER_TWO (CrossCorrelationTableList, Diagonalizer)
  285. double result = CrossCorrelationTableList_Diagonalizer_getDiagonalityMeasure (me, you, nullptr, fromTable, toTable);
  286. NUMBER_TWO_END (U" (= average sum of squared off-diagonal elements)")
  287. }
  288. DIRECT (NEW1_CrossCorrelationTable_Diagonalizer_diagonalize) {
  289. CONVERT_TWO (CrossCorrelationTable, Diagonalizer)
  290. autoCrossCorrelationTable result = CrossCorrelationTable_Diagonalizer_diagonalize (me, you);
  291. CONVERT_TWO_END (me -> name.get(), U"_", you -> name.get())
  292. }
  293. DIRECT (NEW1_CrossCorrelationTableList_Diagonalizer_diagonalize) {
  294. CONVERT_TWO (CrossCorrelationTableList, Diagonalizer)
  295. autoCrossCorrelationTableList result = CrossCorrelationTableList_Diagonalizer_diagonalize (me, you);
  296. CONVERT_TWO_END (me -> name.get(), U"_", you -> name.get());
  297. }
  298. FORM (MODIFY_CrossCorrelationTableList_MixingMatrix_improveUnmixing, U"", nullptr) {
  299. LABEL (U"Iteration parameters")
  300. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  301. POSITIVE (tolerance, U"Tolerance", U"0.001")
  302. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  303. OPTION (U"qdiag")
  304. OPTION (U"ffdiag")
  305. OK
  306. DO
  307. MODIFY_FIRST_OF_TWO (MixingMatrix, CrossCorrelationTableList)
  308. MixingMatrix_CrossCorrelationTableList_improveUnmixing (me, you, maximumNumberOfIterations, tolerance, diagonalizationMethod);
  309. MODIFY_FIRST_OF_TWO_END
  310. }
  311. DIRECT (HELP_Diagonalizer_help) {
  312. HELP (U"Diagonalizer");
  313. }
  314. DIRECT (NEW_Diagonalizer_to_MixingMatrix) {
  315. CONVERT_EACH (Diagonalizer)
  316. autoMixingMatrix result = Diagonalizer_to_MixingMatrix (me);
  317. CONVERT_EACH_END (my name.get())
  318. }
  319. FORM (MODIFY_MixingMatrix_multiplyInputChannel, U"MixingMatrix: Multiply input channel", U"MixingMatrix: Multiply input channel...") {
  320. NATURAL (inputChannel, U"Input channel number", U"1")
  321. REAL (value, U"Multiply by", U"1.0")
  322. OK
  323. DO
  324. MODIFY_EACH (MixingMatrix)
  325. MixingMatrix_multiplyInputChannel (me, inputChannel, value);
  326. MODIFY_EACH_END
  327. }
  328. DIRECT (MODIFY_MixingMatrix_setStandardChannelInterpretation) {
  329. MODIFY_EACH (MixingMatrix)
  330. MixingMatrix_setStandardChannelInterpretation (me);
  331. MODIFY_EACH_END
  332. }
  333. DIRECT (NEW1_MixingMatrix_to_Diagonalizer) {
  334. CONVERT_EACH (MixingMatrix)
  335. autoDiagonalizer result = MixingMatrix_to_Diagonalizer (me);
  336. CONVERT_EACH_END (my name.get())
  337. }
  338. FORM (NEW_Sound_to_MixingMatrix, U"Sound: To MixingMatrix", nullptr) {
  339. praat_TimeFunction_RANGE (fromTime, toTime)
  340. NATURAL (numberOfCrossCorrelations, U"Number of cross-correlations", U"40")
  341. POSITIVE (lagStep, U"Lag step (s)", U"0.002")
  342. LABEL (U"Iteration parameters")
  343. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  344. POSITIVE (tolerance, U"Tolerance", U"0.001")
  345. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  346. OPTION (U"qdiag")
  347. OPTION (U"ffdiag")
  348. OK
  349. DO
  350. CONVERT_EACH (Sound)
  351. autoMixingMatrix result = Sound_to_MixingMatrix (me,
  352. fromTime, toTime, numberOfCrossCorrelations, lagStep,
  353. maximumNumberOfIterations, tolerance, diagonalizationMethod);
  354. CONVERT_EACH_END (my name.get())
  355. }
  356. FORM (MODIFY_Sound_MixingMatrix_improveUnmixing, U"", nullptr) {
  357. praat_TimeFunction_RANGE (fromTime, toTime)
  358. NATURAL (numberOfCrossCorrelations, U"Number of cross-correlations", U"40")
  359. POSITIVE (lagStep, U"Lag step (s)", U"0.002")
  360. LABEL (U"Iteration parameters")
  361. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  362. POSITIVE (tolerance, U"Tolerance", U"0.001")
  363. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  364. OPTION (U"qdiag")
  365. OPTION (U"ffdiag")
  366. OK
  367. DO
  368. MODIFY_FIRST_OF_TWO (MixingMatrix, Sound)
  369. MixingMatrix_Sound_improveUnmixing (me, you,
  370. fromTime, toTime, numberOfCrossCorrelations, lagStep,
  371. maximumNumberOfIterations, tolerance, diagonalizationMethod);
  372. MODIFY_FIRST_OF_TWO_END
  373. }
  374. FORM (NEW_Sound_to_CrossCorrelationTableList, U"Sound: To CrossCorrelationTableList", nullptr) {
  375. praat_TimeFunction_RANGE (fromTime, toTime)
  376. NATURAL (numberOfCrossCorrelations, U"Number of cross-correlations", U"40")
  377. POSITIVE (lagStep, U"Lag step (s)", U"0.002")
  378. OK
  379. DO
  380. CONVERT_EACH (Sound)
  381. autoCrossCorrelationTableList result = Sound_to_CrossCorrelationTableList (me,
  382. fromTime, toTime, numberOfCrossCorrelations, lagStep);
  383. CONVERT_EACH_END (my name.get())
  384. }
  385. FORM (NEW_Sound_to_Sound_bss, U"Sound: To Sound (blind source separation)", U"Sound: To Sound (blind source separation)...") {
  386. praat_TimeFunction_RANGE (fromTime, toTime)
  387. NATURAL (numberOfCrossCorrelations, U"Number of cross-correlations", U"40")
  388. POSITIVE (lagStep, U"Lag step (s)", U"0.002")
  389. LABEL (U"Iteration parameters")
  390. NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"100")
  391. POSITIVE (tolerance, U"Tolerance", U"0.001")
  392. OPTIONMENU (diagonalizationMethod, U"Diagonalization method", 2)
  393. OPTION (U"qdiag")
  394. OPTION (U"ffdiag")
  395. OK
  396. DO
  397. CONVERT_EACH (Sound)
  398. autoSound result = Sound_to_Sound_BSS (me,
  399. fromTime, toTime, numberOfCrossCorrelations, lagStep,
  400. maximumNumberOfIterations, tolerance, diagonalizationMethod);
  401. CONVERT_EACH_END (my name.get(), U"_bss")
  402. }
  403. FORM (NEW_Sound_to_Sound_whiteChannels, U"Sound: To Sound (white channels)", U"Sound: To Sound (white channels)...") {
  404. POSITIVE (varianceFraction, U"Variance fraction to keep", U"0.99")
  405. OK
  406. DO
  407. if (varianceFraction > 1.0) varianceFraction = 1.0;
  408. integer permille = Melder_ifloor (varianceFraction * 1000.0);
  409. CONVERT_EACH (Sound)
  410. autoSound result = Sound_whitenChannels (me, varianceFraction);
  411. CONVERT_EACH_END (my name.get(), U"_", permille);
  412. }
  413. DIRECT (PLAY_Sound_MixingMatrix_play) {
  414. FIND_TWO (Sound, MixingMatrix);
  415. Sound_MixingMatrix_play (me, you, nullptr, nullptr);
  416. END
  417. }
  418. DIRECT (NEW1_Sound_MixingMatrix_mix) {
  419. CONVERT_TWO (Sound, MixingMatrix)
  420. autoSound result = Sound_MixingMatrix_mix (me, you);
  421. CONVERT_TWO_END (my name.get(), U"_", your name.get())
  422. }
  423. FORM (NEW1_Sound_MixingMatrix_mixPart, U"Sound & MixingMatrix: Mix part", U"MixingMatrix") {
  424. REAL (fromTime, U"left Time_range (s)", U"0.0")
  425. REAL (toTime, U"right Time_range (s)", U"0.0 (=all)")
  426. OK
  427. DO
  428. if (toTime < fromTime) {
  429. Melder_throw (U"The start time should be lower than the end time.");
  430. }
  431. CONVERT_TWO (Sound, MixingMatrix)
  432. autoSound result = Sound_MixingMatrix_mixPart (me, you, fromTime, toTime);
  433. CONVERT_TWO_END (my name.get(), U"_", your name.get())
  434. }
  435. DIRECT (NEW1_Sound_MixingMatrix_unmix) {
  436. CONVERT_TWO (Sound, MixingMatrix)
  437. autoSound result = Sound_MixingMatrix_unmix (me, you);
  438. CONVERT_TWO_END (my name.get(), U"_unmixed");
  439. }
  440. DIRECT (NEW_TableOfReal_to_MixingMatrix) {
  441. CONVERT_EACH (TableOfReal)
  442. autoMixingMatrix result = TableOfReal_to_MixingMatrix (me);
  443. CONVERT_EACH_END (my name.get())
  444. }
  445. void praat_BSS_init ();
  446. void praat_BSS_init () {
  447. Thing_recognizeClassesByName (classDiagonalizer, classMixingMatrix, classCrossCorrelationTable, classCrossCorrelationTableList, nullptr);
  448. Thing_recognizeClassByOtherName (classCrossCorrelationTableList, U"CrossCorrelationTables");
  449. praat_addMenuCommand (U"Objects", U"New", U"Create simple CrossCorrelationTable...", U"Create simple Covariance...", praat_HIDDEN + praat_DEPTH_1, NEW1_CrossCorrelationTable_createSimple);
  450. praat_addMenuCommand (U"Objects", U"New", U"Create test CrossCorrelationTableList...", U"Create simple CrossCorrelationTable...", praat_HIDDEN + praat_DEPTH_1, NEW1_CrossCorrelationTableList_createTestSet);
  451. praat_addMenuCommand (U"Objects", U"New", U"Create simple MixingMatrix...", U"Create test CrossCorrelationTableList...", praat_HIDDEN + praat_DEPTH_1, NEW1_MixingMatrix_createSimple);
  452. praat_addAction1 (classCrossCorrelationTable, 0, U"CrossCorrelationTable help", 0, 0, HELP_CrossCorrelationTable_help);
  453. praat_SSCP_as_TableOfReal_init (classCrossCorrelationTable);
  454. praat_addAction1 (classCrossCorrelationTable, 0, U"To CrossCorrelationTableList", nullptr, 0, NEW1_CrossCorrelationTables_to_CrossCorrelationTableList);
  455. praat_addAction1 (classCrossCorrelationTable, 0, U"To CrossCorrelationTables", U"*To CrossCorrelationTableList", praat_DEPRECATED_2015, NEW1_CrossCorrelationTables_to_CrossCorrelationTableList);
  456. praat_addAction1 (classCrossCorrelationTableList, 0, U"CrossCorrelationTableList help", 0, 0, HELP_CrossCorrelationTableList_help);
  457. praat_addAction1 (classCrossCorrelationTableList, 1, U"Extract CrossCorrelationTable...", 0, 0, NEW_CrossCorrelationTableList_extractCrossCorrelationTable);
  458. praat_addAction1 (classCrossCorrelationTableList, 1, U"Get diagonality measure...", 0, 0, REAL_CrossCorrelationTableList_getDiagonalityMeasure);
  459. praat_addAction1 (classCrossCorrelationTableList, 0, U"To Diagonalizer...", 0, 0, NEW_CrossCorrelationTableList_to_Diagonalizer);
  460. praat_addAction1 (classDiagonalizer, 0, U"Diagonalizer help", 0, 0, HELP_Diagonalizer_help);
  461. praat_TableOfReal_init3 (classDiagonalizer);
  462. praat_addAction1 (classDiagonalizer, 0, U"To MixingMatrix", 0, 0, NEW_Diagonalizer_to_MixingMatrix);
  463. praat_addAction1 (classEEG, 0, U"To Sound (mc modulated)...", U"To ERPTier...", praat_HIDDEN, NEW_EEG_to_Sound_modulated);
  464. praat_addAction1 (classEEG, 0, U"To Sound (frequency shifted)...", U"To ERPTier...", 0, NEW_EEG_to_Sound_frequencyShifted);
  465. praat_addAction1 (classEEG, 0, U"To PCA...", U"To ERPTier...", 0, NEW_EEG_to_PCA);
  466. praat_addAction1 (classEEG, 0, U"To CrossCorrelationTable...", U"To PCA...", praat_HIDDEN, NEW_EEG_to_CrossCorrelationTable);
  467. praat_addAction1 (classEEG, 0, U"To CrossCorrelationTables...", U"To PCA...", praat_HIDDEN, NEW_EEG_to_CrossCorrelationTableList);
  468. praat_addAction1 (classEEG, 0, U"To CrossCorrelationTableList...", U"To PCA...", praat_HIDDEN, NEW_EEG_to_CrossCorrelationTableList);
  469. praat_addAction1 (classEEG, 0, U"To Covariance...", U"To CrossCorrelationTable...", praat_HIDDEN, NEW_EEG_to_Covariance);
  470. praat_addAction1 (classEEG, 0, U"To EEG (bss)...", U"To CrossCorrelationTable...", praat_HIDDEN, NEW_EEG_to_EEG_bss);
  471. praat_addAction2 (classEEG, 1, classPCA, 1, U"To EEG (principal components)...", 0, 0, NEW1_EEG_PCA_to_EEG_principalComponents);
  472. praat_addAction2 (classEEG, 1, classPCA, 1, U"To EEG (whiten)...", 0, 0, NEW1_EEG_PCA_to_EEG_whiten);
  473. praat_addAction1 (classMixingMatrix, 0, U"MixingMatrix help", 0, 0, HELP_MixingMatrix_help);
  474. praat_TableOfReal_init3 (classMixingMatrix);
  475. praat_addAction1 (classMixingMatrix, 0, U"Multiply input channel...", U"Set value...", praat_DEPTH_1, MODIFY_MixingMatrix_multiplyInputChannel);
  476. praat_removeAction (classMixingMatrix, nullptr, nullptr, U"Sort by label...");
  477. praat_removeAction (classMixingMatrix, nullptr, nullptr, U"Sort by column...");
  478. praat_addAction1 (classMixingMatrix, 0, U"Set standard channel interpretation", U"Set column label (label)...", praat_DEPTH_1, MODIFY_MixingMatrix_setStandardChannelInterpretation);
  479. praat_addAction1 (classMixingMatrix, 0, U"To Diagonalizer", U"To Matrix", praat_DEPTH_1, NEW1_MixingMatrix_to_Diagonalizer);
  480. praat_addAction1 (classSound, 0, U"To MixingMatrix...", U"Resample...", praat_HIDDEN + praat_DEPTH_1, NEW_Sound_to_MixingMatrix);
  481. praat_addAction1 (classSound, 0, U"To CrossCorrelationTable...", U"Resample...", 1, NEW_Sound_to_CrossCorrelationTable);
  482. praat_addAction1 (classSound, 0, U"To Covariance (channels)...", U"Resample...", praat_HIDDEN + praat_DEPTH_1, NEW_Sound_to_Covariance_channels);
  483. praat_addAction1 (classSound, 0, U"To CrossCorrelationTables...", U"Resample...", praat_HIDDEN + praat_DEPTH_1, NEW_Sound_to_CrossCorrelationTableList);
  484. praat_addAction1 (classSound, 0, U"To CrossCorrelationTableList...", U"Resample...", praat_HIDDEN + praat_DEPTH_1, NEW_Sound_to_CrossCorrelationTableList);
  485. praat_addAction1 (classSound, 0, U"To Sound (bss)...", U"Resample...", 1, NEW_Sound_to_Sound_bss);
  486. praat_addAction1 (classSound, 0, U"To Sound (white channels)...", U"Resample...", 1, NEW_Sound_to_Sound_whiteChannels);
  487. praat_addAction1 (classSound, 2, U"To CrossCorrelationTable (combined)...", U"Cross-correlate...", 1, NEW1_Sounds_to_CrossCorrelationTable_combined);
  488. praat_addAction1 (classTableOfReal, 0, U"To MixingMatrix", U"To Configuration", praat_HIDDEN, NEW_TableOfReal_to_MixingMatrix);
  489. praat_addAction2 (classSound, 1, classMixingMatrix, 1, U"Play", 0, 0, PLAY_Sound_MixingMatrix_play);
  490. praat_addAction2 (classSound, 1, classMixingMatrix, 1, U"Mix", 0, 0, NEW1_Sound_MixingMatrix_mix);
  491. praat_addAction2 (classSound, 1, classMixingMatrix, 1, U"Mix part...", 0, 0, NEW1_Sound_MixingMatrix_mixPart);
  492. praat_addAction2 (classSound, 1, classMixingMatrix, 1, U"Unmix", 0, 0, NEW1_Sound_MixingMatrix_unmix);
  493. praat_addAction2 (classSound, 1, classMixingMatrix, 1, U"Improve unmixing...", 0, 0, MODIFY_Sound_MixingMatrix_improveUnmixing);
  494. praat_addAction2 (classSound, 1, classPCA, 1, U"To Sound (white channels)...", 0 , 0, NEW1_Sound_PCA_whitenChannels);
  495. praat_addAction2 (classSound, 1, classPCA, 1, U"To Sound (principal components)...", 0 , 0, NEW1_Sound_PCA_principalComponents);
  496. praat_addAction2 (classCrossCorrelationTable, 1, classDiagonalizer, 1, U"Diagonalize", 0 , 0, NEW1_CrossCorrelationTable_Diagonalizer_diagonalize);
  497. praat_addAction2 (classCrossCorrelationTableList, 1, classDiagonalizer, 1, U"Get diagonality measure...", 0 , 0, REAL_CrossCorrelationTableList_Diagonalizer_getDiagonalityMeasure);
  498. praat_addAction2 (classCrossCorrelationTableList, 1, classDiagonalizer, 1, U"Diagonalize", 0 , 0, NEW1_CrossCorrelationTableList_Diagonalizer_diagonalize);
  499. praat_addAction2 (classCrossCorrelationTableList, 1, classDiagonalizer, 1, U"Improve diagonality...", 0 , 0, MODIFY_Diagonalizer_CrossCorrelationTableList_improveDiagonality);
  500. praat_addAction2 (classCrossCorrelationTableList, 1, classMixingMatrix, 1, U"Improve unmixing...", 0 , 0, MODIFY_CrossCorrelationTableList_MixingMatrix_improveUnmixing);
  501. INCLUDE_MANPAGES (manual_BSS)
  502. }
  503. /* End of file praat_BSS_init.cpp */