mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
* Fix #46 Draft Implementations * Add docs * Fixup * Add type declaration and test * Fixup tests * Fixup test * Format * Add examples in docs * Update fft.js Edit example in docs (`math.fft` returns complex matrix). * Update ifft.js Edit example in docs (`math.ffti` returns complex matrix). * Update fft.js Edit docs examples, representation of complex number from `a+bi` to `{re:a, im:b}` * Update ifft.js Edit docs examples, representation of complex number from `a+bi` to `{re:a, im:b}` * Update index.ts Edit test. Add test for `math.ifft` `math.fft` returns complex matrix. * Update index.ts Use `approx.deepEqual` instead off `assert.deepStrictEqual`. * Update index.ts Format code * Update index.ts Use `assert.ok(math.deepEqual(...))` instead of `approx.deepEqual`. * Update index.ts Format * Update index.ts Typo: replace `approx` with `assert`. Co-authored-by: Jos de Jong <wjosdejong@gmail.com>
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
// test fft
|
|
|
|
import approx from '../../../../tools/approx.js'
|
|
import math from '../../../../src/defaultInstance.js'
|
|
const fft = math.fft
|
|
|
|
describe('fft', function () {
|
|
it('should calculate 1-dimensional fourier transformation', function () {
|
|
const in1 = [1, math.complex(2, -1), math.complex(0, -1), math.complex(-1, 2)]
|
|
const out1 = [2, math.complex(-2, -2), math.complex(0, -2), math.complex(4, 4)]
|
|
approx.deepEqual(fft(in1.valueOf()), out1.valueOf())
|
|
approx.deepEqual(fft(math.matrix(in1)), math.matrix(out1))
|
|
})
|
|
|
|
it('should calculate multidimensional fourier transformation', function () {
|
|
const in1 = [
|
|
[1, 0],
|
|
[1, 0]
|
|
]
|
|
const out1 = [
|
|
[2, 2],
|
|
[0, 0]
|
|
]
|
|
approx.deepEqual(fft(in1.valueOf()), out1.valueOf())
|
|
approx.deepEqual(fft(math.matrix(in1)), math.matrix(out1))
|
|
const in2 = [
|
|
[0, 0, 1, 1],
|
|
[0, 0, 1, 1],
|
|
[1, 1, 0, 0],
|
|
[1, 1, 0, 0]
|
|
]
|
|
const out2 = [
|
|
[8, 0, 0, 0],
|
|
[0, math.complex(0, 4), 0, -4],
|
|
[0, 0, 0, 0],
|
|
[0, -4, 0, math.complex(0, -4)]
|
|
]
|
|
approx.deepEqual(fft(in2.valueOf()), out2.valueOf())
|
|
approx.deepEqual(fft(math.matrix(in2)), math.matrix(out2))
|
|
})
|
|
})
|