Published
Edited
Jul 23, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
draw(rectangular(N, amplitude))
Insert cell
Insert cell
draw(bartlett(N, amplitude))
Insert cell
Insert cell
draw(parzen(N, amplitude))
Insert cell
Insert cell
Insert cell
draw(tukey(N, amplitude, alpha))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
rectangular = (N, amplitude) => {
return Array(N + 1).fill(amplitude);
}
Insert cell
bartlett = (N, amplitude) => {
return rectangular(N, amplitude).map((y, n) => y * (1 - Math.abs((2 * n) / N - 1)));
}
Insert cell
parzen = (N, amplitude) => {
const L = N + 1;
const f1 = (y, n) => {
const r = Math.abs((2 * n) / L);
return y * (1 - 6 * r ** 2 * (1 - r));
};
const f2 = (y, n) => {
const r = Math.abs((2 * n) / L);
return y * 2 * (1 - r) ** 3;
};
return rectangular(N, amplitude).map((y, n) =>
Math.abs(n - N / 2) > L / 4 && Math.abs(n - N / 2) <= L / 2
? f2(y, n - N / 2)
: f1(y, n - N / 2)
);
}
Insert cell
tukey = (N, amplitude, alpha) => {
const L = N + 1;
const c1 = (L * alpha) / 2;
const c2 = Math.PI / c1;
const f1 = (y, n) => {
return y * 0.5 * (1 - Math.cos(c2 * n));
};
return rectangular(N, amplitude).map((y, n) =>
n < c1 ? f1(y, n) : n > N - c1 ? f1(y, N - n) : y
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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