Published
Edited
Sep 15, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
err = (inp, oup) => {
const f = new FFT(inp.length >> 1);
const gold = f.createComplexArray();
f.transform(gold, inp);
const res = Array(inp.length);
for (let i = 0; i < inp.length; i += 2) {
const gscale = Math.sqrt(Math.pow(gold[i], 2) + Math.pow(gold[i + 1], 2));
// normalized golden vector
const reGnorm = gold[i] / gscale;
const imGnorm = gold[i+1] / gscale;
// error vector
const reErr = gold[i] - oup[i];
const imErr = gold[i + 1] - oup[i + 1];
// derotate error vector (complex conj multiplication)
const reErrN = reErr * reGnorm + imErr * imGnorm;
const imErrN = imErr * reGnorm - reErr * imGnorm;
// save it
res[i] = reErrN;
res[i + 1] = imErrN;
}
return res;
}
Insert cell
Insert cell
{
const div = DOM.element('div');
const err2 = err(inputData, outputDataRadix2);
const err4 = err(inputData, outputDataRadix4);
Plotly.newPlot(div, [
complexPlot(err2, 'radix2'),
complexPlot(err4, 'radix4'),
], {
shapes: [
bound(err2, 'rgb(31,119,180)'),
bound(err4, 'rgb(255,127,14)')
],
width: width,
height: width,
xaxis: {range: [-6e-6, 6e-6]},
yaxis: {range: [-6e-6, 6e-6]}
});
return div;
}
Insert cell
Insert cell
Insert cell
Insert cell
complexPlot = (arr, name) => {
return arr.reduce((res, e, i) => {
if (i & 1) { res.y.push(e); } else { res.x.push(e); }
return res;
},
{x: [], y: [], name: name, mode: 'markers'});
}
Insert cell
bound = (arr, color) => {
const a = arr.reduce((res, e) => Math.max(Math.abs(e), res), 0);
return {
type: 'rect',
x0: -a, y0: -a, x1: a, y1: a,
line: {color: color}
};
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more