Skip to content

Commit

Permalink
feat(dsp): add windowWelch(), add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 18, 2020
1 parent a3f9209 commit 84cd476
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packages/dsp/src/fft/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,21 @@ export const window = (fn: WindowFn, lenOfBuf: number | FloatArray) => {
return buf;
};

export const applyWindow = (a: NumericArray, b: NumericArray, out = a) => {
for (let i = a.length; --i >= 0; ) {
out[i] = a[i] * b[i];
/**
* Takes a `signal` and `window` buffer and multiplies both elementwise. Writes
* results into `out` (or back into `signal` by default).
*
* @param signal
* @param window
* @param out
*/
export const applyWindow = (
signal: NumericArray,
window: NumericArray,
out = signal
) => {
for (let i = signal.length; --i >= 0; ) {
out[i] = signal[i] * window[i];
}
return out;
};
Expand All @@ -39,6 +51,8 @@ export const windowRect: WindowFn = () => 1;
export const windowBartlett: WindowFn = (i, n) =>
1 - Math.abs((i - n / 2) / (n / 2));

export const windowWelch: WindowFn = (i, n) => 1 - ((i - n / 2) / (n / 2)) ** 2;

export const windowSin: WindowFn = (i, n) => sin((PI * i) / n);

export const windowSinPow: Fn<number, WindowFn> = (k) => (i, n) =>
Expand Down

0 comments on commit 84cd476

Please sign in to comment.