Global

Members

WFft

Description:
  • FFT與iFFT

Source:

FFT與iFFT

Example
let arr
let res

arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
res = wf.fft1d(arr)
console.log(res)
// => [
//   [ 120, 0 ],
//   [ -8, 40.21871593700678 ],
//   [ -8, 19.31370849898476 ],
//   [ -8.000000000000002, 11.972846101323912 ],
//   [ -8, 8 ],
//   [ -7.999999999999999, 5.345429103354391 ],
//   [ -8, 3.3137084989847594 ],
//   [ -8.000000000000002, 1.5912989390372623 ],
//   [ -8, 0 ],
//   [ -8, -1.5912989390372623 ],
//   [ -7.999999999999999, -3.3137084989847594 ],
//   [ -7.999999999999998, -5.345429103354393 ],
//   [ -7.999999999999999, -8 ],
//   [ -7.999999999999999, -11.97284610132391 ],
//   [ -7.999999999999997, -19.31370849898476 ],
//   [ -7.999999999999993, -40.21871593700678 ]
// ]

arr = [
    [120, 0],
    [-8, 40.21871593700678],
    [-8, 19.31370849898476],
    [-7.999999999999999, 11.972846101323913],
    [-8, 8],
    [-8, 5.345429103354391],
    [-8, 3.313708498984761],
    [-7.999999999999999, 1.5912989390372623],
    [-8, 0],
    [-7.999999999999999, -1.5912989390372623],
    [-8, -3.313708498984761],
    [-8, -5.345429103354391],
    [-8, -8],
    [-7.999999999999999, -11.972846101323913],
    [-8, -19.31370849898476],
    [-8, -40.21871593700678]
]
res = wf.ifft1d(arr)
console.log(res)
// => [
//    0,                      1,
//    2.0000000000000004, 3.0000000000000013,
//    4,                  5.000000000000002,
//    6,                  7.000000000000001,
//    8,                  9,
//   10,                 10.999999999999998,
//   12,                 12.999999999999998,
//   14,                 15
// ]

Methods

fft1d(arr) → {Array}

Description:
  • FFT1D

Source:
Example
let arr
let res

arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
res = wf.fft1d(arr)
console.log(res)
// => [
//   [ 120, 0 ],
//   [ -8, 40.21871593700678 ],
//   [ -8, 19.31370849898476 ],
//   [ -8.000000000000002, 11.972846101323912 ],
//   [ -8, 8 ],
//   [ -7.999999999999999, 5.345429103354391 ],
//   [ -8, 3.3137084989847594 ],
//   [ -8.000000000000002, 1.5912989390372623 ],
//   [ -8, 0 ],
//   [ -8, -1.5912989390372623 ],
//   [ -7.999999999999999, -3.3137084989847594 ],
//   [ -7.999999999999998, -5.345429103354393 ],
//   [ -7.999999999999999, -8 ],
//   [ -7.999999999999999, -11.97284610132391 ],
//   [ -7.999999999999997, -19.31370849898476 ],
//   [ -7.999999999999993, -40.21871593700678 ]
// ]
Parameters:
Name Type Description
arr Array

輸入數據陣列

Returns:

回傳轉換後數據陣列

Type
Array

fft2d(mat) → {Array}

Description:
  • FFT2D

Source:
Example
let mat
let res

mat = [[1, 2, 3], [4, 5, 6]]
res = wf.fft2d(mat)
console.log(res)
// => [
//   [ [ 21, 1.0445074572148558e-16 ], [ -2.9999999999999982, 1.7320508075688785 ], [ -3.0000000000000013, -1.7320508075688705 ] ],
//   [ [ -9, -2.326366143623307e-16 ], [ 0, -8.881784197001252e-16 ], [ 0, -2.7755575615628914e-15 ] ]
// ]
Parameters:
Name Type Description
mat Array

輸入二維實數矩陣

Returns:

