/** * Typed Signal Processing Functions (Parallel-First) * * AssemblyScript-friendly TypeScript implementations with typed-function * integration and workerpool parallel execution. * * Includes FFT, IFFT, convolution, and correlation functions optimized * for Float64Array. * * Parallelism note: the element-wise spectrum operations (magnitude, power) * offload large Float64Array inputs to the worker pool. The radix-2 FFT * butterfly itself runs on the calling thread — its stages have tight * data dependencies that a chunked worker dispatch cannot exploit. * * @packageDocumentation */ import { applyWindowDispatch } from '../wasm/signal/wasm-bridge.js'; /** 64-bit float (default for decimals) */ type f64 = number; /** 32-bit signed integer */ type i32 = number; /** * Parallel FFT with typed-function dispatch * * Supports: number[], Float64Array, Complex[] */ export declare const parallelFFT: import("@danielsimonjr/mathts-core").TypedFunction; /** * Parallel IFFT with typed-function dispatch. * * Async: large inverse transforms are parallelized across worker threads via * the four-step (transpose) decomposition; small ones run on this thread. */ export declare const parallelIFFT: import("@danielsimonjr/mathts-core").TypedFunction; /** * FFT magnitude spectrum */ export declare const parallelFFTMagnitude: import("@danielsimonjr/mathts-core").TypedFunction; /** * FFT power spectrum (|X|^2) */ export declare const parallelFFTPower: import("@danielsimonjr/mathts-core").TypedFunction; /** * Parallel 1D convolution using FFT method * * Uses convolution theorem: conv(x,h) = IFFT(FFT(x) * FFT(h)) */ export declare const parallelConv: import("@danielsimonjr/mathts-core").TypedFunction; /** * Parallel cross-correlation */ export declare const parallelXCorr: import("@danielsimonjr/mathts-core").TypedFunction; /** * Parallel auto-correlation */ export declare const parallelAutoCorr: import("@danielsimonjr/mathts-core").TypedFunction; /** * Cross-correlation of two real signals via sliding dot product. * Returns array of length (a.length + b.length - 1). * * @param a - First signal * @param b - Second signal * @returns Cross-correlation array */ export declare function crossCorrelation(a: number[], b: number[]): number[]; /** * Auto-correlation of a signal (cross-correlation with itself). * * @param a - Input signal * @returns Auto-correlation array */ export declare function autoCorrelation(a: number[]): number[]; /** * Compute the group delay of a digital filter defined by numerator and * denominator polynomial coefficients. * * Group delay is the negative derivative of the phase response with * respect to angular frequency. * * @param b - Numerator coefficients (FIR for IIR: b/a) * @param a - Denominator coefficients (use [1] for FIR) * @param w - Optional array of angular frequencies; defaults to 512 points in [0, pi] * @returns Object with { w: number[], delay: number[] } */ export declare function groupDelay(b: number[], a: number[], w?: number[]): { w: number[]; delay: number[]; }; /** * Unwrap phase angles by adding +/-2*pi to remove discontinuities. * * @param phase - Array of phase values in radians * @returns Unwrapped phase array */ export declare function unwrapPhase(phase: number[]): number[]; /** * Discrete Cosine Transform (Type II). * * @param x - Input signal * @returns DCT coefficients * * @example * dct([1, 2, 3, 4]) // DCT-II coefficients */ export declare function dct(x: number[]): number[]; /** * Inverse Discrete Cosine Transform (Type III). * * @param X - DCT coefficients * @returns Reconstructed signal */ export declare function idct(X: number[]): number[]; /** * Discrete Sine Transform (Type II). * * @param x - Input signal * @returns DST coefficients */ export declare function dst(x: number[]): number[]; /** * Inverse Discrete Sine Transform (Type III). * * @param X - DST coefficients * @returns Reconstructed signal */ export declare function idst(X: number[]): number[]; /** * Single-level discrete wavelet transform (periodization boundary). * * Haar/db1 use a dedicated closed-form (and WASM-accelerated) 2-tap path. * All other supported families (db2-4, sym2-4, coif1-2) route through the * general orthogonal filter bank in `../signal/wavelet-filters.ts`, which is * verified to reproduce this same Haar/db1 result bit-for-bit and to match * `pywt.dwt(..., mode='periodization')` for every family. * * @param x - Input signal (length >= 2) * @param wavelet - Wavelet name; see `SUPPORTED_WAVELETS` in * `../signal/wavelet-filters.ts` for the full list * @returns `{ approx: number[], detail: number[] }` */ export declare function dwt(x: number[], wavelet?: string): { approx: number[]; detail: number[]; }; /** * 2D FFT of a matrix (array of arrays). * * The transform is two batches of independent 1D FFTs — every row, then every * column — so for large inputs each batch is dispatched to the worker pool via * `computePool.fftBatch`. Below the parallel threshold (or when the pool is * uninitialized) it falls back to the sequential per-row/per-column loop. * * @param x - 2D input (rows x cols), each value is real * @returns `{ real: number[][], imag: number[][] }` */ export declare function fft2d(x: number[][]): Promise<{ real: number[][]; imag: number[][]; }>; /** * Numerical continuous Fourier transform. * F(omega) = integral f(t) * exp(-j*omega*t) dt * * @param f - Time-domain function * @param t - Time sample points * @param omega - Frequency to evaluate at * @returns `{ re: number, im: number }` */ export declare function fourier(f: (t: f64) => f64, t: number[], omega: f64): { re: f64; im: f64; }; /** * Numerical inverse Fourier transform. * f(t) = (1/2pi) integral F(omega) * exp(j*omega*t) domega * * @param F - Frequency-domain function returning {re, im} * @param omega - Frequency sample points * @param t - Time point to evaluate at * @returns Reconstructed value at t */ export declare function invFourier(F: (omega: f64) => { re: f64; im: f64; }, omega: number[], t: f64): f64; /** * Hilbert transform of a real signal via FFT. * * @param x - Real input signal * @returns Imaginary part of the analytic signal */ export declare function hilbertTransform(x: number[]): number[]; /** * Compute spectrogram using Short-Time Fourier Transform. * * Each windowed frame is FFT'd independently, so for large inputs the frames * are dispatched as a batch to the worker pool via `computePool.fftBatch`. * Below the parallel threshold (or when the pool is uninitialized) it falls * back to the sequential per-frame loop. * * @param x - Input signal * @param opts - { windowSize, hopSize, window } * @returns `{ magnitude: number[][], frequencies: number[], times: number[] }` */ export declare function spectrogram(x: number[], opts?: { windowSize?: i32; hopSize?: i32; window?: string; }): Promise<{ magnitude: number[][]; frequencies: number[]; times: number[]; }>; /** * Estimate power spectral density using periodogram method. * * @param x - Input signal * @param opts - { nfft, window } * @returns `{ psd: number[], frequencies: number[] }` */ export declare function periodogram(x: number[], opts?: { nfft?: i32; window?: string; }): { psd: number[]; frequencies: number[]; }; /** * Apply a lowpass FIR filter using windowed sinc. * * @param x - Input signal * @param cutoff - Normalized cutoff frequency (0 to 0.5) * @param order - Filter order (default 31) * @returns Filtered signal */ export declare function lowpassFilter(x: number[], cutoff: f64, order?: i32): number[]; /** * Apply a highpass FIR filter using windowed sinc. * * @param x - Input signal * @param cutoff - Normalized cutoff frequency (0 to 0.5) * @param order - Filter order (default 31) * @returns Filtered signal */ export declare function highpassFilter(x: number[], cutoff: f64, order?: i32): number[]; /** * Apply a bandpass FIR filter. * * @param x - Input signal * @param low - Low cutoff frequency (normalized, 0 to 0.5) * @param high - High cutoff frequency (normalized, 0 to 0.5) * @param order - Filter order (default 31) * @returns Filtered signal */ export declare function bandpassFilter(x: number[], low: f64, high: f64, order?: i32): number[]; /** * Resample a signal to a new sample rate using linear interpolation. * * @param x - Input signal * @param newRate - Target sample rate * @param oldRate - Original sample rate * @returns Resampled signal */ export declare function resample(x: number[], newRate: f64, oldRate: f64): number[]; /** * Apply a median filter to a signal. * * @param x - Input signal * @param n - Window size (default 3, must be odd) * @returns Filtered signal */ export declare function medfilt(x: number[], n?: i32): number[]; /** * Generate a window function of given type and length. * * @param n - Window length * @param type - Window type: 'hamming' | 'hann' | 'blackman' | 'rectangular' | 'bartlett' * @returns Window coefficients */ export declare function windowFunction(n: i32, type: string): number[]; /** * Direct convolution of two signals (alias for sequential use). * * @param a - First signal * @param b - Second signal * @returns Convolution result (length a.length + b.length - 1) */ export declare function convolve(a: number[], b: number[]): number[]; /** * Cross-correlation of two signals (alias). * * @param a - First signal * @param b - Second signal * @returns Cross-correlation result */ export declare function correlate(a: number[], b: number[]): number[]; /** * Welch's overlapped-segment-averaging Power Spectral Density. * * For arrays >= WASM_SIGNAL_THRESHOLD samples (4096) dispatches to the * WASM kernel (AS → JS fallback). * * @param signal - Input signal samples * @param opts - { frameLength, overlap, window } * @returns `{ psd: number[], frequencies: number[], frameLength: number }` */ export declare function welchPSD(signal: number[] | Float64Array, opts?: { frameLength?: i32; overlap?: i32; window?: string; }): { psd: number[]; frequencies: number[]; frameLength: number; }; /** * Bartlett's non-overlapped segment-averaging Power Spectral Density. * * Special case of Welch with overlap=0 and rectangular window. * * @param signal - Input signal samples * @param opts - { frameLength } * @returns `{ psd: number[], frequencies: number[], frameLength: number }` */ export declare function bartlettPSD(signal: number[] | Float64Array, opts?: { frameLength?: i32; }): { psd: number[]; frequencies: number[]; frameLength: number; }; /** * Multi-taper Power Spectral Density (Thomson's method, order K=5). * * Uses K discrete prolate spheroidal sequences (DPSS, approximated here * as Slepian windows via cos-sum) to reduce spectral leakage. The final * PSD is the mean of the K individual tapered periodograms. * * For large inputs, each tapered periodogram is computed via the WASM * Welch kernel (frame = full signal, overlap = 0). * * @param signal - Input signal samples * @param opts - { nfft, K } (K = number of tapers, default 5) * @returns `{ psd: number[], frequencies: number[] }` */ export declare function multiTaperPSD(signal: number[] | Float64Array, opts?: { nfft?: i32; K?: i32; }): { psd: number[]; frequencies: number[]; }; /** * Goertzel algorithm: compute the power |X[k]|² at a single frequency. * * Dispatches to the WASM kernel for arrays >= 4096 samples. * * @param signal - Input signal samples * @param targetFreq - Target frequency in Hz * @param sampleRate - Sample rate in Hz * @returns |X[k]|² (unnormalized power at the target frequency) */ export declare function goertzel(signal: number[] | Float64Array, targetFreq: f64, sampleRate: f64): f64; /** * Chirp-Z Transform (Bluestein algorithm). * * Computes M points of the z-transform along a chirp contour in the * z-plane. The contour is defined by: * A = exp(2πi·phiStart) — starting point * W = exp(2πi·phiStep) — angular step * * Dispatches to the WASM kernel for max(n, m) >= 4096. * * @param signal - Input signal samples (real) * @param m - Number of output points * @param phiStart - Start angle in turns (e.g. 0 = DC, 0.5 = Nyquist) * @param phiStep - Step angle in turns (negative for standard DFT) * @returns `{ re: Float64Array, im: Float64Array }` — M complex output values */ export declare function chirpZTransform(signal: number[] | Float64Array, m: i32, phiStart?: f64, phiStep?: f64): { re: Float64Array; im: Float64Array; }; /** * Primary export: typed signal processing functions */ export declare const typedSignal: { fft: import("@danielsimonjr/mathts-core").TypedFunction; ifft: import("@danielsimonjr/mathts-core").TypedFunction; fftMagnitude: import("@danielsimonjr/mathts-core").TypedFunction; fftPower: import("@danielsimonjr/mathts-core").TypedFunction; conv: import("@danielsimonjr/mathts-core").TypedFunction; xcorr: import("@danielsimonjr/mathts-core").TypedFunction; autocorr: import("@danielsimonjr/mathts-core").TypedFunction; crossCorrelation: typeof crossCorrelation; autoCorrelation: typeof autoCorrelation; groupDelay: typeof groupDelay; unwrapPhase: typeof unwrapPhase; dct: typeof dct; idct: typeof idct; dst: typeof dst; idst: typeof idst; dwt: typeof dwt; fft2d: typeof fft2d; fourier: typeof fourier; invFourier: typeof invFourier; hilbertTransform: typeof hilbertTransform; spectrogram: typeof spectrogram; periodogram: typeof periodogram; lowpassFilter: typeof lowpassFilter; highpassFilter: typeof highpassFilter; bandpassFilter: typeof bandpassFilter; resample: typeof resample; medfilt: typeof medfilt; windowFunction: typeof windowFunction; convolve: typeof convolve; correlate: typeof correlate; welchPSD: typeof welchPSD; bartlettPSD: typeof bartlettPSD; multiTaperPSD: typeof multiTaperPSD; goertzel: typeof goertzel; chirpZTransform: typeof chirpZTransform; applyWindow: typeof applyWindowDispatch; }; /** * Initialize signal processing pool */ export declare function initializeSignal(): Promise; /** * Terminate signal processing pool */ export declare function terminateSignal(): Promise; export {}; //# sourceMappingURL=signal.d.ts.map