-
Notifications
You must be signed in to change notification settings - Fork 12
/
xreimZeroFilling.ts
48 lines (42 loc) · 1.08 KB
/
xreimZeroFilling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { DataXReIm } from '../types';
/**
* This function make a zero filling to re and im part.
*
* @param data - object of kind {x:[], re:[], im:[]}
* @param totalLength - final number of points
* @returns - data.
*/
export function xreimZeroFilling(
data: DataXReIm,
totalLength: number,
): DataXReIm {
const length = data.x.length;
if (totalLength === 0 || length === totalLength) return data;
if (length > totalLength) {
return {
x: data.x.slice(0, totalLength),
re: data.re.slice(0, totalLength),
im: data.im.slice(0, totalLength),
};
}
const x = data.x;
const re = data.re;
const im = data.im;
const newX = new Float64Array(totalLength);
const newRE = new Float64Array(totalLength);
const newIM = new Float64Array(totalLength);
for (let i = 0; i < length; i++) {
newX[i] = x[i];
newRE[i] = re[i];
newIM[i] = im[i];
}
const deltaX = (x[x.length - 1] - x[0]) / (length - 1);
for (let i = length; i < totalLength; i++) {
newX[i] = newX[i - 1] + deltaX;
}
return {
x: newX,
re: newRE,
im: newIM,
};
}