回傳二維[re,im]複數矩陣

Type
Array

filter1d(arr, dt, hzStart, hzEnd, optopt) → {Array}

Description:
  • FFT1D Filter

Source:
Example
let dt
let arr
let res

//dt=0.0078125s, 3+6hz
dt = 0.0078125

arr = [
    0,
    0.437015151709824,
    0.845854910274064,
    1.20056554679302,
    1.47944976553089,
    1.66674368151922,
    1.75379573376597,
    1.73964987434863,
    1.63098631369783,
    1.44142799002054,
    1.19027504868833,
    0.900778315875612,
    0.598101848038141,
    0.307150781019375,
    0.0504516520458098,
    -0.153732804251563,
    -0.292893218813452,
    -0.361241031239776,
    -0.360072875476548,
    -0.297503430771426,
    -0.187593110348962,
    -0.0489494660021425,
    0.0970731816865672,
    0.228416556922734,
    0.324423348821458,
    0.367818520155133,
    0.346391996239585,
    0.254233601317238,
    0.0924099202087415,
    -0.130978839760706,
    -0.401370102712605,
    -0.698891832710318,
    -1,
    -1.27946118721924,
    -1.51251056875181,
    -1.67699974648618,
    -1.75534914481383,
    -1.73613585202716,
    -1.61517856456688,
    -1.39602400854158,
    -1.08979021355164,
    -0.714376916729265,
    -0.293107462345689,
    0.147084814656977,
    0.577773754381215,
    0.971283137555866,
    1.30286634912854,
    1.55263964022464,
    1.70710678118655,
    1.76014786721285,
    1.7133908766509,
    1.57593734934667,
    1.36346871276832,
    1.09681259653473,
    0.80009440465607,
    0.498634516368545,
    0.216772751324739,
    -0.0241926543480825,
    -0.207774827040493,
    -0.323625771825179,
    -0.368309299491684,
    -0.345455359932455,
    -0.265285555765141,
    -0.1435542027991,
    -3.67544536472586E-16,
    0.1435542027991,
    0.26528555576514,
    0.345455359932455,
    0.368309299491684,
    0.323625771825179,
    0.207774827040493,
    0.0241926543480835,
    -0.216772751324738,
    -0.498634516368544,
    -0.800094404656069,
    -1.09681259653473,
    -1.36346871276832,
    -1.57593734934667,
    -1.7133908766509,
    -1.76014786721285,
    -1.70710678118655,
    -1.55263964022464,
    -1.30286634912855,
    -0.971283137555864,
    -0.577773754381218,
    -0.14708481465698,
    0.293107462345686,
    0.714376916729258,
    1.08979021355163,
    1.39602400854158,
    1.61517856456688,
    1.73613585202716,
    1.75534914481383,
    1.67699974648618,
    1.51251056875181,
    1.27946118721924,
    1,
    0.698891832710321,
    0.40137010271261,
    0.130978839760704,
    -0.0924099202087405,
    -0.254233601317238,
    -0.346391996239584,
    -0.367818520155133,
    -0.324423348821457,
    -0.228416556922734,
    -0.0970731816865679,
    0.0489494660021418,
    0.18759311034896,
    0.297503430771423,
    0.360072875476548,
    0.361241031239776,
    0.292893218813452,
    0.153732804251566,
    -0.0504516520458086,
    -0.307150781019376,
    -0.598101848038137,
    -0.900778315875611,
    -1.19027504868833,
    -1.44142799002054,
    -1.63098631369783,
    -1.73964987434863,
    -1.75379573376597,
    -1.66674368151922,
    -1.47944976553089,
    -1.20056554679302,
    -0.845854910274064,
    -0.43701515170983,
]

