dsp-collection 0.2.5 → 0.2.7
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.
- package/README.md +6 -2
- package/filter/FirFilterWin.d.ts +8 -0
- package/filter/FirFilterWin.d.ts.map +1 -0
- package/filter/FirFilterWin.js +55 -0
- package/filter/FirFilterWin.js.map +1 -0
- package/filter/SpecFilt.d.ts +11 -10
- package/filter/SpecFilt.d.ts.map +1 -0
- package/filter/SpecFilt.js +98 -98
- package/filter/SpecFilt.js.map +1 -1
- package/math/Complex.d.ts +43 -42
- package/math/Complex.d.ts.map +1 -0
- package/math/Complex.js +130 -129
- package/math/Complex.js.map +1 -1
- package/math/ComplexArray.d.ts +37 -36
- package/math/ComplexArray.d.ts.map +1 -0
- package/math/ComplexArray.js +170 -170
- package/math/ComplexArray.js.map +1 -1
- package/math/MathUtils.d.ts +10 -7
- package/math/MathUtils.d.ts.map +1 -0
- package/math/MathUtils.js +116 -81
- package/math/MathUtils.js.map +1 -1
- package/math/MutableComplex.d.ts +24 -22
- package/math/MutableComplex.d.ts.map +1 -0
- package/math/MutableComplex.js +68 -64
- package/math/MutableComplex.js.map +1 -1
- package/math/NumApprox.d.ts +4 -3
- package/math/NumApprox.d.ts.map +1 -0
- package/math/NumApprox.js +67 -67
- package/math/NumApprox.js.map +1 -1
- package/math/PolyReal.d.ts +14 -13
- package/math/PolyReal.d.ts.map +1 -0
- package/math/PolyReal.js +226 -226
- package/math/PolyReal.js.map +1 -1
- package/package.json +11 -3
- package/signal/AdaptiveStft.d.ts +13 -12
- package/signal/AdaptiveStft.d.ts.map +1 -0
- package/signal/AdaptiveStft.js +57 -57
- package/signal/AdaptiveStft.js.map +1 -1
- package/signal/Autocorrelation.d.ts +6 -5
- package/signal/Autocorrelation.d.ts.map +1 -0
- package/signal/Autocorrelation.js +53 -53
- package/signal/Autocorrelation.js.map +1 -1
- package/signal/Dft.d.ts +10 -9
- package/signal/Dft.d.ts.map +1 -0
- package/signal/Dft.js +87 -87
- package/signal/Dft.js.map +1 -1
- package/signal/EnvelopeDetection.d.ts +2 -1
- package/signal/EnvelopeDetection.d.ts.map +1 -0
- package/signal/EnvelopeDetection.js +9 -9
- package/signal/EnvelopeDetection.js.map +1 -1
- package/signal/Fft.d.ts +10 -9
- package/signal/Fft.d.ts.map +1 -0
- package/signal/Fft.js +275 -275
- package/signal/Fft.js.map +1 -1
- package/signal/Goertzel.d.ts +6 -5
- package/signal/Goertzel.d.ts.map +1 -0
- package/signal/Goertzel.js +48 -48
- package/signal/Goertzel.js.map +1 -1
- package/signal/InstFreq.d.ts +9 -8
- package/signal/InstFreq.d.ts.map +1 -0
- package/signal/InstFreq.js +26 -26
- package/signal/InstFreq.js.map +1 -1
- package/signal/PitchDetectionHarm.d.ts +27 -26
- package/signal/PitchDetectionHarm.d.ts.map +1 -0
- package/signal/PitchDetectionHarm.js +72 -68
- package/signal/PitchDetectionHarm.js.map +1 -1
- package/signal/Resampling.d.ts +8 -7
- package/signal/Resampling.d.ts.map +1 -0
- package/signal/Resampling.js +218 -218
- package/signal/Resampling.js.map +1 -1
- package/signal/WindowFunctions.d.ts +42 -40
- package/signal/WindowFunctions.d.ts.map +1 -0
- package/signal/WindowFunctions.js +194 -194
- package/signal/WindowFunctions.js.map +1 -1
- package/utils/ArrayUtils.d.ts +10 -9
- package/utils/ArrayUtils.d.ts.map +1 -0
- package/utils/ArrayUtils.js +68 -68
- package/utils/ArrayUtils.js.map +1 -1
- package/utils/DspUtils.d.ts +5 -2
- package/utils/DspUtils.d.ts.map +1 -0
- package/utils/DspUtils.js +12 -6
- package/utils/DspUtils.js.map +1 -1
- package/utils/MiscUtils.d.ts +7 -6
- package/utils/MiscUtils.d.ts.map +1 -0
- package/utils/MiscUtils.js +20 -20
- package/utils/MiscUtils.js.map +1 -1
package/signal/AdaptiveStft.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import Complex from "../math/Complex.js";
|
|
2
|
-
import * as Goertzel from "./Goertzel.js";
|
|
3
|
-
import * as WindowFunctions from "./WindowFunctions.js";
|
|
4
|
-
export function getSingle_relWindow(samples, roughFrequency, roughWindowCenterPosition, relWindowWidth, windowFunction) {
|
|
5
|
-
if (roughFrequency <= 0 || roughFrequency >= 0.5 || relWindowWidth < 1) {
|
|
6
|
-
return;
|
|
7
|
-
}
|
|
8
|
-
if (!Number.isInteger(relWindowWidth)) {
|
|
9
|
-
throw new Error("Parameter relWindowWidth is not an integer.");
|
|
10
|
-
}
|
|
11
|
-
const windowWidth = Math.round(relWindowWidth / roughFrequency);
|
|
12
|
-
const windowStartPosition = Math.round(roughWindowCenterPosition - windowWidth / 2);
|
|
13
|
-
if (windowStartPosition < 0 || windowStartPosition + windowWidth > samples.length) {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
const windowSamples = samples.subarray(windowStartPosition, windowStartPosition + windowWidth);
|
|
17
|
-
const windowedSamples = windowFunction ? WindowFunctions.applyWindow(windowSamples, windowFunction) : windowSamples;
|
|
18
|
-
const component0 = Goertzel.goertzelSingle(windowedSamples, relWindowWidth);
|
|
19
|
-
const componentNormalized = component0.mulReal(2 / windowWidth);
|
|
20
|
-
const componentPhaseAdjusted = (relWindowWidth % 2 == 1) ? componentNormalized.neg() : componentNormalized;
|
|
21
|
-
return {
|
|
22
|
-
component: componentPhaseAdjusted,
|
|
23
|
-
frequency: relWindowWidth / windowWidth,
|
|
24
|
-
windowStartPosition: windowStartPosition,
|
|
25
|
-
windowWidth: windowWidth
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export function getSingle_maxWindow(samples, roughFrequency, roughWindowCenterPosition, maxWindowWidth, windowFunction) {
|
|
29
|
-
const relWindowWidth = Math.floor(maxWindowWidth * roughFrequency);
|
|
30
|
-
return getSingle_relWindow(samples, roughFrequency, roughWindowCenterPosition, relWindowWidth, windowFunction);
|
|
31
|
-
}
|
|
32
|
-
export function getSingle(samples, roughFrequency, windowFunction) {
|
|
33
|
-
const r = getSingle_maxWindow(samples, roughFrequency, samples.length / 2, samples.length, windowFunction);
|
|
34
|
-
return r ? r.component : Complex.NaN;
|
|
35
|
-
}
|
|
36
|
-
export function getHarmonicAmplitudes(samples, windowCenterPosition, f0, harmonics, relWindowWidth = 7, windowFunction = WindowFunctions.flatTopWindowNorm) {
|
|
37
|
-
if (!isFinite(f0) || f0 <= 0 || harmonics <= 0) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (!Number.isInteger(relWindowWidth)) {
|
|
41
|
-
throw new Error("Parameter relWindowWidth is not an integer.");
|
|
42
|
-
}
|
|
43
|
-
const windowWidth = Math.round(relWindowWidth / f0);
|
|
44
|
-
const windowStartPosition = Math.round(windowCenterPosition - windowWidth / 2);
|
|
45
|
-
if (windowStartPosition < 0 || windowStartPosition + windowWidth > samples.length || windowWidth <= 0) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const windowSamples = samples.subarray(windowStartPosition, windowStartPosition + windowWidth);
|
|
49
|
-
const windowedSamples = WindowFunctions.applyWindow(windowSamples, windowFunction);
|
|
50
|
-
const amplitudes = new Float64Array(harmonics);
|
|
51
|
-
for (let harmonic = 1; harmonic <= harmonics; harmonic++) {
|
|
52
|
-
const c = Goertzel.goertzelSingle(windowedSamples, harmonic * relWindowWidth);
|
|
53
|
-
const amplitude = c.abs() * 2 / windowWidth;
|
|
54
|
-
amplitudes[harmonic - 1] = amplitude;
|
|
55
|
-
}
|
|
56
|
-
return amplitudes;
|
|
57
|
-
}
|
|
1
|
+
import Complex from "../math/Complex.js";
|
|
2
|
+
import * as Goertzel from "./Goertzel.js";
|
|
3
|
+
import * as WindowFunctions from "./WindowFunctions.js";
|
|
4
|
+
export function getSingle_relWindow(samples, roughFrequency, roughWindowCenterPosition, relWindowWidth, windowFunction) {
|
|
5
|
+
if (roughFrequency <= 0 || roughFrequency >= 0.5 || relWindowWidth < 1) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (!Number.isInteger(relWindowWidth)) {
|
|
9
|
+
throw new Error("Parameter relWindowWidth is not an integer.");
|
|
10
|
+
}
|
|
11
|
+
const windowWidth = Math.round(relWindowWidth / roughFrequency);
|
|
12
|
+
const windowStartPosition = Math.round(roughWindowCenterPosition - windowWidth / 2);
|
|
13
|
+
if (windowStartPosition < 0 || windowStartPosition + windowWidth > samples.length) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const windowSamples = samples.subarray(windowStartPosition, windowStartPosition + windowWidth);
|
|
17
|
+
const windowedSamples = windowFunction ? WindowFunctions.applyWindow(windowSamples, windowFunction) : windowSamples;
|
|
18
|
+
const component0 = Goertzel.goertzelSingle(windowedSamples, relWindowWidth);
|
|
19
|
+
const componentNormalized = component0.mulReal(2 / windowWidth);
|
|
20
|
+
const componentPhaseAdjusted = (relWindowWidth % 2 == 1) ? componentNormalized.neg() : componentNormalized;
|
|
21
|
+
return {
|
|
22
|
+
component: componentPhaseAdjusted,
|
|
23
|
+
frequency: relWindowWidth / windowWidth,
|
|
24
|
+
windowStartPosition: windowStartPosition,
|
|
25
|
+
windowWidth: windowWidth
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function getSingle_maxWindow(samples, roughFrequency, roughWindowCenterPosition, maxWindowWidth, windowFunction) {
|
|
29
|
+
const relWindowWidth = Math.floor(maxWindowWidth * roughFrequency);
|
|
30
|
+
return getSingle_relWindow(samples, roughFrequency, roughWindowCenterPosition, relWindowWidth, windowFunction);
|
|
31
|
+
}
|
|
32
|
+
export function getSingle(samples, roughFrequency, windowFunction) {
|
|
33
|
+
const r = getSingle_maxWindow(samples, roughFrequency, samples.length / 2, samples.length, windowFunction);
|
|
34
|
+
return r ? r.component : Complex.NaN;
|
|
35
|
+
}
|
|
36
|
+
export function getHarmonicAmplitudes(samples, windowCenterPosition, f0, harmonics, relWindowWidth = 7, windowFunction = WindowFunctions.flatTopWindowNorm) {
|
|
37
|
+
if (!isFinite(f0) || f0 <= 0 || harmonics <= 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (!Number.isInteger(relWindowWidth)) {
|
|
41
|
+
throw new Error("Parameter relWindowWidth is not an integer.");
|
|
42
|
+
}
|
|
43
|
+
const windowWidth = Math.round(relWindowWidth / f0);
|
|
44
|
+
const windowStartPosition = Math.round(windowCenterPosition - windowWidth / 2);
|
|
45
|
+
if (windowStartPosition < 0 || windowStartPosition + windowWidth > samples.length || windowWidth <= 0) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const windowSamples = samples.subarray(windowStartPosition, windowStartPosition + windowWidth);
|
|
49
|
+
const windowedSamples = WindowFunctions.applyWindow(windowSamples, windowFunction);
|
|
50
|
+
const amplitudes = new Float64Array(harmonics);
|
|
51
|
+
for (let harmonic = 1; harmonic <= harmonics; harmonic++) {
|
|
52
|
+
const c = Goertzel.goertzelSingle(windowedSamples, harmonic * relWindowWidth);
|
|
53
|
+
const amplitude = c.abs() * 2 / windowWidth;
|
|
54
|
+
amplitudes[harmonic - 1] = amplitude;
|
|
55
|
+
}
|
|
56
|
+
return amplitudes;
|
|
57
|
+
}
|
|
58
58
|
//# sourceMappingURL=AdaptiveStft.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AdaptiveStft.js","sourceRoot":"","sources":["../../src/signal/AdaptiveStft.ts"],"names":[],"mappings":"AASA,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AA+BxD,MAAM,UAAU,mBAAmB,CAAE,OAAoC,EAAE,cAAsB,EAAE,yBAAiC,EAC9H,cAAsB,EAAE,cAA0D;IACrF,IAAI,cAAc,IAAI,CAAC,IAAI,cAAc,IAAI,GAAG,IAAI,cAAc,GAAG,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"AdaptiveStft.js","sourceRoot":"","sources":["../../src/signal/Ada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AAC,CAAC;IACpE,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC;IACpD,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,oBAAoB,GAAG,WAAW,GAAG,CAAC,CAAC,CAAC;IAC/E,IAAI,mBAAmB,GAAG,CAAC,IAAI,mBAAmB,GAAG,WAAW,GAAG,OAAO,CAAC,MAAM,IAAI,WAAW,IAAI,CAAC,EAAE,CAAC;QACrG,OAAO;IAAC,CAAC;IACZ,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,WAAW,CAAC,CAAC;IAC/F,MAAM,eAAe,GAAG,eAAe,CAAC,WAAW,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;IACnF,MAAM,UAAU,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,CAAC;IAC/C,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,IAAI,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC;QACxD,MAAM,CAAC,GAAG,QAAQ,CAAC,cAAc,CAAC,eAAe,EAAE,QAAQ,GAAG,cAAc,CAAC,CAAC;QAC9E,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,WAAW,CAAC;QAC5C,UAAU,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,SAAS,CAAC;IAAC,CAAC;IAC1C,OAAO,UAAU,CAAC;AAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import * as WindowFunctions from "./WindowFunctions.
|
|
2
|
-
export declare function nonPeriodicAutocorrelationSingle(x: ArrayLike<number>, distance: number, compensate: boolean): number;
|
|
3
|
-
export declare function findNonPeriodicAutocorrelationMaximum(x: ArrayLike<number>, minDistance: number, maxDistance: number, fixedOverlapWidth: boolean): number;
|
|
4
|
-
export declare function nonPeriodicAutocorrelation(x: ArrayLike<number>, normalize: boolean): Float64Array;
|
|
5
|
-
export declare function windowedNonPeriodicAutocorrelation(x: ArrayLike<number>, windowFunction: WindowFunctions.WindowFunction, normalize: boolean): Float64Array;
|
|
1
|
+
import * as WindowFunctions from "./WindowFunctions.ts";
|
|
2
|
+
export declare function nonPeriodicAutocorrelationSingle(x: ArrayLike<number>, distance: number, compensate: boolean): number;
|
|
3
|
+
export declare function findNonPeriodicAutocorrelationMaximum(x: ArrayLike<number>, minDistance: number, maxDistance: number, fixedOverlapWidth: boolean): number;
|
|
4
|
+
export declare function nonPeriodicAutocorrelation(x: ArrayLike<number>, normalize: boolean): Float64Array;
|
|
5
|
+
export declare function windowedNonPeriodicAutocorrelation(x: ArrayLike<number>, windowFunction: WindowFunctions.WindowFunction, normalize: boolean): Float64Array;
|
|
6
|
+
//# sourceMappingURL=Autocorrelation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Autocorrelation.d.ts","sourceRoot":"","sources":["../../src/signal/Autocorrelation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AAqBxD,wBAAgB,gCAAgC,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAI,MAAM,CAKvG;AAgBhB,wBAAgB,qCAAqC,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,OAAO,GAAI,MAAM,CAUxI;AAgBnB,wBAAgB,0BAA0B,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,GAAI,YAAY,CAStF;AAoBd,wBAAgB,kCAAkC,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,cAAc,EAAE,eAAe,CAAC,cAAc,EAAE,SAAS,EAAE,OAAO,GAAI,YAAY,CAMpI"}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import * as WindowFunctions from "./WindowFunctions.js";
|
|
2
|
-
import * as ArrayUtils from "../utils/ArrayUtils.js";
|
|
3
|
-
function autocorrelationKernel(x, distance, n) {
|
|
4
|
-
let sum = 0;
|
|
5
|
-
for (let i = 0; i < n; i++) {
|
|
6
|
-
sum += x[i] * x[i + distance];
|
|
7
|
-
}
|
|
8
|
-
return sum;
|
|
9
|
-
}
|
|
10
|
-
export function nonPeriodicAutocorrelationSingle(x, distance, compensate) {
|
|
11
|
-
const n = x.length - distance;
|
|
12
|
-
let sum = autocorrelationKernel(x, distance, n);
|
|
13
|
-
if (compensate && n > 0) {
|
|
14
|
-
sum *= x.length / n;
|
|
15
|
-
}
|
|
16
|
-
return sum;
|
|
17
|
-
}
|
|
18
|
-
export function findNonPeriodicAutocorrelationMaximum(x, minDistance, maxDistance, fixedOverlapWidth) {
|
|
19
|
-
let maxVal = -Infinity;
|
|
20
|
-
let maxPos = minDistance;
|
|
21
|
-
for (let distance = minDistance; distance < maxDistance; distance++) {
|
|
22
|
-
const val = fixedOverlapWidth ?
|
|
23
|
-
autocorrelationKernel(x, distance, x.length - maxDistance) :
|
|
24
|
-
nonPeriodicAutocorrelationSingle(x, distance, true);
|
|
25
|
-
if (val > maxVal) {
|
|
26
|
-
maxVal = val;
|
|
27
|
-
maxPos = distance;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return maxPos;
|
|
31
|
-
}
|
|
32
|
-
export function nonPeriodicAutocorrelation(x, normalize) {
|
|
33
|
-
const n = x.length;
|
|
34
|
-
const r = new Float64Array(n);
|
|
35
|
-
for (let distance = 0; distance < n; distance++) {
|
|
36
|
-
r[distance] = nonPeriodicAutocorrelationSingle(x, distance, true);
|
|
37
|
-
}
|
|
38
|
-
if (normalize && n > 0 && r[0] != 0) {
|
|
39
|
-
const max = r[0];
|
|
40
|
-
for (let distance = 0; distance < n; distance++) {
|
|
41
|
-
r[distance] /= max;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return r;
|
|
45
|
-
}
|
|
46
|
-
export function windowedNonPeriodicAutocorrelation(x, windowFunction, normalize) {
|
|
47
|
-
const windowed = WindowFunctions.applyWindow(x, windowFunction);
|
|
48
|
-
const autoCorr = nonPeriodicAutocorrelation(windowed, normalize);
|
|
49
|
-
const window = WindowFunctions.getWindowTable(windowFunction, x.length);
|
|
50
|
-
const windowAutoCorr = nonPeriodicAutocorrelation(window, true);
|
|
51
|
-
const compensated = ArrayUtils.divide(autoCorr, windowAutoCorr);
|
|
52
|
-
return compensated;
|
|
53
|
-
}
|
|
1
|
+
import * as WindowFunctions from "./WindowFunctions.js";
|
|
2
|
+
import * as ArrayUtils from "../utils/ArrayUtils.js";
|
|
3
|
+
function autocorrelationKernel(x, distance, n) {
|
|
4
|
+
let sum = 0;
|
|
5
|
+
for (let i = 0; i < n; i++) {
|
|
6
|
+
sum += x[i] * x[i + distance];
|
|
7
|
+
}
|
|
8
|
+
return sum;
|
|
9
|
+
}
|
|
10
|
+
export function nonPeriodicAutocorrelationSingle(x, distance, compensate) {
|
|
11
|
+
const n = x.length - distance;
|
|
12
|
+
let sum = autocorrelationKernel(x, distance, n);
|
|
13
|
+
if (compensate && n > 0) {
|
|
14
|
+
sum *= x.length / n;
|
|
15
|
+
}
|
|
16
|
+
return sum;
|
|
17
|
+
}
|
|
18
|
+
export function findNonPeriodicAutocorrelationMaximum(x, minDistance, maxDistance, fixedOverlapWidth) {
|
|
19
|
+
let maxVal = -Infinity;
|
|
20
|
+
let maxPos = minDistance;
|
|
21
|
+
for (let distance = minDistance; distance < maxDistance; distance++) {
|
|
22
|
+
const val = fixedOverlapWidth ?
|
|
23
|
+
autocorrelationKernel(x, distance, x.length - maxDistance) :
|
|
24
|
+
nonPeriodicAutocorrelationSingle(x, distance, true);
|
|
25
|
+
if (val > maxVal) {
|
|
26
|
+
maxVal = val;
|
|
27
|
+
maxPos = distance;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return maxPos;
|
|
31
|
+
}
|
|
32
|
+
export function nonPeriodicAutocorrelation(x, normalize) {
|
|
33
|
+
const n = x.length;
|
|
34
|
+
const r = new Float64Array(n);
|
|
35
|
+
for (let distance = 0; distance < n; distance++) {
|
|
36
|
+
r[distance] = nonPeriodicAutocorrelationSingle(x, distance, true);
|
|
37
|
+
}
|
|
38
|
+
if (normalize && n > 0 && r[0] != 0) {
|
|
39
|
+
const max = r[0];
|
|
40
|
+
for (let distance = 0; distance < n; distance++) {
|
|
41
|
+
r[distance] /= max;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return r;
|
|
45
|
+
}
|
|
46
|
+
export function windowedNonPeriodicAutocorrelation(x, windowFunction, normalize) {
|
|
47
|
+
const windowed = WindowFunctions.applyWindow(x, windowFunction);
|
|
48
|
+
const autoCorr = nonPeriodicAutocorrelation(windowed, normalize);
|
|
49
|
+
const window = WindowFunctions.getWindowTable(windowFunction, x.length);
|
|
50
|
+
const windowAutoCorr = nonPeriodicAutocorrelation(window, true);
|
|
51
|
+
const compensated = ArrayUtils.divide(autoCorr, windowAutoCorr);
|
|
52
|
+
return compensated;
|
|
53
|
+
}
|
|
54
54
|
//# sourceMappingURL=Autocorrelation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocorrelation.js","sourceRoot":"","sources":["../../src/signal/Autocorrelation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAC;AACxD,OAAO,KAAK,UAAU,MAAM,wBAAwB,CAAC;AAErD,SAAS,qBAAqB,CAAE,CAAoB,EAAE,QAAgB,EAAE,CAAS;IAC9E,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"Autocorrelation.js","sourceRoot":"","sources":["../../src/signal/Autocorrel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xE,MAAM,cAAc,GAAG,0BAA0B,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAChE,OAAO,WAAW,CAAC;AAAC,CAAC"}
|
package/signal/Dft.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import MutableComplex from "../math/MutableComplex.
|
|
2
|
-
import ComplexArray from "../math/ComplexArray.
|
|
3
|
-
export declare function dftRealSingle(x: ArrayLike<number>, relativeFrequency: number): MutableComplex;
|
|
4
|
-
export declare function dftSingle(x: ComplexArray, relativeFrequency: number, direction: boolean): MutableComplex;
|
|
5
|
-
export declare function dftReal(x: ArrayLike<number>): ComplexArray;
|
|
6
|
-
export declare function dftRealHalf(x: ArrayLike<number>): ComplexArray;
|
|
7
|
-
export declare function dft(x: ComplexArray, direction: boolean): ComplexArray;
|
|
8
|
-
export declare function dftRealSpectrum(x: ArrayLike<number>, inclNyquist?: boolean): ComplexArray;
|
|
9
|
-
export declare function iDftRealSpectrum(x: ComplexArray, len: number): Float64Array;
|
|
1
|
+
import MutableComplex from "../math/MutableComplex.ts";
|
|
2
|
+
import ComplexArray from "../math/ComplexArray.ts";
|
|
3
|
+
export declare function dftRealSingle(x: ArrayLike<number>, relativeFrequency: number): MutableComplex;
|
|
4
|
+
export declare function dftSingle(x: ComplexArray, relativeFrequency: number, direction: boolean): MutableComplex;
|
|
5
|
+
export declare function dftReal(x: ArrayLike<number>): ComplexArray;
|
|
6
|
+
export declare function dftRealHalf(x: ArrayLike<number>): ComplexArray;
|
|
7
|
+
export declare function dft(x: ComplexArray, direction: boolean): ComplexArray;
|
|
8
|
+
export declare function dftRealSpectrum(x: ArrayLike<number>, inclNyquist?: boolean): ComplexArray;
|
|
9
|
+
export declare function iDftRealSpectrum(x: ComplexArray, len: number): Float64Array;
|
|
10
|
+
//# sourceMappingURL=Dft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Dft.d.ts","sourceRoot":"","sources":["../../src/signal/Dft.ts"],"names":[],"mappings":"AAWA,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,YAAY,MAAM,yBAAyB,CAAC;AAoBnD,wBAAgB,aAAa,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,iBAAiB,EAAE,MAAM,GAAI,cAAc,CAShF;AAiBhB,wBAAgB,SAAS,CAAE,CAAC,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,GAAI,cAAc,CAU3F;AAWhB,wBAAgB,OAAO,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAI,YAAY,CAM/C;AAUd,wBAAgB,WAAW,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAI,YAAY,CAMnD;AAYd,wBAAgB,GAAG,CAAE,CAAC,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,GAAI,YAAY,CAM1D;AAkBd,wBAAgB,eAAe,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,UAAQ,GAAI,YAAY,CAW5E;AAiBd,wBAAgB,gBAAgB,CAAE,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAI,YAAY,CAKhE"}
|
package/signal/Dft.js
CHANGED
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import Complex from "../math/Complex.js";
|
|
2
|
-
import MutableComplex from "../math/MutableComplex.js";
|
|
3
|
-
import ComplexArray from "../math/ComplexArray.js";
|
|
4
|
-
export function dftRealSingle(x, relativeFrequency) {
|
|
5
|
-
const n = x.length;
|
|
6
|
-
if (n == 0) {
|
|
7
|
-
throw new Error("Input array must not be empty.");
|
|
8
|
-
}
|
|
9
|
-
const w = -2 * Math.PI / n * relativeFrequency;
|
|
10
|
-
const acc = new MutableComplex(0, 0);
|
|
11
|
-
for (let p = 0; p < n; p++) {
|
|
12
|
-
const c = Complex.fromPolar(x[p], w * p);
|
|
13
|
-
acc.addTo(c);
|
|
14
|
-
}
|
|
15
|
-
return acc;
|
|
16
|
-
}
|
|
17
|
-
export function dftSingle(x, relativeFrequency, direction) {
|
|
18
|
-
const n = x.length;
|
|
19
|
-
if (n == 0) {
|
|
20
|
-
throw new Error("Input array must not be empty.");
|
|
21
|
-
}
|
|
22
|
-
const w = (direction ? -1 : 1) * 2 * Math.PI / n * relativeFrequency;
|
|
23
|
-
const acc = new MutableComplex(0, 0);
|
|
24
|
-
for (let p = 0; p < n; p++) {
|
|
25
|
-
const c = MutableComplex.fromPolar(1, w * p);
|
|
26
|
-
c.mulBy(x.get(p));
|
|
27
|
-
acc.addTo(c);
|
|
28
|
-
}
|
|
29
|
-
return acc;
|
|
30
|
-
}
|
|
31
|
-
export function dftReal(x) {
|
|
32
|
-
const n = x.length;
|
|
33
|
-
const a = new ComplexArray(n);
|
|
34
|
-
for (let frequency = 0; frequency < n; frequency++) {
|
|
35
|
-
const c = dftRealSingle(x, frequency);
|
|
36
|
-
a.set(frequency, c);
|
|
37
|
-
}
|
|
38
|
-
return a;
|
|
39
|
-
}
|
|
40
|
-
export function dftRealHalf(x) {
|
|
41
|
-
const n = Math.ceil(x.length / 2);
|
|
42
|
-
const a = new ComplexArray(n);
|
|
43
|
-
for (let frequency = 0; frequency < n; frequency++) {
|
|
44
|
-
const c = dftRealSingle(x, frequency);
|
|
45
|
-
a.set(frequency, c);
|
|
46
|
-
}
|
|
47
|
-
return a;
|
|
48
|
-
}
|
|
49
|
-
export function dft(x, direction) {
|
|
50
|
-
const n = x.length;
|
|
51
|
-
const a = new ComplexArray(n);
|
|
52
|
-
for (let frequency = 0; frequency < n; frequency++) {
|
|
53
|
-
const c = dftSingle(x, frequency, direction);
|
|
54
|
-
a.set(frequency, c);
|
|
55
|
-
}
|
|
56
|
-
return a;
|
|
57
|
-
}
|
|
58
|
-
export function dftRealSpectrum(x, inclNyquist = false) {
|
|
59
|
-
const n = x.length;
|
|
60
|
-
if (n == 0) {
|
|
61
|
-
throw new Error("Input array must not be empty.");
|
|
62
|
-
}
|
|
63
|
-
const m = (n % 2 == 0 && inclNyquist) ? n / 2 + 1 : Math.ceil(n / 2);
|
|
64
|
-
const a = new ComplexArray(m);
|
|
65
|
-
for (let frequency = 0; frequency < m; frequency++) {
|
|
66
|
-
const c = dftRealSingle(x, frequency);
|
|
67
|
-
const r = (frequency == 0 || frequency == n / 2) ? 1 / n : 2 / n;
|
|
68
|
-
c.mulByReal(r);
|
|
69
|
-
a.set(frequency, c);
|
|
70
|
-
}
|
|
71
|
-
return a;
|
|
72
|
-
}
|
|
73
|
-
export function iDftRealSpectrum(x, len) {
|
|
74
|
-
const a = new Float64Array(len);
|
|
75
|
-
for (let frequency = 0; frequency < x.length; frequency++) {
|
|
76
|
-
const c = x.get(frequency);
|
|
77
|
-
synthesizeSinusoidal(a, frequency, c.abs(), c.arg());
|
|
78
|
-
}
|
|
79
|
-
return a;
|
|
80
|
-
}
|
|
81
|
-
function synthesizeSinusoidal(a, frequency, amplitude, phase) {
|
|
82
|
-
const n = a.length;
|
|
83
|
-
const w = frequency * 2 * Math.PI / n;
|
|
84
|
-
for (let p = 0; p < n; p++) {
|
|
85
|
-
a[p] += amplitude * Math.cos(phase + w * p);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
1
|
+
import Complex from "../math/Complex.js";
|
|
2
|
+
import MutableComplex from "../math/MutableComplex.js";
|
|
3
|
+
import ComplexArray from "../math/ComplexArray.js";
|
|
4
|
+
export function dftRealSingle(x, relativeFrequency) {
|
|
5
|
+
const n = x.length;
|
|
6
|
+
if (n == 0) {
|
|
7
|
+
throw new Error("Input array must not be empty.");
|
|
8
|
+
}
|
|
9
|
+
const w = -2 * Math.PI / n * relativeFrequency;
|
|
10
|
+
const acc = new MutableComplex(0, 0);
|
|
11
|
+
for (let p = 0; p < n; p++) {
|
|
12
|
+
const c = Complex.fromPolar(x[p], w * p);
|
|
13
|
+
acc.addTo(c);
|
|
14
|
+
}
|
|
15
|
+
return acc;
|
|
16
|
+
}
|
|
17
|
+
export function dftSingle(x, relativeFrequency, direction) {
|
|
18
|
+
const n = x.length;
|
|
19
|
+
if (n == 0) {
|
|
20
|
+
throw new Error("Input array must not be empty.");
|
|
21
|
+
}
|
|
22
|
+
const w = (direction ? -1 : 1) * 2 * Math.PI / n * relativeFrequency;
|
|
23
|
+
const acc = new MutableComplex(0, 0);
|
|
24
|
+
for (let p = 0; p < n; p++) {
|
|
25
|
+
const c = MutableComplex.fromPolar(1, w * p);
|
|
26
|
+
c.mulBy(x.get(p));
|
|
27
|
+
acc.addTo(c);
|
|
28
|
+
}
|
|
29
|
+
return acc;
|
|
30
|
+
}
|
|
31
|
+
export function dftReal(x) {
|
|
32
|
+
const n = x.length;
|
|
33
|
+
const a = new ComplexArray(n);
|
|
34
|
+
for (let frequency = 0; frequency < n; frequency++) {
|
|
35
|
+
const c = dftRealSingle(x, frequency);
|
|
36
|
+
a.set(frequency, c);
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
export function dftRealHalf(x) {
|
|
41
|
+
const n = Math.ceil(x.length / 2);
|
|
42
|
+
const a = new ComplexArray(n);
|
|
43
|
+
for (let frequency = 0; frequency < n; frequency++) {
|
|
44
|
+
const c = dftRealSingle(x, frequency);
|
|
45
|
+
a.set(frequency, c);
|
|
46
|
+
}
|
|
47
|
+
return a;
|
|
48
|
+
}
|
|
49
|
+
export function dft(x, direction) {
|
|
50
|
+
const n = x.length;
|
|
51
|
+
const a = new ComplexArray(n);
|
|
52
|
+
for (let frequency = 0; frequency < n; frequency++) {
|
|
53
|
+
const c = dftSingle(x, frequency, direction);
|
|
54
|
+
a.set(frequency, c);
|
|
55
|
+
}
|
|
56
|
+
return a;
|
|
57
|
+
}
|
|
58
|
+
export function dftRealSpectrum(x, inclNyquist = false) {
|
|
59
|
+
const n = x.length;
|
|
60
|
+
if (n == 0) {
|
|
61
|
+
throw new Error("Input array must not be empty.");
|
|
62
|
+
}
|
|
63
|
+
const m = (n % 2 == 0 && inclNyquist) ? n / 2 + 1 : Math.ceil(n / 2);
|
|
64
|
+
const a = new ComplexArray(m);
|
|
65
|
+
for (let frequency = 0; frequency < m; frequency++) {
|
|
66
|
+
const c = dftRealSingle(x, frequency);
|
|
67
|
+
const r = (frequency == 0 || frequency == n / 2) ? 1 / n : 2 / n;
|
|
68
|
+
c.mulByReal(r);
|
|
69
|
+
a.set(frequency, c);
|
|
70
|
+
}
|
|
71
|
+
return a;
|
|
72
|
+
}
|
|
73
|
+
export function iDftRealSpectrum(x, len) {
|
|
74
|
+
const a = new Float64Array(len);
|
|
75
|
+
for (let frequency = 0; frequency < x.length; frequency++) {
|
|
76
|
+
const c = x.get(frequency);
|
|
77
|
+
synthesizeSinusoidal(a, frequency, c.abs(), c.arg());
|
|
78
|
+
}
|
|
79
|
+
return a;
|
|
80
|
+
}
|
|
81
|
+
function synthesizeSinusoidal(a, frequency, amplitude, phase) {
|
|
82
|
+
const n = a.length;
|
|
83
|
+
const w = frequency * 2 * Math.PI / n;
|
|
84
|
+
for (let p = 0; p < n; p++) {
|
|
85
|
+
a[p] += amplitude * Math.cos(phase + w * p);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
88
|
//# sourceMappingURL=Dft.js.map
|
package/signal/Dft.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dft.js","sourceRoot":"","sources":["../../src/signal/Dft.ts"],"names":[],"mappings":"AAUA,OAAO,OAAO,MAAM,oBAAoB,CAAC;AACzC,OAAO,cAAc,MAAM,2BAA2B,CAAC;AACvD,OAAO,YAAY,MAAM,yBAAyB,CAAC;AAoBnD,MAAM,UAAU,aAAa,CAAE,CAAoB,EAAE,iBAAyB;IAC3E,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,IAAI,CAAC,IAAI,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"Dft.js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AAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACjE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACf,CAAC,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IAAC,CAAC;IACzB,OAAO,CAAC,CAAC;AAAC,CAAC;AAiBd,MAAM,UAAU,gBAAgB,CAAE,CAAe,EAAE,GAAW;IAC3D,MAAM,CAAC,GAAG,IAAI,YAAY,CAAC,GAAG,CAAC,CAAC;IAChC,KAAK,IAAI,SAAS,GAAG,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC;QACzD,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC3B,oBAAoB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAAC,CAAC;IAC1D,OAAO,CAAC,CAAC;AAAC,CAAC;AAEd,SAAS,oBAAoB,CAAE,CAAe,EAAE,SAAiB,EAAE,SAAiB,EAAE,KAAa;IAChG,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;IACnB,MAAM,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;IACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1B,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;IAAC,CAAC;AAAA,CAAC"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function generateSignalEnvelope(signal: ArrayLike<number>, windowWidthDc: number, windowWidthEnvelope: number): Float64Array;
|
|
1
|
+
export declare function generateSignalEnvelope(signal: ArrayLike<number>, windowWidthDc: number, windowWidthEnvelope: number): Float64Array;
|
|
2
|
+
//# sourceMappingURL=EnvelopeDetection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnvelopeDetection.d.ts","sourceRoot":"","sources":["../../src/signal/EnvelopeDetection.ts"],"names":[],"mappings":"AAwBA,wBAAgB,sBAAsB,CAAE,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,GAAI,YAAY,CAKtH"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as MathUtils from "../math/MathUtils.js";
|
|
2
|
-
export function generateSignalEnvelope(signal, windowWidthDc, windowWidthEnvelope) {
|
|
3
|
-
const a1 = MathUtils.
|
|
4
|
-
for (let i = 0; i < a1.length; i++) {
|
|
5
|
-
a1[i] = Math.abs(signal[i] - a1[i]);
|
|
6
|
-
}
|
|
7
|
-
const a2 = MathUtils.
|
|
8
|
-
return a2;
|
|
9
|
-
}
|
|
1
|
+
import * as MathUtils from "../math/MathUtils.js";
|
|
2
|
+
export function generateSignalEnvelope(signal, windowWidthDc, windowWidthEnvelope) {
|
|
3
|
+
const a1 = MathUtils.simpleMovingAverage(signal, windowWidthDc);
|
|
4
|
+
for (let i = 0; i < a1.length; i++) {
|
|
5
|
+
a1[i] = Math.abs(signal[i] - a1[i]);
|
|
6
|
+
}
|
|
7
|
+
const a2 = MathUtils.simpleMovingAverage(a1, windowWidthEnvelope);
|
|
8
|
+
return a2;
|
|
9
|
+
}
|
|
10
10
|
//# sourceMappingURL=EnvelopeDetection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvelopeDetection.js","sourceRoot":"","sources":["../../src/signal/EnvelopeDetection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAoBlD,MAAM,UAAU,sBAAsB,CAAE,MAAyB,EAAE,aAAqB,EAAE,mBAA2B;IAClH,MAAM,EAAE,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"EnvelopeDetection.js","sourceRoot":"","sources":["../../src/signal/EnvelopeDetection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAoBlD,MAAM,UAAU,sBAAsB,CAAE,MAAyB,EAAE,aAAqB,EAAE,mBAA2B;IAClH,MAAM,EAAE,GAAG,SAAS,CAAC,mBAAmB,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAChE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAClC,EAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAAC,CAAC;IACzC,MAAM,EAAE,GAAG,SAAS,CAAC,mBAAmB,CAAC,EAAE,EAAE,mBAAmB,CAAC,CAAC;IAClE,OAAO,EAAE,CAAC;AAAC,CAAC"}
|
package/signal/Fft.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import ComplexArray from "../math/ComplexArray.
|
|
2
|
-
export declare function fft(x: ComplexArray, direction?: boolean): ComplexArray;
|
|
3
|
-
export declare function fftReal(x: ArrayLike<number>): ComplexArray;
|
|
4
|
-
export declare function fftRealHalf(x: ArrayLike<number>, inclNyquist?: boolean): ComplexArray;
|
|
5
|
-
export declare function fftRealSpectrum(x: ArrayLike<number>, inclNyquist?: boolean): ComplexArray;
|
|
6
|
-
export declare function fftShift(x: ComplexArray): ComplexArray;
|
|
7
|
-
export declare function iFftRealHalfSimple(x: ComplexArray, len: number, inclNyquist?: boolean): Float64Array;
|
|
8
|
-
export declare function iFftRealHalfOpt(x: ComplexArray, len: number, inclNyquist?: boolean): Float64Array;
|
|
9
|
-
export declare function iFftRealHalf(x: ComplexArray, len: number, inclNyquist?: boolean): Float64Array;
|
|
1
|
+
import ComplexArray from "../math/ComplexArray.ts";
|
|
2
|
+
export declare function fft(x: ComplexArray, direction?: boolean): ComplexArray;
|
|
3
|
+
export declare function fftReal(x: ArrayLike<number>): ComplexArray;
|
|
4
|
+
export declare function fftRealHalf(x: ArrayLike<number>, inclNyquist?: boolean): ComplexArray;
|
|
5
|
+
export declare function fftRealSpectrum(x: ArrayLike<number>, inclNyquist?: boolean): ComplexArray;
|
|
6
|
+
export declare function fftShift(x: ComplexArray): ComplexArray;
|
|
7
|
+
export declare function iFftRealHalfSimple(x: ComplexArray, len: number, inclNyquist?: boolean): Float64Array;
|
|
8
|
+
export declare function iFftRealHalfOpt(x: ComplexArray, len: number, inclNyquist?: boolean): Float64Array;
|
|
9
|
+
export declare function iFftRealHalf(x: ComplexArray, len: number, inclNyquist?: boolean): Float64Array;
|
|
10
|
+
//# sourceMappingURL=Fft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Fft.d.ts","sourceRoot":"","sources":["../../src/signal/Fft.ts"],"names":[],"mappings":"AASA,OAAO,YAAY,MAAM,yBAAyB,CAAC;AAoBnD,wBAAgB,GAAG,CAAE,CAAC,EAAE,YAAY,EAAE,SAAS,UAAO,GAAI,YAAY,CAOvD;AAkIf,wBAAgB,OAAO,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,GAAI,YAAY,CACxB;AAmBrC,wBAAgB,WAAW,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,UAAQ,GAAI,YAAY,CA4BvE;AAoBf,wBAAgB,eAAe,CAAE,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,UAAQ,GAAI,YAAY,CAa5E;AAMd,wBAAgB,QAAQ,CAAE,CAAC,EAAE,YAAY,GAAI,YAAY,CAM3C;AAsBd,wBAAgB,kBAAkB,CAAE,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAI,YAAY,CAKpF;AAuCjB,wBAAgB,eAAe,CAAE,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAI,YAAY,CA+BrD;AAsB7C,wBAAgB,YAAY,CAAE,CAAC,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAI,YAAY,CAIvC"}
|