dsp-collection
Version:
A collection of JavaScript modules for digital signal processing (written in TypeScript)
69 lines • 1.65 kB
JavaScript
import Complex from "./Complex.js";
export default class MutableComplex extends Complex {
constructor(re = 0, im = 0) {
super(re, im);
}
static fromComplex(x) {
return new MutableComplex(x.re, x.im);
}
static expj(arg) {
return new MutableComplex(Math.cos(arg), Math.sin(arg));
}
static fromPolar(abs, arg) {
return new MutableComplex(abs * Math.cos(arg), abs * Math.sin(arg));
}
set(x) {
this.re = x.re;
this.im = x.im;
}
setReIm(re, im = 0) {
this.re = re;
this.im = im;
}
setExpj(arg) {
this.re = Math.cos(arg);
this.im = Math.sin(arg);
}
setPolar(abs, arg) {
this.re = abs * Math.cos(arg);
this.im = abs * Math.sin(arg);
}
addRealTo(x) {
this.re += x;
}
addTo(x) {
this.re += x.re;
this.im += x.im;
}
subRealFrom(x) {
this.re -= x;
}
subFrom(x) {
this.re -= x.re;
this.im -= x.im;
}
mulByReal(x) {
this.re *= x;
this.im *= x;
}
mulBy(x) {
this.setMul(this.re, this.im, x.re, x.im);
}
divByReal(x) {
this.re /= x;
this.im /= x;
}
divBy(x) {
this.setDiv(this.re, this.im, x.re, x.im);
}
setMul(re1, im1, re2, im2) {
this.re = re1 * re2 - im1 * im2;
this.im = re1 * im2 + im1 * re2;
}
setDiv(re1, im1, re2, im2) {
const m = re1 * re1 + im1 * im1;
this.re = (re1 * re2 + im1 * im2) / m;
this.im = (im1 * re2 - re1 * im2) / m;
}
}
//# sourceMappingURL=MutableComplex.js.map