Published
Edited
May 2, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
pulseTrain = {
const a = Array(600);
for (let i = 0; i<a.length; i++) {
a[i] = ((i - i%100)/100)%2==1 ? 1 : 0;
}
return a;
}
Insert cell
impulseResponse = {
const a = Array(100);
let area = 0;
for (let i = 0; i<100; i++) {
const phase = i*2*Math.PI/200;
a[i] = Math.sin(phase);
area += a[i];
}
// normalize so that area under the curve is 1:
for (let i = 0; i< a.length; i++) {
a[i] = a[i] / area;
}
return a;
}
Insert cell
convolution = convolute(pulseTrain, impulseResponse);
Insert cell
slowerPulseTrain = {
const a = Array(600);
for (let i = 0; i<a.length; i++) {
a[i] = ((i - i%150)/150)%2==1 ? 1 : 0;
}
return a;
}
Insert cell
slowerConvolution = convolute(slowerPulseTrain, impulseResponse);
Insert cell
function convolute(a,b) {
let result = Array(a.length + b.length).fill(0);
a.forEach((sample, i) => {
b.forEach((weight, j) => {
result[i + j] += sample * weight;
});
});
return result;
}
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