dspx 1.2.4 → 1.3.0
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 +40 -78
- package/binding.gyp +10 -0
- package/dist/FilterBankDesign.d.ts +233 -0
- package/dist/FilterBankDesign.d.ts.map +1 -0
- package/dist/FilterBankDesign.js +247 -0
- package/dist/FilterBankDesign.js.map +1 -0
- package/dist/advanced-dsp.d.ts +6 -6
- package/dist/advanced-dsp.d.ts.map +1 -1
- package/dist/advanced-dsp.js +35 -12
- package/dist/advanced-dsp.js.map +1 -1
- package/dist/backends.d.ts +0 -103
- package/dist/backends.d.ts.map +1 -1
- package/dist/backends.js +0 -217
- package/dist/backends.js.map +1 -1
- package/dist/bindings.d.ts +216 -17
- package/dist/bindings.d.ts.map +1 -1
- package/dist/bindings.js +503 -43
- package/dist/bindings.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +67 -8
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +38 -8
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +84 -26
- package/dist/utils.js.map +1 -1
- package/package.json +1 -2
- package/prebuilds/win32-x64/dspx.node +0 -0
- package/scripts/add-dispose-to-tests.js +145 -0
- package/src/native/DspPipeline.cc +668 -118
- package/src/native/DspPipeline.h +13 -0
- package/src/native/FilterBankDesignBindings.cc +241 -0
- package/src/native/IDspStage.h +24 -0
- package/src/native/UtilityBindings.cc +130 -0
- package/src/native/adapters/ClipDetectionStage.h +15 -4
- package/src/native/adapters/ConvolutionStage.h +101 -0
- package/src/native/adapters/CumulativeMovingAverageStage.h +264 -0
- package/src/native/adapters/DecimatorStage.h +80 -0
- package/src/native/adapters/DifferentiatorStage.h +13 -0
- package/src/native/adapters/ExponentialMovingAverageStage.h +290 -0
- package/src/native/adapters/FilterBankStage.cc +336 -0
- package/src/native/adapters/FilterBankStage.h +170 -0
- package/src/native/adapters/FilterStage.cc +122 -0
- package/src/native/adapters/FilterStage.h +4 -0
- package/src/native/adapters/HilbertEnvelopeStage.h +55 -0
- package/src/native/adapters/IntegratorStage.h +15 -0
- package/src/native/adapters/InterpolatorStage.h +51 -0
- package/src/native/adapters/LinearRegressionStage.h +40 -0
- package/src/native/adapters/LmsStage.h +63 -0
- package/src/native/adapters/MeanAbsoluteValueStage.h +76 -0
- package/src/native/adapters/MovingAverageStage.h +119 -0
- package/src/native/adapters/PeakDetectionStage.h +53 -0
- package/src/native/adapters/RectifyStage.h +14 -0
- package/src/native/adapters/ResamplerStage.h +67 -0
- package/src/native/adapters/RlsStage.h +76 -0
- package/src/native/adapters/RmsStage.h +72 -0
- package/src/native/adapters/SnrStage.h +45 -0
- package/src/native/adapters/SscStage.h +65 -0
- package/src/native/adapters/StftStage.h +62 -0
- package/src/native/adapters/VarianceStage.h +59 -0
- package/src/native/adapters/WampStage.h +59 -0
- package/src/native/adapters/WaveformLengthStage.h +51 -0
- package/src/native/adapters/ZScoreNormalizeStage.h +64 -0
- package/src/native/core/CumulativeMovingAverageFilter.h +123 -0
- package/src/native/core/ExponentialMovingAverageFilter.h +129 -0
- package/src/native/core/FilterBankDesign.h +266 -0
- package/src/native/core/Policies.h +124 -0
- package/src/native/utils/CircularBufferArray.cc +2 -1
- package/src/native/utils/Toon.h +195 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://www.typescriptlang.org/)
|
|
6
6
|
[](./LICENSE)
|
|
7
7
|
|
|
8
|
-
> **A
|
|
8
|
+
> **A high-performance DSP library with native C++ acceleration, Redis state persistence, and comprehensive time-series processing. Built for Node.js backends processing real-time biosignals, audio, and sensor data.**
|
|
9
9
|
|
|
10
10
|
** v1.0.0 Release** Fully tested (500+ tests passing), battle-tested architecture, comprehensive documentation. Ready for production workloads.
|
|
11
11
|
|
|
@@ -19,8 +19,7 @@ A modern DSP library built for Node.js backends processing real-time biosignals,
|
|
|
19
19
|
- 🎯 **SIMD Acceleration** – AVX2/SSE2/NEON optimizations provide 2-8x speedup on batch operations and rectification
|
|
20
20
|
- ⚡ **Optimal FIR Filters (NEW)** – Pre-computed Parks-McClellan coefficients ship with library (30-50% faster than window-based)
|
|
21
21
|
- 🔧 **TypeScript-First** – Full type safety with excellent IntelliSense
|
|
22
|
-
- 📡 **
|
|
23
|
-
- 🔥 **Kafka Streaming (Experimental)** – Real-time data ingestion and log streaming via Apache Kafka (testing in progress)
|
|
22
|
+
- 📡 **Low state serialization overhead** – Less than 0.1ms latency for state save/load operations
|
|
24
23
|
- ⏱️ **Time-Series Processing** – Support for irregular timestamps and time-based windows
|
|
25
24
|
- 🔗 **Fluent Pipeline API** – Chain filter operations with method chaining
|
|
26
25
|
- 🎯 **Zero-Copy Processing** – Direct TypedArray manipulation for minimal overhead
|
|
@@ -344,7 +343,7 @@ const output = await pipeline.process(input, {
|
|
|
344
343
|
|
|
345
344
|
**SIMD Acceleration:** Batch operations and rectification are 2-8x faster with AVX2/SSE2/NEON on x86_64. See [SIMD_OPTIMIZATIONS.md](https://github.com/A-KGeorge/dspx/blob/main/docs/SIMD_OPTIMIZATIONS.md) for details.
|
|
346
345
|
|
|
347
|
-
**Recommendation:** Use batched callbacks in production. Individual callbacks benchmark faster but block the Node.js event loop and can't integrate with real telemetry systems (
|
|
346
|
+
**Recommendation:** Use batched callbacks in production. Individual callbacks benchmark faster but block the Node.js event loop and can't integrate with real telemetry systems (Datadog, Loki).
|
|
348
347
|
|
|
349
348
|
### 🎯 FFT Performance Note
|
|
350
349
|
|
|
@@ -540,77 +539,57 @@ console.log(input); // [1, 2, 3, 4, 5] - unchanged
|
|
|
540
539
|
console.log(output); // [1, 1.5, 2, 3, 4] - smoothed
|
|
541
540
|
```
|
|
542
541
|
|
|
543
|
-
###
|
|
542
|
+
### Low state serialization overhead
|
|
544
543
|
|
|
545
544
|
```typescript
|
|
546
545
|
import { createDspPipeline } from "dspx";
|
|
546
|
+
import { v4 as uuidv4 } from "uuid";
|
|
547
547
|
import { createClient } from "redis";
|
|
548
548
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
// Create pipeline with Redis config
|
|
552
|
-
const pipeline = createDspPipeline({
|
|
553
|
-
redisHost: "localhost",
|
|
554
|
-
redisPort: 6379,
|
|
555
|
-
stateKey: "dsp:user123:channel1",
|
|
556
|
-
});
|
|
557
|
-
|
|
558
|
-
pipeline.MovingAverage({ windowSize: 100 });
|
|
549
|
+
let redis;
|
|
550
|
+
let redisAvailable = false;
|
|
559
551
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
await
|
|
564
|
-
|
|
565
|
-
}
|
|
552
|
+
try {
|
|
553
|
+
redis = createClient({ url: "redis://localhost:6379" });
|
|
554
|
+
await redis.connect();
|
|
555
|
+
await redis.ping();
|
|
556
|
+
redisAvailable = true;
|
|
557
|
+
} catch {}
|
|
566
558
|
|
|
567
|
-
|
|
568
|
-
await pipeline.process(chunk1, { sampleRate: 2000, channels: 1 });
|
|
559
|
+
const stateKey = `dspx-state-${uuidv4()}`;
|
|
569
560
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
561
|
+
const pipeline = createDspPipeline();
|
|
562
|
+
pipeline
|
|
563
|
+
.MovingAverage({ mode: "batch", windowSize: 10, windowDuration: 2 })
|
|
564
|
+
.Rms({ mode: "batch", windowSize: 10, windowDuration: 2 })
|
|
565
|
+
.Rectify({ mode: "half" });
|
|
573
566
|
|
|
574
|
-
|
|
575
|
-
|
|
567
|
+
await pipeline.process(new Float32Array([1, -1, 2, -2, 3, -3]), {
|
|
568
|
+
channels: 1,
|
|
569
|
+
});
|
|
576
570
|
|
|
577
|
-
|
|
578
|
-
pipeline.clearState();
|
|
579
|
-
```
|
|
571
|
+
const serialized = await pipeline.saveState();
|
|
580
572
|
|
|
581
|
-
|
|
573
|
+
if (redisAvailable) await redis.set(stateKey, serialized);
|
|
582
574
|
|
|
583
|
-
|
|
575
|
+
const pipeline2 = createDspPipeline();
|
|
576
|
+
pipeline2
|
|
577
|
+
.MovingAverage({ mode: "batch", windowSize: 10, windowDuration: 2 })
|
|
578
|
+
.Rms({ mode: "batch", windowSize: 10, windowDuration: 2 })
|
|
579
|
+
.Rectify({ mode: "half" });
|
|
584
580
|
|
|
585
|
-
|
|
586
|
-
import { createDspPipeline, createKafkaConsumer } from "dspx";
|
|
581
|
+
await pipeline2.loadState(serialized);
|
|
587
582
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
pipeline
|
|
591
|
-
.MovingAverage({ mode: "moving", windowSize: 10 })
|
|
592
|
-
.Rms({ mode: "moving", windowSize: 5 });
|
|
593
|
-
|
|
594
|
-
// Consume sensor data from Kafka topic
|
|
595
|
-
const consumer = await createKafkaConsumer({
|
|
596
|
-
brokers: ["localhost:9092"],
|
|
597
|
-
groupId: "dsp-processors",
|
|
598
|
-
topics: ["sensor-data"],
|
|
599
|
-
onMessage: async ({ value }) => {
|
|
600
|
-
const samples = new Float32Array(value.data);
|
|
601
|
-
const output = await pipeline.process(samples, {
|
|
602
|
-
channels: 1,
|
|
603
|
-
sampleRate: 44100,
|
|
604
|
-
});
|
|
605
|
-
console.log("Processed:", output[0]);
|
|
606
|
-
},
|
|
583
|
+
const output = await pipeline2.process(new Float32Array([4, -4, 5, -5]), {
|
|
584
|
+
channels: 1,
|
|
607
585
|
});
|
|
608
|
-
|
|
609
|
-
|
|
586
|
+
console.log(output);
|
|
587
|
+
if (redisAvailable) {
|
|
588
|
+
redis.destroy();
|
|
589
|
+
console.log("\n✓ Disconnected from Redis");
|
|
590
|
+
}
|
|
610
591
|
```
|
|
611
592
|
|
|
612
|
-
**See [Kafka Integration Guide](https://github.com/A-KGeorge/dspx/blob/main/docs/KAFKA_INTEGRATION.md) for real-time streaming examples.**
|
|
613
|
-
|
|
614
593
|
### Multi-Channel Processing
|
|
615
594
|
|
|
616
595
|
```typescript
|
|
@@ -638,15 +617,7 @@ const output = await pipeline.process(fourChannelData, {
|
|
|
638
617
|
### Creating a Pipeline
|
|
639
618
|
|
|
640
619
|
```typescript
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
interface RedisConfig {
|
|
644
|
-
redisHost?: string; // Redis server hostname (optional)
|
|
645
|
-
redisPort?: number; // Redis server port (optional)
|
|
646
|
-
stateKey?: string; // Key prefix for state storage (optional)
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
const pipeline = createDspPipeline(config?: RedisConfig);
|
|
620
|
+
const pipeline = createDspPipeline();
|
|
650
621
|
```
|
|
651
622
|
|
|
652
623
|
### Process Methods
|
|
@@ -1838,15 +1809,11 @@ import { createClient } from "redis";
|
|
|
1838
1809
|
const redis = await createClient({ url: "redis://localhost:6379" }).connect();
|
|
1839
1810
|
const stateKey = "dsp:stream:sensor01";
|
|
1840
1811
|
|
|
1841
|
-
const pipeline = createDspPipeline(
|
|
1842
|
-
redisHost: "localhost",
|
|
1843
|
-
redisPort: 6379,
|
|
1844
|
-
stateKey,
|
|
1845
|
-
});
|
|
1812
|
+
const pipeline = createDspPipeline();
|
|
1846
1813
|
|
|
1847
1814
|
pipeline.MovingAverage({ windowSize: 100 });
|
|
1848
|
-
|
|
1849
1815
|
// Restore state if processing was interrupted
|
|
1816
|
+
await redis.set(stateKey, savedState);
|
|
1850
1817
|
const savedState = await redis.get(stateKey);
|
|
1851
1818
|
if (savedState) {
|
|
1852
1819
|
await pipeline.loadState(savedState);
|
|
@@ -2394,11 +2361,6 @@ All 500+ tests pass after these fixes. Run `npm test` to verify.
|
|
|
2394
2361
|
|
|
2395
2362
|
We welcome contributions! Here are areas where help is particularly needed:
|
|
2396
2363
|
|
|
2397
|
-
### High Priority
|
|
2398
|
-
|
|
2399
|
-
- **Kafka Integration Testing** – The Kafka streaming feature is experimental and needs comprehensive integration tests. Help us validate producer/consumer patterns, error handling, and performance under load.
|
|
2400
|
-
- **Additional Filters** – Implement new DSP filters (bandpass, highpass, lowpass, etc.) following the existing architecture patterns.
|
|
2401
|
-
|
|
2402
2364
|
### How to Contribute
|
|
2403
2365
|
|
|
2404
2366
|
1. Fork the repository
|
package/binding.gyp
CHANGED
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"src/native/core/IirFilter.cc",
|
|
20
20
|
"src/native/FftBindings.cc",
|
|
21
21
|
"src/native/FilterBindings.cc",
|
|
22
|
+
"src/native/FilterBankDesignBindings.cc",
|
|
22
23
|
"src/native/MatrixBindings.cc",
|
|
23
24
|
"src/native/UtilityBindings.cc",
|
|
24
25
|
"src/native/utils/CircularBufferArray.cc",
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
"src/native/utils/SlidingWindowFilter.cc",
|
|
28
29
|
"src/native/utils/TimeSeriesBuffer.cc",
|
|
29
30
|
"src/native/adapters/FilterStage.cc",
|
|
31
|
+
"src/native/adapters/FilterBankStage.cc",
|
|
30
32
|
"src/native/adapters/FftStage.cc"
|
|
31
33
|
],
|
|
32
34
|
"include_dirs": [
|
|
@@ -38,6 +40,14 @@
|
|
|
38
40
|
"src/native/emg",
|
|
39
41
|
"src/native/vendors/eigen-3.4.0"
|
|
40
42
|
],
|
|
43
|
+
"dependencies": [
|
|
44
|
+
],
|
|
45
|
+
"libraries": [
|
|
46
|
+
],
|
|
47
|
+
"sources!": [
|
|
48
|
+
],
|
|
49
|
+
"sources+": [
|
|
50
|
+
],
|
|
41
51
|
"defines": [
|
|
42
52
|
"NAPI_VERSION=8"
|
|
43
53
|
],
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filter Bank Design
|
|
3
|
+
*
|
|
4
|
+
* Utilities for designing psychoacoustic and mathematical filter banks.
|
|
5
|
+
* These are stateless functions that generate filter coefficients.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Frequency spacing scale for filter bank
|
|
9
|
+
* - 'linear': Linear spacing in Hz (equal bandwidth)
|
|
10
|
+
* - 'log': Logarithmic spacing (constant Q)
|
|
11
|
+
* - 'mel': Mel scale (mimics human hearing perception)
|
|
12
|
+
* - 'bark': Bark scale (critical band rate)
|
|
13
|
+
*/
|
|
14
|
+
export type FilterScale = "linear" | "log" | "mel" | "bark";
|
|
15
|
+
/**
|
|
16
|
+
* Filter topology type
|
|
17
|
+
* - 'butterworth': Maximally flat passband response
|
|
18
|
+
* - 'chebyshev': Equiripple passband response (steeper rolloff)
|
|
19
|
+
*/
|
|
20
|
+
export type FilterBankType = "butterworth" | "chebyshev";
|
|
21
|
+
/**
|
|
22
|
+
* Options for filter bank design
|
|
23
|
+
*/
|
|
24
|
+
export interface FilterBankOptions {
|
|
25
|
+
/**
|
|
26
|
+
* Frequency spacing scale
|
|
27
|
+
* - 'mel': Recommended for speech/audio analysis (mimics human hearing)
|
|
28
|
+
* - 'bark': Alternative psychoacoustic scale
|
|
29
|
+
* - 'log': Constant-Q filter bank (octave bands)
|
|
30
|
+
* - 'linear': Equal bandwidth bands
|
|
31
|
+
*/
|
|
32
|
+
scale: FilterScale;
|
|
33
|
+
/**
|
|
34
|
+
* Number of frequency bands
|
|
35
|
+
* Typical values:
|
|
36
|
+
* - Mel spectrograms: 20-40 bands
|
|
37
|
+
* - Audio analysis: 10-30 bands
|
|
38
|
+
* - Octave bands: 10 bands (use 'log' scale)
|
|
39
|
+
*/
|
|
40
|
+
count: number;
|
|
41
|
+
/**
|
|
42
|
+
* Sample rate in Hz
|
|
43
|
+
*/
|
|
44
|
+
sampleRate: number;
|
|
45
|
+
/**
|
|
46
|
+
* Frequency range [minFreq, maxFreq] in Hz
|
|
47
|
+
* @example [20, 8000] // 20 Hz to 8 kHz for speech
|
|
48
|
+
* @example [0, sampleRate/2] // Full spectrum
|
|
49
|
+
*/
|
|
50
|
+
frequencyRange: [number, number];
|
|
51
|
+
/**
|
|
52
|
+
* Filter topology (optional, defaults to 'butterworth')
|
|
53
|
+
* - 'butterworth': Smoother response, more gradual rolloff
|
|
54
|
+
* - 'chebyshev': Steeper rolloff, slight passband ripple
|
|
55
|
+
*/
|
|
56
|
+
type?: FilterBankType;
|
|
57
|
+
/**
|
|
58
|
+
* Filter order per band (optional, defaults to 2)
|
|
59
|
+
* Higher order = steeper slopes but more computation
|
|
60
|
+
* Typical range: 2-8
|
|
61
|
+
*/
|
|
62
|
+
order?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Passband ripple for Chebyshev filters in dB (optional, defaults to 0.5)
|
|
65
|
+
* Only used when type='chebyshev'
|
|
66
|
+
* Typical range: 0.1-1.0 dB
|
|
67
|
+
*/
|
|
68
|
+
rippleDb?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Filter coefficients for a single band
|
|
72
|
+
*/
|
|
73
|
+
export interface FilterCoefficients {
|
|
74
|
+
/** Numerator coefficients (feedforward) */
|
|
75
|
+
b: number[];
|
|
76
|
+
/** Denominator coefficients (feedback) */
|
|
77
|
+
a: number[];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Filter Bank Design Utilities
|
|
81
|
+
*
|
|
82
|
+
* Generates sets of bandpass filters covering a frequency range according to
|
|
83
|
+
* psychoacoustic (Mel, Bark) or mathematical (Linear, Log) scales.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* // Create 24-band Mel-spaced filter bank for speech analysis
|
|
87
|
+
* const melBank = FilterBankDesign.design({
|
|
88
|
+
* scale: 'mel',
|
|
89
|
+
* count: 24,
|
|
90
|
+
* sampleRate: 16000,
|
|
91
|
+
* frequencyRange: [100, 8000]
|
|
92
|
+
* });
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Create octave-band filter bank
|
|
96
|
+
* const octaveBank = FilterBankDesign.design({
|
|
97
|
+
* scale: 'log',
|
|
98
|
+
* count: 10,
|
|
99
|
+
* sampleRate: 44100,
|
|
100
|
+
* frequencyRange: [20, 20000],
|
|
101
|
+
* type: 'butterworth',
|
|
102
|
+
* order: 4
|
|
103
|
+
* });
|
|
104
|
+
*/
|
|
105
|
+
export declare class FilterBankDesign {
|
|
106
|
+
/**
|
|
107
|
+
* Design a filter bank with specified options
|
|
108
|
+
*
|
|
109
|
+
* This is a stateless operation that returns filter coefficients
|
|
110
|
+
* ready to be used with IIR filter processors or pipelines.
|
|
111
|
+
*
|
|
112
|
+
* @param options - Filter bank design options
|
|
113
|
+
* @returns Array of filter coefficients (one per band)
|
|
114
|
+
*
|
|
115
|
+
* @throws Error if options are invalid:
|
|
116
|
+
* - count must be positive
|
|
117
|
+
* - frequency range must be valid
|
|
118
|
+
* - maxFreq must be less than Nyquist frequency
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* // Design a Mel-spaced filter bank for speech
|
|
122
|
+
* const bank = FilterBankDesign.design({
|
|
123
|
+
* scale: 'mel',
|
|
124
|
+
* count: 24,
|
|
125
|
+
* sampleRate: 16000,
|
|
126
|
+
* frequencyRange: [100, 8000]
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* // Use the coefficients with an IIR filter
|
|
130
|
+
* const pipeline = createDspPipeline();
|
|
131
|
+
* bank.forEach((coeffs, i) => {
|
|
132
|
+
* pipeline.filter({
|
|
133
|
+
* type: 'iir',
|
|
134
|
+
* b: coeffs.b,
|
|
135
|
+
* a: coeffs.a
|
|
136
|
+
* });
|
|
137
|
+
* });
|
|
138
|
+
*/
|
|
139
|
+
static design(options: FilterBankOptions): FilterCoefficients[];
|
|
140
|
+
/**
|
|
141
|
+
* Create a Mel-scale filter bank (helper method)
|
|
142
|
+
*
|
|
143
|
+
* Mel scale mimics human auditory perception where equal distances
|
|
144
|
+
* on the Mel scale correspond to equal perceived pitch differences.
|
|
145
|
+
*
|
|
146
|
+
* Common for: Speech recognition, audio analysis, spectrograms
|
|
147
|
+
*
|
|
148
|
+
* @param count - Number of bands (typically 20-40)
|
|
149
|
+
* @param sampleRate - Sample rate in Hz
|
|
150
|
+
* @param range - Frequency range [min, max] in Hz (defaults to [0, Nyquist])
|
|
151
|
+
* @returns Array of filter coefficients
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* // Standard 40-band Mel filter bank for speech recognition
|
|
155
|
+
* const melBank = FilterBankDesign.createMel(40, 16000, [100, 8000]);
|
|
156
|
+
*/
|
|
157
|
+
static createMel(count: number, sampleRate: number, range?: [number, number]): FilterCoefficients[];
|
|
158
|
+
/**
|
|
159
|
+
* Create a Bark-scale filter bank (helper method)
|
|
160
|
+
*
|
|
161
|
+
* Bark scale represents critical band rate in human hearing.
|
|
162
|
+
* Each Bark corresponds to a critical band width.
|
|
163
|
+
*
|
|
164
|
+
* Common for: Psychoacoustic modeling, audio compression
|
|
165
|
+
*
|
|
166
|
+
* @param count - Number of bands (typically 20-30)
|
|
167
|
+
* @param sampleRate - Sample rate in Hz
|
|
168
|
+
* @param range - Frequency range [min, max] in Hz (defaults to [0, Nyquist])
|
|
169
|
+
* @returns Array of filter coefficients
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* // 24-band Bark filter bank
|
|
173
|
+
* const barkBank = FilterBankDesign.createBark(24, 44100, [20, 20000]);
|
|
174
|
+
*/
|
|
175
|
+
static createBark(count: number, sampleRate: number, range?: [number, number]): FilterCoefficients[];
|
|
176
|
+
/**
|
|
177
|
+
* Create a logarithmic (constant-Q) filter bank (helper method)
|
|
178
|
+
*
|
|
179
|
+
* Logarithmic spacing creates constant-Q bands where Q = f_center / bandwidth.
|
|
180
|
+
* This is common in musical applications (octave bands).
|
|
181
|
+
*
|
|
182
|
+
* Common for: Musical analysis, octave band analysis, EQ
|
|
183
|
+
*
|
|
184
|
+
* @param count - Number of bands (typically 10 for octave bands)
|
|
185
|
+
* @param sampleRate - Sample rate in Hz
|
|
186
|
+
* @param range - Frequency range [min, max] in Hz (defaults to [20, Nyquist])
|
|
187
|
+
* @returns Array of filter coefficients
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* // Standard 10-band octave filter bank
|
|
191
|
+
* const octaveBank = FilterBankDesign.createLog(10, 44100, [20, 20000]);
|
|
192
|
+
*/
|
|
193
|
+
static createLog(count: number, sampleRate: number, range?: [number, number]): FilterCoefficients[];
|
|
194
|
+
/**
|
|
195
|
+
* Create a linear filter bank (helper method)
|
|
196
|
+
*
|
|
197
|
+
* Linear spacing creates equal-bandwidth bands across the spectrum.
|
|
198
|
+
* Less perceptually relevant but mathematically simple.
|
|
199
|
+
*
|
|
200
|
+
* Common for: Analysis, research, testing
|
|
201
|
+
*
|
|
202
|
+
* @param count - Number of bands
|
|
203
|
+
* @param sampleRate - Sample rate in Hz
|
|
204
|
+
* @param range - Frequency range [min, max] in Hz (defaults to [0, Nyquist])
|
|
205
|
+
* @returns Array of filter coefficients
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* // 20 equal-bandwidth bands
|
|
209
|
+
* const linearBank = FilterBankDesign.createLinear(20, 44100);
|
|
210
|
+
*/
|
|
211
|
+
static createLinear(count: number, sampleRate: number, range?: [number, number]): FilterCoefficients[];
|
|
212
|
+
/**
|
|
213
|
+
* Get frequency boundaries for a filter bank design
|
|
214
|
+
*
|
|
215
|
+
* Returns the boundary frequencies without actually designing the filters.
|
|
216
|
+
* Useful for visualization and planning.
|
|
217
|
+
*
|
|
218
|
+
* @param options - Filter bank design options (same as design())
|
|
219
|
+
* @returns Array of boundary frequencies in Hz (length = count + 1)
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* const boundaries = FilterBankDesign.getBoundaries({
|
|
223
|
+
* scale: 'mel',
|
|
224
|
+
* count: 24,
|
|
225
|
+
* sampleRate: 16000,
|
|
226
|
+
* frequencyRange: [100, 8000]
|
|
227
|
+
* });
|
|
228
|
+
* console.log('Band edges:', boundaries);
|
|
229
|
+
* // [100, 145.2, 195.8, ..., 8000]
|
|
230
|
+
*/
|
|
231
|
+
static getBoundaries(options: FilterBankOptions): number[];
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=FilterBankDesign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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