res = wf.filter1d(arr, dt, 0, 2)
console.log(res)
// => [
//   -1.967983691641977e-17,
//   -2.307740440357446e-17,
//   -2.6914726362424797e-17,
//   -3.118255834826216e-17,
//   -3.587061878001477e-17,
//   -4.0967613709476845e-17,
//   -4.646126402941945e-17,
//   -5.2338335055034716e-17,
//   -5.858466840745145e-17,
//   -6.518521612250948e-17,
//   -7.212407690262343e-17,
//   -7.938453442440174e-17,
//   -8.694909760973329e-17,
//   -9.479954276332726e-17,
//   -1.029169574751909e-16,
//   -1.112817861822817e-16,
//   ... (112 more items)
// ]

res = wf.filter1d(arr, dt, 0, 4)
console.log(res)
// => [
//   -4.560690164444523e-16,
//   0.14673047445536136,
//   0.290284677254462,
//   0.4275550934302818,
//   0.5555702330196021,
//   0.6715589548470182,
//   0.7730104533627369,
//   0.8577286100002721,
//   0.9238795325112868,
//   0.970031253194544,
//   0.9951847266721972,
//   0.9987954562051725,
//   0.9807852804032308,
//   0.9415440651830213,
//   0.8819212643483555,
//   0.8032075314806454,
//   ... (112 more items)
// ]

res = wf.filter1d(arr, dt, 4, 8)
console.log(res)
// => [
//   -4.482834651769285e-16,
//   0.2902846772544623,
//   0.5555702330196025,
//   0.7730104533627374,
//   0.9238795325112875,
//   0.995184726672198,
//   0.9807852804032318,
//   0.8819212643483564,
//   0.7071067811865488,
//   0.47139673682599875,
//   0.19509032201612916,
//   -0.0980171403295599,
//   -0.3826834323650895,
//   -0.6343932841636456,
//   -0.8314696123025458,
//   -0.9569403357322097,
//   ... (112 more items)
// ]
Parameters:
Name Type Attributes Default Description
arr Array

輸入數據陣列

dt Number

輸入數據點時間間隔數字,單位s

hzStart Number

輸入過濾用帶通頻率下限數字,單位Hz

hzEnd Number

輸入過濾用帶通頻率上限數字,單位Hz

opt Object <optional>
{}

選項物件

Properties
Name Type Attributes Default Description
useOneTurn Boolean <optional>
true

true=輸入視為一個完整週期(頭尾重複),週期(n-1)dt;false=標準DFT,週期ndt

Returns:

回傳帶通處理後數據陣列

Type
Array

filter2d(mat, dt, hzStart, hzEnd, optopt) → {Array}

Description:
  • FFT2D 帶通濾波

Source:
Example
let mat
let res

mat = [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6]]
res = wf.filter2d(mat, 0.5, 0.3, 0.8)
console.log(res)
// => [
//   [ -2, -2, 0, 0 ],
//   [ -2, -2, 0, 0 ],
//   [  0,  0, 2, 2 ],
//   [  0,  0, 2, 2 ]
// ]
Parameters:
Name Type Attributes Default Description
mat Array

輸入二維實數矩陣

dt Number

時間間隔,單位s

hzStart Number

帶通頻率下限,單位Hz(以徑向頻率 sqrt(fRow²+fCol²) 判斷)

hzEnd Number

帶通頻率上限,單位Hz

opt Object <optional>
{}

選項物件

Properties
Name Type Attributes Default Description
useOneTurn Boolean <optional>
true

true=各軸視為一個完整週期(頭尾重複),週期(len-1)dt;false=標準DFT,週期lendt

Returns:

回傳帶通處理後二維實數矩陣

Type
Array

ifft1d(arr) → {Array}

Description:
  • iFFT1D

Source:
Example
let arr
let res

