Skip to content

Commit f22677f

Browse files
committed
Rename irfft to fft
1 parent cbdb7ee commit f22677f

5 files changed

Lines changed: 24 additions & 25 deletions

File tree

changelog.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 2.0.0
1+
# 2.1.0
22

33
## Breaking
44

@@ -12,7 +12,7 @@
1212
## Added
1313

1414
- `fft()` named export — returns complex DFT as `[re, im]`, N/2+1 bins, unnormalized.
15-
- `irfft(re, im)` — inverse of `fft()`, native split-radix DIF inverse (~1.8x faster than complex IFFT approach).
15+
- `ifft(re, im)` — inverse of `fft()`, native split-radix DIF inverse (~1.8x faster than complex IFFT approach).
1616
- `cfft(re, im)` / `cifft(re, im)` — in-place complex FFT and inverse FFT (radix-2 Cooley-Tukey).
1717
- Optional output buffer parameter for both `rfft()` and `fft()`.
1818

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ function inverseTransform(N, entry) {
463463
* @param {Float64Array} [output] - Optional buffer (length N). If omitted, returns internal view (overwritten on next call with same N).
464464
* @returns {Float64Array} Real time-domain signal, length N.
465465
*/
466-
export function irfft(re, im, output) {
466+
export function ifft(re, im, output) {
467467
const bins = re.length
468468
const N = (bins - 1) << 1
469469
if (N < 2 || (N & (N - 1))) throw Error('Input must have N/2+1 bins where N is power of 2 (>= 2).')

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"dsp",
2121
"fft",
2222
"rfft",
23-
"irfft",
2423
"ifft",
2524
"cfft",
2625
"dft"

readme.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Returns complex DFT as `[re, im]`, each `Float64Array` of length N/2+1 (DC throu
4747
- Unnormalized: `X[k] = sum( x[n] * e^(-j*2*pi*k*n/N) )`.
4848
- DC and Nyquist bins always have `im = 0` (real input).
4949

50-
### `irfft(re, im, output?)` — named export
50+
### `ifft(re, im, output?)` — named export
5151

5252
Inverse of `fft()` — recovers time-domain signal from complex spectrum. Returns `Float64Array` of length N.
5353

@@ -58,7 +58,7 @@ Inverse of `fft()` — recovers time-domain signal from complex spectrum. Return
5858
```js
5959
const [re, im] = fft(signal)
6060
// modify spectrum...
61-
const recovered = irfft(re, im)
61+
const recovered = ifft(re, im)
6262
```
6363

6464
### `cfft(re, im)` — named export
@@ -71,7 +71,7 @@ In-place complex inverse FFT (1/N normalized). Same signature as `cfft`.
7171

7272
### View semantics
7373

74-
`rfft`, `fft`, and `irfft` return internal cached buffers by default. The next call with the same N overwrites the previous result. Pass an output buffer to keep results across calls:
74+
`rfft`, `fft`, and `ifft` return internal cached buffers by default. The next call with the same N overwrites the previous result. Pass an output buffer to keep results across calls:
7575

7676
```js
7777
const out = new Float64Array(N / 2)

test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { test } from 'node:test'
22
import assert from 'node:assert/strict'
3-
import rfft, { fft, irfft, cfft, cifft } from './index.js'
3+
import rfft, { fft, ifft, cfft, cifft } from './index.js'
44

55
const EPSILON = 1e-6
66

@@ -262,85 +262,85 @@ test('fft: view overwritten on repeated calls', () => {
262262
assert(Math.abs(ra[1][10] - (-N / 2)) < EPSILON, 'ra now reflects b')
263263
})
264264

265-
// --- Inverse real FFT (irfft) ---
265+
// --- Inverse real FFT (ifft) ---
266266

267-
test('irfft: rejects invalid input', () => {
267+
test('ifft: rejects invalid input', () => {
268268
// bins=1 → N=0 (invalid)
269-
assert.throws(() => irfft(new Float64Array(1), new Float64Array(1)))
269+
assert.throws(() => ifft(new Float64Array(1), new Float64Array(1)))
270270
// bins=4 → N=6 (not power of 2)
271-
assert.throws(() => irfft(new Float64Array(4), new Float64Array(4)))
271+
assert.throws(() => ifft(new Float64Array(4), new Float64Array(4)))
272272
})
273273

274-
test('irfft(fft(x)) round-trip recovers signal', () => {
274+
test('ifft(fft(x)) round-trip recovers signal', () => {
275275
for (const N of [4, 64, 256, 1024]) {
276276
const input = new Float32Array(N)
277277
for (let i = 0; i < N; i++) input[i] = Math.sin(i * 0.7) + Math.cos(i * 1.3)
278278

279279
const [re, im] = fft(input)
280-
const recovered = irfft(re, im)
280+
const recovered = ifft(re, im)
281281

282282
assert.equal(recovered.length, N)
283283
for (let i = 0; i < N; i++)
284284
assert(Math.abs(recovered[i] - input[i]) < EPSILON, `N=${N}, i=${i}: ${recovered[i]} vs ${input[i]}`)
285285
}
286286
})
287287

288-
test('irfft: DC spectrum → constant signal', () => {
288+
test('ifft: DC spectrum → constant signal', () => {
289289
const N = 64, half = N / 2
290290
const re = new Float64Array(half + 1)
291291
const im = new Float64Array(half + 1)
292292
re[0] = N // X[0] = N for DC=1
293-
const out = irfft(re, im)
293+
const out = ifft(re, im)
294294
for (let i = 0; i < N; i++)
295295
assert(Math.abs(out[i] - 1) < EPSILON, `i=${i}: ${out[i]}`)
296296
})
297297

298-
test('irfft: cosine spectrum → cosine signal', () => {
298+
test('ifft: cosine spectrum → cosine signal', () => {
299299
const N = 128, k0 = 5, half = N / 2
300300
const re = new Float64Array(half + 1)
301301
const im = new Float64Array(half + 1)
302302
re[k0] = N / 2 // cos at bin k0
303-
const out = irfft(re, im)
303+
const out = ifft(re, im)
304304
for (let i = 0; i < N; i++) {
305305
const expected = Math.cos(2 * Math.PI * k0 * i / N)
306306
assert(Math.abs(out[i] - expected) < EPSILON, `i=${i}: ${out[i]} vs ${expected}`)
307307
}
308308
})
309309

310-
test('irfft: sine spectrum → sine signal', () => {
310+
test('ifft: sine spectrum → sine signal', () => {
311311
const N = 128, k0 = 5, half = N / 2
312312
const re = new Float64Array(half + 1)
313313
const im = new Float64Array(half + 1)
314314
im[k0] = -N / 2 // sin at bin k0: X[k0] = -jN/2
315-
const out = irfft(re, im)
315+
const out = ifft(re, im)
316316
for (let i = 0; i < N; i++) {
317317
const expected = Math.sin(2 * Math.PI * k0 * i / N)
318318
assert(Math.abs(out[i] - expected) < EPSILON, `i=${i}: ${out[i]} vs ${expected}`)
319319
}
320320
})
321321

322-
test('irfft: output buffer parameter', () => {
322+
test('ifft: output buffer parameter', () => {
323323
const N = 64, half = N / 2
324324
const re = new Float64Array(half + 1)
325325
const im = new Float64Array(half + 1)
326326
re[0] = N
327327
const buf = new Float64Array(N)
328-
const ret = irfft(re, im, buf)
328+
const ret = ifft(re, im, buf)
329329
assert.equal(ret, buf)
330330
assert(Math.abs(buf[0] - 1) < EPSILON)
331331
})
332332

333-
test('irfft: view overwritten on repeated calls', () => {
333+
test('ifft: view overwritten on repeated calls', () => {
334334
const N = 64, half = N / 2
335335

336336
const re1 = new Float64Array(half + 1), im1 = new Float64Array(half + 1)
337337
re1[0] = N // DC → all ones
338-
const a = irfft(re1, im1)
338+
const a = ifft(re1, im1)
339339
assert(Math.abs(a[half] - 1) < EPSILON, 'DC: a[32] should be 1')
340340

341341
const re2 = new Float64Array(half + 1), im2 = new Float64Array(half + 1)
342342
re2[3] = N / 2 // cosine at bin 3 → cos(2π·3·32/64) = cos(3π) = -1
343-
irfft(re2, im2) // overwrites a
343+
ifft(re2, im2) // overwrites a
344344

345345
assert(Math.abs(a[half] - (-1)) < EPSILON, 'a[32] should now be -1 (cosine at bin 3)')
346346
})

0 commit comments

Comments
 (0)