phase method
Applies in-place phasing (rotation in the complex plane) to the complex-
valued array whith the real part reals
and the imaginary part imags
.
according to the following equations:
realsi
:= realsi
*cos(phii
) - imagsi
*sin(phii
)
imagsi
:= imagsi
*cos(phii
) + realsi
*sin(phii
)
with
phii
:= a0 + (i/(reals.length-1))*a1, i=0...reals.length-1
a0 and a1 are the "zeroeth and first order phasing angles" in degrees.
inverse
= true ==> reverse phasing (sine terms will change sign
according to an inverse rotation in the complex plane)
Implementation
void phase(Float64List reals, Float64List imags, double a0, double a1,
bool inverse) {
if (imags == null || (imags.length != reals.length)) {
throw """real and imaginary spectrum have unequal sizes:
${reals.length} + ' / ' + ${imags.length}""";
}
double real, imag, realnew, imagnew;
int size1 = reals.length - 1;
double a0rad = a0 * math.pi / 180,
a1rad = a1 * math.pi / 180;
double sinPhi, cosPhi;
double phi;
for (int i = 0; i <= size1; i++) {
real = reals[i];
imag = imags[i];
phi = a0rad + (i * a1rad) / size1;
cosPhi = math.cos(phi);
sinPhi = math.sin(phi);
if (inverse) {
realnew = real * cosPhi - imag * sinPhi;
imagnew = imag * cosPhi + real * sinPhi;
} else {
realnew = real * cosPhi + imag * sinPhi;
imagnew = imag * cosPhi - real * sinPhi;
}
reals[i] = realnew;
imags[i] = imagnew;
}
}