Skip to content

Commit

Permalink
refactor(dsp): update spectrumPow() arg order
Browse files Browse the repository at this point in the history
- swap `window` & `n` args, since `window` more likely to be provided
  • Loading branch information
postspectacular committed Dec 22, 2020
1 parent f67f820 commit be1b615
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/dsp/src/fft/fft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,15 @@ export const spectrumMag = (
*
* @param complex
* @param db
* @param n
* @param window
* @param n
* @param out
*/
export const spectrumPow = (
complex: ComplexArray,
db = false,
n = complex[0].length / 2,
window: number | NumericArray = 2 / complex[0].length,
n = complex[0].length / 2,
out: NumericArray = []
) => {
const [real, img] = complex;
Expand Down
4 changes: 2 additions & 2 deletions packages/dsp/test/fft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ describe("fft", () => {
const norm = normalizeFFT(copyComplex(fwd), win);

assert(eqDelta(spectrumMag(norm)[I], A));
assert(eqDelta(spectrumPow(norm, false, N / 2, 1)[I], A / 2));
assert(eqDelta(spectrumPow(norm, true, N / 2, 1)[I], magDb(A)));
assert(eqDelta(spectrumPow(norm, false, 1)[I], A / 2));
assert(eqDelta(spectrumPow(norm, true, 1)[I], magDb(A)));
assert(eqDelta(spectrumPhase(norm)[I], (1 / 12) * TAU));
});
});

0 comments on commit be1b615

Please sign in to comment.