speaker-calibration 2.2.247 → 2.2.249

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/.eslintignore +71 -71
  2. package/.eslintrc.json +40 -40
  3. package/.gitignore +81 -0
  4. package/.prettierignore +69 -69
  5. package/.prettierrc +14 -14
  6. package/LICENSE +20 -20
  7. package/README.md +133 -133
  8. package/__mocks__/fileMock.js +1 -1
  9. package/__mocks__/styleMock.js +1 -1
  10. package/babel.config.js +3 -3
  11. package/coverage/clover.xml +71 -71
  12. package/coverage/coverage-final.json +224 -224
  13. package/coverage/lcov-report/PythonServerInterface.js.html +265 -265
  14. package/coverage/lcov-report/base.css +354 -354
  15. package/coverage/lcov-report/block-navigation.js +82 -82
  16. package/coverage/lcov-report/index.html +123 -123
  17. package/coverage/lcov-report/prettify.css +101 -101
  18. package/coverage/lcov-report/prettify.js +937 -937
  19. package/coverage/lcov-report/sorter.js +189 -189
  20. package/coverage/lcov-report/src/index.html +121 -121
  21. package/coverage/lcov-report/src/server/PythonServerInterface.js.html +268 -268
  22. package/coverage/lcov-report/src/server/index.html +123 -123
  23. package/coverage/lcov-report/src/tasks/audioCalibrator.js.html +499 -499
  24. package/coverage/lcov-report/src/tasks/audioRecorder.js.html +412 -412
  25. package/coverage/lcov-report/src/tasks/index.html +143 -143
  26. package/coverage/lcov-report/src/tasks/volume/index.html +123 -123
  27. package/coverage/lcov-report/src/tasks/volume/volume.js.html +409 -409
  28. package/coverage/lcov-report/src/utils.js.html +172 -172
  29. package/coverage/lcov.info +91 -91
  30. package/dist/example/NoSleep.min.js +1 -1
  31. package/dist/example/fetch-languages-sheets.js +77 -77
  32. package/dist/example/i18n.js +29654 -30000
  33. package/dist/example/index.html +47 -47
  34. package/dist/example/listener.html +81 -81
  35. package/dist/example/server.js +51 -51
  36. package/dist/example/speaker.html +145 -145
  37. package/dist/example/speakerUI.js +273 -273
  38. package/dist/example/styles.css +152 -152
  39. package/dist/main.js +1 -1
  40. package/dist/mlsGen.js +6814 -6814
  41. package/dist/mlsGen.wasm +0 -0
  42. package/dist/package-lock.json +1018 -1018
  43. package/dist/package.json +18 -18
  44. package/doc/AudioCalibrator.html +417 -417
  45. package/doc/AudioPeer.html +251 -251
  46. package/doc/AudioRecorder.html +195 -195
  47. package/doc/ImpulseResponse.html +215 -215
  48. package/doc/Listener.html +308 -308
  49. package/doc/MlsGenInterface.html +226 -226
  50. package/doc/MyEventEmitter.html +274 -274
  51. package/doc/PythonServerAPI.html +109 -109
  52. package/doc/Speaker.html +276 -276
  53. package/doc/Takes%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +128 -128
  54. package/doc/Takes%20the%20url%20of%20the%20current%20site%0Aand%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +138 -138
  55. package/doc/Takes%20the%20url%20of%20the%20current%20site%20and%20a%20target%20element%20where%20html%20elements%20will%20be%20appended..html +137 -137
  56. package/doc/Volume.html +88 -88
  57. package/doc/audioCalibrator.js.html +179 -179
  58. package/doc/audioPeer.js.html +175 -175
  59. package/doc/audioRecorder.js.html +163 -163
  60. package/doc/creates%20a%20new%20AudioRecorder%20instance.%20%0ASets%20up%20the%20audio%20context%20and%20file%20reader..html +114 -114
  61. package/doc/fonts/OpenSans-Bold-webfont.svg +1829 -1829
  62. package/doc/fonts/OpenSans-BoldItalic-webfont.svg +1829 -1829
  63. package/doc/fonts/OpenSans-Italic-webfont.svg +1829 -1829
  64. package/doc/fonts/OpenSans-Light-webfont.svg +1830 -1830
  65. package/doc/fonts/OpenSans-LightItalic-webfont.svg +1834 -1834
  66. package/doc/fonts/OpenSans-Regular-webfont.svg +1830 -1830
  67. package/doc/global.html +308 -308
  68. package/doc/index.html +58 -58
  69. package/doc/listener.js.html +170 -170
  70. package/doc/mlsGen_mlsGenInterface.js.html +117 -117
  71. package/doc/myEventEmitter.js.html +124 -124
  72. package/doc/peer-connection_audioPeer.js.html +188 -188
  73. package/doc/peer-connection_listener.js.html +311 -311
  74. package/doc/peer-connection_speaker.js.html +381 -381
  75. package/doc/scripts/linenumber.js +25 -25
  76. package/doc/scripts/prettify/Apache-License-2.0.txt +202 -202
  77. package/doc/scripts/prettify/lang-css.js +24 -24
  78. package/doc/scripts/prettify/prettify.js +640 -640
  79. package/doc/server_PythonServerAPI.js.html +160 -160
  80. package/doc/speaker.js.html +248 -248
  81. package/doc/styles/jsdoc-default.css +371 -371
  82. package/doc/styles/prettify-jsdoc.css +111 -111
  83. package/doc/styles/prettify-tomorrow.css +163 -163
  84. package/doc/tasks_audioCalibrator.js.html +207 -207
  85. package/doc/tasks_audioRecorder.js.html +190 -190
  86. package/doc/tasks_impulse-response_impulseResponse.js.html +442 -442
  87. package/doc/tasks_impulse-response_mlsGen_mlsGenInterface.js.html +175 -175
  88. package/doc/tasks_volume_volume.js.html +185 -185
  89. package/doc/utils.js.html +105 -105
  90. package/jest.config.js +173 -173
  91. package/netlify.toml +26 -26
  92. package/package.json +78 -78
  93. package/src/config/firebase.js +26 -26
  94. package/src/index.html +21 -21
  95. package/src/listener-app/PhonePeer.js +474 -474
  96. package/src/listener-app/listener.js +377 -377
  97. package/src/main.js +22 -22
  98. package/src/myEventEmitter.js +83 -83
  99. package/src/peer-connection/audioPeer.js +100 -100
  100. package/src/peer-connection/listener.js +299 -299
  101. package/src/peer-connection/peerErrors.js +25 -25
  102. package/src/peer-connection/speaker.js +963 -963
  103. package/src/powerCheck.js +110 -110
  104. package/src/server/PythonServerAPI.js +959 -959
  105. package/src/tasks/combination/combination.js +44 -29
  106. package/src/tasks/combination/mlsGen/mlsGen.cpp +98 -98
  107. package/src/tasks/combination/mlsGen/mlsGen.hpp +303 -303
  108. package/src/tasks/combination/mlsGen/mlsGenInterface.js +131 -131
  109. package/src/tasks/combination/mlsGen/mlsGenTest.cpp +180 -180
  110. package/src/tasks/impulse-response/impulseResponse.js +610 -610
  111. package/src/tasks/impulse-response/mlsGen/mlsGen.cpp +98 -98
  112. package/src/tasks/impulse-response/mlsGen/mlsGen.hpp +303 -303
  113. package/src/tasks/impulse-response/mlsGen/mlsGenInterface.js +131 -131
  114. package/src/tasks/impulse-response/mlsGen/mlsGenTest.cpp +180 -180
  115. package/src/tasks/volume/volume.cpp +2 -2
  116. package/src/tasks/volume/volume.hpp +22 -22
  117. package/src/tasks/volume/volume.js +279 -279
  118. package/src/utils.js +205 -205
  119. package/webpack.config.js +65 -65
  120. package/.github/workflows/update-phrases.yml +0 -37
  121. package/makefile +0 -74