arr = [
    [120, 0],
    [-8, 40.21871593700678],
    [-8, 19.31370849898476],
    [-7.999999999999999, 11.972846101323913],
    [-8, 8],
    [-8, 5.345429103354391],
    [-8, 3.313708498984761],
    [-7.999999999999999, 1.5912989390372623],
    [-8, 0],
    [-7.999999999999999, -1.5912989390372623],
    [-8, -3.313708498984761],
    [-8, -5.345429103354391],
    [-8, -8],
    [-7.999999999999999, -11.972846101323913],
    [-8, -19.31370849898476],
    [-8, -40.21871593700678]
]
res = wf.ifft1d(arr)
console.log(res)
// => [
//    0,                      1,
//    2.0000000000000004, 3.0000000000000013,
//    4,                  5.000000000000002,
//    6,                  7.000000000000001,
//    8,                  9,
//   10,                 10.999999999999998,
//   12,                 12.999999999999998,
//   14,                 15
// ]
Parameters:
Name Type Description
arr Array

輸入數據陣列

Returns:

回傳轉換後數據陣列

Type
Array

ifft2d(mat) → {Array}

Description:
  • iFFT2D

Source:
Example
let mat
let res

mat = [
    [ [ 21, 1.0445074572148558e-16 ], [ -2.9999999999999982, 1.7320508075688785 ], [ -3.0000000000000013, -1.7320508075688705 ] ],
    [ [ -9, -2.326366143623307e-16 ], [ 0, -8.881784197001252e-16 ], [ 0, -2.7755575615628914e-15 ] ]
]
res = wf.ifft2d(mat)
console.log(res)
// => [
//   [ 1.0000000000000002, 2.0000000000000004, 2.9999999999999987 ],
//   [ 4, 5.000000000000001, 5.999999999999999 ]
// ]
Parameters:
Name Type Description
mat Array

輸入二維[re,im]複數矩陣

Returns:

回傳二維實數矩陣

Type
Array

spectrum1d(arr, dt, optopt) → {Array}

Description:
  • 振幅頻譜1D

Source:
Example
let arr
let res

arr = [1, 2, 3, 4]
res = wf.spectrum1d(arr, 1)
console.log(res)
// => [
//   { freq: 0, real: 10, imag: 0, ampl: 10 },
//   { freq: 0.3333333333333333, real: -2, imag: 2, ampl: 2.8284271247461903 }
// ]
Parameters:
Name Type Attributes Default Description
arr Array

輸入數據陣列

dt Number

時間間隔,單位s

opt Object <optional>
{}

選項物件

Properties
Name Type Attributes Default Description
useOneTurn Boolean <optional>
true

true=輸入視為一個完整週期(頭尾重複),週期(n-1)dt;false=標準DFT,週期ndt

Returns:

回傳[{freq,real,imag,ampl},...]頻譜陣列

Type
Array

spectrum2d(mat, dt, optopt) → {Array}

Description:
  • 振幅頻譜2D

Source:
Example
let mat
let res

mat = [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6]]
res = wf.spectrum2d(mat, 0.5)
console.log(res)
// => [
//   [
//     { freqRow: 0, freqCol: 0, real: 48, imag: 0, ampl: 48 },
//     { freqRow: 0, freqCol: 0.6666666666666666, real: -8, imag: 8, ampl: 11.313708498984761 }
//   ],
//   [
//     { freqRow: 0.6666666666666666, freqCol: 0, real: -8, imag: 8, ampl: 11.313708498984761 },
//     { freqRow: 0.6666666666666666, freqCol: 0.6666666666666666, real: 0, imag: 0, ampl: 0 }
//   ]
// ]
Parameters:
Name Type Attributes Default Description
mat Array

輸入二維實數矩陣

dt Number

時間間隔,單位s

opt Object <optional>
{}

選項物件

Properties
Name Type Attributes Default Description
useOneTurn Boolean <optional>
true

true=各軸視為一個完整週期(頭尾重複),週期(len-1)dt;false=標準DFT,週期lendt

Returns:

回傳二維[{freqRow,freqCol,real,imag,ampl},...]頻譜矩陣(僅正頻半象限)

Type
Array