@@ -1,131 +1,131 @@
1
- /* eslint-disable prefer-destructuring */
2
- /* eslint-disable dot-notation */
3
- // eslint-disable-next-line import/extensions
4
- const createMLSGenModule = require('../../../../dist/mlsGen.js');
5
-
6
- /**
7
- * MLSGenInterface provides a class for interfacing with the MLSGen WASM module.
8
- */
9
- class MlsGenInterface {
10
- /** @private */
11
- #mlsOrder;
12
-
13
- /** @private */
14
- #WASMInstance; // the WASM module instance
15
-
16
- /** @private */
17
- #MLSGenInstance; // the MLSGen object instance
18
-
19
- /**
20
- * Creates an instance of MlsGenInterface.
21
- * Makes a call to the WASM glue code to load the WASM module.
22
- *
23
- * @param WASMInstance
24
- * @param mlsOrder
25
- * @param sourceSamplingRate
26
- * @param sinkSamplingRate
27
- * @example
28
- */
29
- constructor(WASMInstance, mlsOrder, sourceSamplingRate, sinkSamplingRate) {
30
- this.#mlsOrder = mlsOrder;
31
- this.#WASMInstance = WASMInstance;
32
-
33
- console.warn('initializing MLSGen, need to manually garbage collect');
34
- this.#MLSGenInstance = new this.#WASMInstance['MLSGen'](
35
- mlsOrder,
36
- sourceSamplingRate,
37
- sinkSamplingRate
38
- );
39
- }
40
-
41
- /**
42
- * Factory function that provide an asynchronous function that fetches the WASM module
43
- * and returns a promise that resolves when the module is loaded.
44
- *
45
- * @param mlsOrder
46
- * @param sourceSamplingRate - The sampling rate of the source audio.
47
- * @param sinkSamplingRate - The sampling rate of the sink audio.
48
- * @returns MlsGenInterface.
49
- * @example
50
- */
51
- static factory = async (mlsOrder, sourceSamplingRate, sinkSamplingRate) => {
52
- if (sourceSamplingRate === undefined || sinkSamplingRate === undefined) {
53
- throw new Error('sourceSamplingRate and sinkSamplingRate must be defined');
54
- }
55
- return new MlsGenInterface(
56
- await createMLSGenModule().then(instance => instance),
57
- mlsOrder,
58
- sourceSamplingRate,
59
- sinkSamplingRate
60
- );
61
- };
62
-
63
- /**
64
- * A Higher-Order function that takes an async callback function that access the MLSGen object,
65
- * providing safe garbage collection.
66
- *
67
- * @param func
68
- * @param args
69
- * @param funcsWithParams
70
- * @example
71
- */
72
- withGarbageCollection = async funcsWithParams => {
73
- try {
74
- for (let i = 0; i < funcsWithParams.length; i += 1) {
75
- const funcWithParams = funcsWithParams[i];
76
- // eslint-disable-next-line no-await-in-loop
77
- await funcWithParams();
78
- }
79
- } catch (error) {
80
- console.error(error);
81
- } finally {
82
- // garbage collect
83
- if (
84
- this !== undefined &&
85
- this !== null &&
86
- this.#MLSGenInstance !== undefined &&
87
- this.#MLSGenInstance !== null
88
- ) {
89
- this.#MLSGenInstance['Destruct'](); // Call the destructor
90
- this.#MLSGenInstance['delete'](); // Delete the object
91
- console.warn(`GARBAGE COLLECTION: deleted MLSGen`);
92
- this.#WASMInstance['doLeakCheck'](); // Check for memory leaks
93
- }
94
- }
95
- };
96
-
97
- /**
98
- * Calculate and return the Impulse Response of the recorded signal.
99
- *
100
- * @returns
101
- * @example
102
- */
103
- getImpulseResponse = () => this.#MLSGenInstance['getImpulseResponse']();
104
-
105
- /**
106
- * Given a recorded MLS signal, this function sets the recordedSignal property of the MLSGen object.
107
- *
108
- * @param signals
109
- * @example
110
- */
111
- setRecordedSignals = signals => {
112
- // get memory view
113
- const averagedSignals = this.average(signals);
114
- const recordedSignalsMemoryView = this.#MLSGenInstance['setRecordedSignalsMemoryView'](
115
- averagedSignals.byteLength
116
- );
117
- for (let i = 0; i < averagedSignals.length; i += 1) {
118
- recordedSignalsMemoryView[i] = averagedSignals[i];
119
- }
120
- };
121
-
122
- /**
123
- * Calculate the Maximum Length Sequence (MLS) with period P = 2^N - 1
124
- * using the MLSGen WASM module.
125
- *
126
- * @example
127
- */
128
- getMLS = () => this.#MLSGenInstance['getMLS']();
129
- }
130
-
131
- export default MlsGenInterface;
1
+ /* eslint-disable prefer-destructuring */
2
+ /* eslint-disable dot-notation */
3
+ // eslint-disable-next-line import/extensions
4
+ const createMLSGenModule = require('../../../../dist/mlsGen.js');
5
+
6
+ /**
7
+ * MLSGenInterface provides a class for interfacing with the MLSGen WASM module.
8
+ */
9
+ class MlsGenInterface {
10
+ /** @private */
11
+ #mlsOrder;
12
+
13
+ /** @private */
14
+ #WASMInstance; // the WASM module instance
15
+
16
+ /** @private */
17
+ #MLSGenInstance; // the MLSGen object instance
18
+
19
+ /**
20
+ * Creates an instance of MlsGenInterface.
21
+ * Makes a call to the WASM glue code to load the WASM module.
22
+ *
23
+ * @param WASMInstance
24
+ * @param mlsOrder
25
+ * @param sourceSamplingRate
26
+ * @param sinkSamplingRate
27
+ * @example
28
+ */
29
+ constructor(WASMInstance, mlsOrder, sourceSamplingRate, sinkSamplingRate) {
30
+ this.#mlsOrder = mlsOrder;
31
+ this.#WASMInstance = WASMInstance;
32
+
33
+ console.warn('initializing MLSGen, need to manually garbage collect');
34
+ this.#MLSGenInstance = new this.#WASMInstance['MLSGen'](
35
+ mlsOrder,
36
+ sourceSamplingRate,
37
+ sinkSamplingRate
38
+ );
39
+ }
40
+
41
+ /**
42
+ * Factory function that provide an asynchronous function that fetches the WASM module
43
+ * and returns a promise that resolves when the module is loaded.
44
+ *
45
+ * @param mlsOrder
46
+ * @param sourceSamplingRate - The sampling rate of the source audio.
47
+ * @param sinkSamplingRate - The sampling rate of the sink audio.
48
+ * @returns MlsGenInterface.
49
+ * @example
50
+ */
51
+ static factory = async (mlsOrder, sourceSamplingRate, sinkSamplingRate) => {
52
+ if (sourceSamplingRate === undefined || sinkSamplingRate === undefined) {
53
+ throw new Error('sourceSamplingRate and sinkSamplingRate must be defined');
54
+ }
55
+ return new MlsGenInterface(
56
+ await createMLSGenModule().then(instance => instance),
57
+ mlsOrder,
58
+ sourceSamplingRate,
59
+ sinkSamplingRate
60
+ );
61
+ };
62
+
63
+ /**
64
+ * A Higher-Order function that takes an async callback function that access the MLSGen object,
65
+ * providing safe garbage collection.
66
+ *
67
+ * @param func
68
+ * @param args
69
+ * @param funcsWithParams
70
+ * @example
71
+ */
72
+ withGarbageCollection = async funcsWithParams => {
73
+ try {
74
+ for (let i = 0; i < funcsWithParams.length; i += 1) {
75
+ const funcWithParams = funcsWithParams[i];
76
+ // eslint-disable-next-line no-await-in-loop
77
+ await funcWithParams();
78
+ }
79
+ } catch (error) {
80
+ console.error(error);
81
+ } finally {
82
+ // garbage collect
83
+ if (
84
+ this !== undefined &&
85
+ this !== null &&
86
+ this.#MLSGenInstance !== undefined &&
87
+ this.#MLSGenInstance !== null
88
+ ) {
89
+ this.#MLSGenInstance['Destruct'](); // Call the destructor
90
+ this.#MLSGenInstance['delete'](); // Delete the object
91
+ console.warn(`GARBAGE COLLECTION: deleted MLSGen`);
92
+ this.#WASMInstance['doLeakCheck'](); // Check for memory leaks
93
+ }
94
+ }
95
+ };
96
+
97
+ /**
98
+ * Calculate and return the Impulse Response of the recorded signal.
99
+ *
100
+ * @returns
101
+ * @example
102
+ */
103
+ getImpulseResponse = () => this.#MLSGenInstance['getImpulseResponse']();
104
+
105
+ /**
106
+ * Given a recorded MLS signal, this function sets the recordedSignal property of the MLSGen object.
107
+ *
108
+ * @param signals
109
+ * @example
110
+ */
111
+ setRecordedSignals = signals => {
112
+ // get memory view
113
+ const averagedSignals = this.average(signals);
114
+ const recordedSignalsMemoryView = this.#MLSGenInstance['setRecordedSignalsMemoryView'](
115
+ averagedSignals.byteLength
116
+ );
117
+ for (let i = 0; i < averagedSignals.length; i += 1) {
118
+ recordedSignalsMemoryView[i] = averagedSignals[i];
119
+ }
120
+ };
121
+
122
+ /**
123
+ * Calculate the Maximum Length Sequence (MLS) with period P = 2^N - 1
124
+ * using the MLSGen WASM module.
125
+ *
126
+ * @example
127
+ */
128
+ getMLS = () => this.#MLSGenInstance['getMLS']();
129
+ }
130
+
131
+ export default MlsGenInterface;
@@ -1,181 +1,181 @@
1
- #include "stdio.h"
2
-
3
- void GenerateSignal(bool *mls, double *signal, long P) {
4
- long i;
5
- double *input = new double[P];
6
- for (i = 0; i < P; i++) // Change 0 to 1 and 1 to -1
7
- {
8
- input[i] = -2 * mls[i] + 1;
9
- }
10
- for (i = 0; i < P; i++) // Simulate a system with h = {2, 0.4, 0.2, -0.1,
11
- // -0.8}, just an example
12
- {
13
- signal[i] = 2.0 * input[(P + i - 0) % P] + 0.4 * input[(P + i - 1) % P] +
14
- 0.2 * input[(P + i - 2) % P] - 0.1 * input[(P + i - 3) % P] -
15
- 0.8 * input[(P + i - 4) % P];
16
- }
17
- delete[] input;
18
- }
19
-
20
- void GenerateMls(bool *mls, long P, long N) {
21
- const long maxNoTaps = 18;
22
- const bool tapsTab[16][18] = {
23
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
24
- 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
25
- 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
26
- 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27
- 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1,
28
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
29
- 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
30
- 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,
31
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32
- 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
33
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
34
- 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
35
- bool taps[maxNoTaps];
36
- long i, j;
37
- bool *delayLine = new bool[maxNoTaps];
38
- long sum;
39
- for (i = 0; i < N; i++) // copy the N'th taps table
40
- {
41
- taps[i] = tapsTab[maxNoTaps - N][i];
42
- delayLine[i] = 1;
43
- }
44
- for (i = 0; i < P; i++) // Generate an MLS by summing the taps mod 2
45
- {
46
- sum = 0;
47
- for (j = 0; j < N; j++) {
48
- sum += taps[j] * delayLine[j];
49
- }
50
- sum &= 1; // mod 2
51
- mls[i] = delayLine[N - 1];
52
- for (j = N - 2; j >= 0; j--) {
53
- delayLine[j + 1] = delayLine[j];
54
- }
55
- delayLine[0] = *(bool *)&sum;
56
- }
57
- delete[] delayLine;
58
- }
59
-
60
- void FastHadamard(double *x, long P1, long N) {
61
- long i, i1, j, k, k1, k2;
62
- double temp;
63
- k1 = P1;
64
- for (k = 0; k < N; k++) {
65
- k2 = k1 >> 1;
66
- for (j = 0; j < k2; j++) {
67
- for (i = j; i < P1; i = i + k1) {
68
- i1 = i + k2;
69
- temp = x[i] + x[i1];
70
- x[i1] = x[i] - x[i1];
71
- x[i] = temp;
72
- }
73
- }
74
- k1 = k1 >> 1;
75
- }
76
- }
77
-
78
- void PermuteSignal(double *sig, double *perm, long *tagS, long P) {
79
- long i;
80
- double dc = 0;
81
- for (i = 0; i < P; i++) dc += sig[i];
82
- perm[0] = -dc;
83
- for (i = 0; i < P; i++) { // Just a permutation of the measured signal
84
- perm[tagS[i]] = sig[i];
85
- }
86
- }
87
- void PermuteResponse(double *perm, double *resp, long *tagL, long P) {
88
- long i;
89
- const double fact = 1 / double(P + 1);
90
- for (i = 0; i < P; i++) // Just a permutation of the impulse response
91
- {
92
- resp[i] = perm[tagL[i]] * fact;
93
- }
94
- resp[P] = 0;
95
- }
96
-
97
- void GeneratetagL(bool *mls, long *tagL, long P, long N) {
98
- long i, j;
99
- long *colSum = new long[P];
100
- long *index = new long[N];
101
- for (i = 0; i < P; i++) // Run through all the columns in the autocorr matrix
102
- {
103
- colSum[i] = 0;
104
- for (j = 0; j < N; j++) // Find colSum as the value of the first N elements
105
- // regarded as a binary number
106
- {
107
- colSum[i] += mls[(P + i - j) % P] << (N - 1 - j);
108
- }
109
- for (j = 0; j < N; j++) // Figure out if colSum is a 2^j number and store
110
- // the column as the j'th index
111
- {
112
- if (colSum[i] == (1 << j)) index[j] = i;
113
- }
114
- }
115
- for (i = 0; i < P; i++) // For each row in the L matrix
116
- {
117
- tagL[i] = 0;
118
- for (j = 0; j < N; j++) // Find the tagL as the value of the rows in the L
119
- // matrix regarded as a binary number
120
- {
121
- tagL[i] += mls[(P + index[j] - i) % P] * (1 << j);
122
- }
123
- }
124
- delete[] colSum;
125
- delete[] index;
126
- }
127
-
128
- void GeneratetagS(bool *mls, long *tagS, long P, long N) {
129
- long i, j;
130
- for (i = 0; i < P; i++) // For each column in the S matrix
131
- {
132
- tagS[i] = 0;
133
- for (j = 0; j < N; j++) // Find the tagS as the value of the columns in the
134
- // S matrix regarded as a binary number
135
- {
136
- tagS[i] += mls[(P + i - j) % P] * (1 << (N - 1 - j));
137
- }
138
- }
139
- }
140
-
141
- int main() {
142
- const long N = 18;
143
- const long P = (1 << N) - 1;
144
- long i;
145
- bool *mls = new bool[P];
146
- long *tagL = new long[P];
147
- long *tagS = new long[P];
148
- double *signal = new double[P];
149
- double *perm = new double[P + 1];
150
- double *resp = new double[P + 1];
151
- GenerateMls(mls, P, N); // Generate the Maximum length sequence
152
- GeneratetagL(mls, tagL, P, N); // Generate tagL for the L matrix
153
- GeneratetagS(mls, tagS, P, N); // Generate tagS for the S matrix
154
- GenerateSignal(mls, signal,
155
- P); // Do a simulated measurement and get the signal
156
- PermuteSignal(signal, perm, tagS, P); // Permute the signal according to tagS
157
- FastHadamard(perm, P + 1, N); // Do a Hadamard transform in place
158
- PermuteResponse(perm, resp, tagL,
159
- P); // Permute the impulseresponse according to tagL
160
-
161
- printf("The mls is:\n");
162
- for (i = 0; i < 10; i++) printf("%d\n", mls[i]);
163
- printf("The tagL is:\n");
164
- for (i = 0; i < 10; i++) printf("%ld\n", tagL[i]);
165
- printf("The tagS is:\n");
166
- for (i = 0; i < 10; i++) printf("%ld\n", tagS[i]);
167
- printf("The signal is:\n");
168
- for (i = 0; i < 10; i++) printf("%f\n", signal[i]);
169
- printf("The permuted signal is:\n");
170
- for (i = 0; i < 10; i++) printf("%f\n", perm[i]);
171
- printf("Impulse response:\n");
172
- for (i = 0; i < 10; i++) printf("%10.5f\n", resp[i]);
173
- delete[] mls;
174
- delete[] tagL;
175
- delete[] tagS;
176
- delete[] signal;
177
- delete[] perm;
178
- delete[] resp;
179
-
180
- return 0;
1
+ #include "stdio.h"
2
+
3
+ void GenerateSignal(bool *mls, double *signal, long P) {
4
+ long i;
5
+ double *input = new double[P];
6
+ for (i = 0; i < P; i++) // Change 0 to 1 and 1 to -1
7
+ {
8
+ input[i] = -2 * mls[i] + 1;
9
+ }
10
+ for (i = 0; i < P; i++) // Simulate a system with h = {2, 0.4, 0.2, -0.1,
11
+ // -0.8}, just an example
12
+ {
13
+ signal[i] = 2.0 * input[(P + i - 0) % P] + 0.4 * input[(P + i - 1) % P] +
14
+ 0.2 * input[(P + i - 2) % P] - 0.1 * input[(P + i - 3) % P] -
15
+ 0.8 * input[(P + i - 4) % P];
16
+ }
17
+ delete[] input;
18
+ }
19
+
20
+ void GenerateMls(bool *mls, long P, long N) {
21
+ const long maxNoTaps = 18;
22
+ const bool tapsTab[16][18] = {
23
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
24
+ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,
25
+ 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,
26
+ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
27
+ 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1,
28
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0,
29
+ 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
30
+ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0,
31
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
32
+ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0,
33
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
34
+ 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
35
+ bool taps[maxNoTaps];
36
+ long i, j;
37
+ bool *delayLine = new bool[maxNoTaps];
38
+ long sum;
39
+ for (i = 0; i < N; i++) // copy the N'th taps table
40
+ {
41
+ taps[i] = tapsTab[maxNoTaps - N][i];
42
+ delayLine[i] = 1;
43
+ }
44
+ for (i = 0; i < P; i++) // Generate an MLS by summing the taps mod 2
45
+ {
46
+ sum = 0;
47
+ for (j = 0; j < N; j++) {
48
+ sum += taps[j] * delayLine[j];
49
+ }
50
+ sum &= 1; // mod 2
51
+ mls[i] = delayLine[N - 1];
52
+ for (j = N - 2; j >= 0; j--) {
53
+ delayLine[j + 1] = delayLine[j];
54
+ }
55
+ delayLine[0] = *(bool *)&sum;
56
+ }
57
+ delete[] delayLine;
58
+ }
59
+
60
+ void FastHadamard(double *x, long P1, long N) {
61
+ long i, i1, j, k, k1, k2;
62
+ double temp;
63
+ k1 = P1;
64
+ for (k = 0; k < N; k++) {
65
+ k2 = k1 >> 1;
66
+ for (j = 0; j < k2; j++) {
67
+ for (i = j; i < P1; i = i + k1) {
68
+ i1 = i + k2;
69
+ temp = x[i] + x[i1];
70
+ x[i1] = x[i] - x[i1];
71
+ x[i] = temp;
72
+ }
73
+ }
74
+ k1 = k1 >> 1;
75
+ }
76
+ }
77
+
78
+ void PermuteSignal(double *sig, double *perm, long *tagS, long P) {
79
+ long i;
80
+ double dc = 0;
81
+ for (i = 0; i < P; i++) dc += sig[i];
82
+ perm[0] = -dc;
83
+ for (i = 0; i < P; i++) { // Just a permutation of the measured signal
84
+ perm[tagS[i]] = sig[i];
85
+ }
86
+ }
87
+ void PermuteResponse(double *perm, double *resp, long *tagL, long P) {
88
+ long i;
89
+ const double fact = 1 / double(P + 1);
90
+ for (i = 0; i < P; i++) // Just a permutation of the impulse response
91
+ {
92
+ resp[i] = perm[tagL[i]] * fact;
93
+ }
94
+ resp[P] = 0;
95
+ }
96
+
97
+ void GeneratetagL(bool *mls, long *tagL, long P, long N) {
98
+ long i, j;
99
+ long *colSum = new long[P];
100
+ long *index = new long[N];
101
+ for (i = 0; i < P; i++) // Run through all the columns in the autocorr matrix
102
+ {
103
+ colSum[i] = 0;
104
+ for (j = 0; j < N; j++) // Find colSum as the value of the first N elements
105
+ // regarded as a binary number
106
+ {
107
+ colSum[i] += mls[(P + i - j) % P] << (N - 1 - j);
108
+ }
109
+ for (j = 0; j < N; j++) // Figure out if colSum is a 2^j number and store
110
+ // the column as the j'th index
111
+ {
112
+ if (colSum[i] == (1 << j)) index[j] = i;
113
+ }
114
+ }
115
+ for (i = 0; i < P; i++) // For each row in the L matrix
116
+ {
117
+ tagL[i] = 0;
118
+ for (j = 0; j < N; j++) // Find the tagL as the value of the rows in the L
119
+ // matrix regarded as a binary number
120
+ {
121
+ tagL[i] += mls[(P + index[j] - i) % P] * (1 << j);
122
+ }
123
+ }
124
+ delete[] colSum;
125
+ delete[] index;
126
+ }
127
+
128
+ void GeneratetagS(bool *mls, long *tagS, long P, long N) {
129
+ long i, j;
130
+ for (i = 0; i < P; i++) // For each column in the S matrix
131
+ {
132
+ tagS[i] = 0;
133
+ for (j = 0; j < N; j++) // Find the tagS as the value of the columns in the
134
+ // S matrix regarded as a binary number
135
+ {
136
+ tagS[i] += mls[(P + i - j) % P] * (1 << (N - 1 - j));
137
+ }
138
+ }
139
+ }
140
+
141
+ int main() {
142
+ const long N = 18;
143
+ const long P = (1 << N) - 1;
144
+ long i;
145
+ bool *mls = new bool[P];
146
+ long *tagL = new long[P];
147
+ long *tagS = new long[P];
148
+ double *signal = new double[P];
149
+ double *perm = new double[P + 1];
150
+ double *resp = new double[P + 1];
151
+ GenerateMls(mls, P, N); // Generate the Maximum length sequence
152
+ GeneratetagL(mls, tagL, P, N); // Generate tagL for the L matrix
153
+ GeneratetagS(mls, tagS, P, N); // Generate tagS for the S matrix
154
+ GenerateSignal(mls, signal,
155
+ P); // Do a simulated measurement and get the signal
156
+ PermuteSignal(signal, perm, tagS, P); // Permute the signal according to tagS
157
+ FastHadamard(perm, P + 1, N); // Do a Hadamard transform in place
158
+ PermuteResponse(perm, resp, tagL,
159
+ P); // Permute the impulseresponse according to tagL
160
+
161
+ printf("The mls is:\n");
162
+ for (i = 0; i < 10; i++) printf("%d\n", mls[i]);
163
+ printf("The tagL is:\n");
164
+ for (i = 0; i < 10; i++) printf("%ld\n", tagL[i]);
165
+ printf("The tagS is:\n");
166
+ for (i = 0; i < 10; i++) printf("%ld\n", tagS[i]);
167
+ printf("The signal is:\n");
168
+ for (i = 0; i < 10; i++) printf("%f\n", signal[i]);
169
+ printf("The permuted signal is:\n");
170
+ for (i = 0; i < 10; i++) printf("%f\n", perm[i]);
171
+ printf("Impulse response:\n");
172
+ for (i = 0; i < 10; i++) printf("%10.5f\n", resp[i]);
173
+ delete[] mls;
174
+ delete[] tagL;
175
+ delete[] tagS;
176
+ delete[] signal;
177
+ delete[] perm;
178
+ delete[] resp;
179
+
180
+ return 0;
181
181
  }