Published
Edited
Mar 13, 2022
5 stars
Chandrupatla’s root-finding methodSidi’s root-finding methodRegular numbersDruidJS workerNatural breaksDistance to a segmentRay out of a convex hullWord Tour: 40k words and their friendsHello, @thi.ng/grid-iteratorsHead/tail breaksPseudo-blue noise shaderHow fast does walk-on-spheres converge?AoC 12: shortest path under constraintsKDE estimationPlot: Correlation heatmapPoisson Finish 2Poisson disk sampling functionsWoS with transportSimple and surprising sortLocal medianTime series topological subsamplingUnion-FindLevel set experiment 1Mean value coordinatesPoisson potentialMiddle-squareWorld of squares (spherical)World of squaresLargest Inscribed SquareHello, PyWaveletsGeothmetic meandianHello, Reorder.jsGeometric MedianImage FFTTransport to a mapDisc TransportTP3: Power Diagram and Semi-Discrete Optimal TransportThe blue waveHello, genetic-jsSliced Optimal TransportDruidJSSelf-Organizing Maps meet DelaunayHello, polygon-clippingseedrandom, minimalWalk on Spheres 2Walk on SpheresHello, AutoencoderKaprekar’s numberVoronoiMap2D
Hello, ccwt.js
Polygon TriangulationQuantile.invert?Linear congruential generatorHue blurNeedle in a haystackMoving average blurApollo 11 implementation of trigonometric functions, by Margaret H. Hamilton (march 1969)2D curves intersectionThe 2D approximate Newton-Raphson methodInverting Lee’s Tetrahedral projectionLinde–Buzo–Gray stipplingMean shift clustering with kd-tree2D point distributionsShortest pathKahan SummationHello, delatinDijkstra’s algorithm in gpu.jsLloyd’s relaxation on a graphManhattan DiameterManhattan VoronoiMobility landscapes — an introductionDijkstra’s shortest-path treeH3 odditiesProtein MatrixConvex Spectral WeightsSort stuff by similarityKrigingDelaunay.findTrianglen-dimensions binning?Travelling with a self-organizing mapUMAP-o-MaticMNIST & UMAP-jsHello UMAP-jsMean shift clusteringLevenshtein transitionRd quasi-random sequencesAutomated label placement (countries)Phyllotaxis explainedMotionrugsPlanar hull (Andrew’s monotone chain algorithm)South Africa’s medial axisTravelling salesperson approximation with t-SNEDistance to shoreWorkerngraph: pagerank, louvain…t-SNE VoronoiCloud ContoursCircular function drawingKruskal MazeMyceliumTravelling salesperson approximation on the globe, with t-SNEtsne.jstsne.js & worker
Also listed in…
Hello
Insert cell
Insert cell
Insert cell
Insert cell
async function visual(sound) {
const audio_context = new window.AudioContext({ sampleRate: 44100 }),
audio_buffer = await new Promise((resolve) =>
sound.arrayBuffer().then((d) => audio_context.decodeAudioData(d, resolve))
);

const pcmf32_buffer = audio_buffer.getChannelData(0);

const length_in_seconds = pcmf32_buffer.length / audio_context.sampleRate;

const minimum_frequency = 16.34 * length_in_seconds;
const maximum_frequency = 20000.0 * length_in_seconds;
const deviation = 1.0;

const height = 500;

// linear
const frequency_basis_linear = 0;
const frequency_range_linear = maximum_frequency - minimum_frequency;
const frequency_offset_linear = minimum_frequency;

// logarithmic
const frequency_basis_log = 2.0; // each octave double the frequency
const minimum_octave =
Math.log(minimum_frequency) / Math.log(frequency_basis_log);
const maximum_octave =
Math.log(maximum_frequency) / Math.log(frequency_basis_log);

const frequency_range_log = maximum_octave - minimum_octave;
const frequency_offset_log = minimum_octave;

// linear
//CCWT.frequencyBand(frequencies, height, frequency_range_linear, frequency_offset_linear, frequency_basis_linear, deviation)

// logarithmic
const frequencies = CCWT.frequencyBand(
height,
frequency_range_log,
frequency_offset_log,
frequency_basis_log,
deviation
);

// add some padding to avoid start / end oddities (when there is data at one/both end of the signal)
const padding = 1; // suggested by @mootari
const gain_factor = 30;
const fourier_transformed_signal = CCWT.fft1d(
pcmf32_buffer,
padding,
gain_factor
);

const pixels_per_second = 60;
const output_width = Math.floor(length_in_seconds * pixels_per_second);

let percent_complete = 0;

const width = output_width;
const canvas_ctx = DOM.context2d(width, height, 1);
canvas_ctx.fillStyle = "#000000";
canvas_ctx.fillRect(0, 0, width, height);

const row_callback = function (y, row_data, output_padding) {
const spectrogram = canvas_ctx.createImageData(output_width, 1);
const spectro_data = spectrogram.data;

const percent_complete_new = Math.round((y / height) * 100);
if (percent_complete_new != percent_complete) {
console.log(percent_complete_new + "%");
percent_complete = percent_complete_new;
}

let x = 0;
for (x = 0; x < output_width; ++x) {
const r = row_data[output_padding * 2 + x * 2];
const i = row_data[output_padding * 2 + x * 2 + 1];

const amplitude_raw = Math.hypot(r, i);

// logarithmic intensity (sharpen edges / invert result when < 1)
/*
const logarithmic_basis = 1
const log_factor = 1.0 / Math.log(logarithmic_basis);
const value_sign = (0 < amplitude_raw) - (amplitude_raw < 0)
const amplitude = Math.min(Math.max(Math.log(amplitude_raw * value_sign) * log_factor, 0.), 1.) * value_sign
*/

// linear intensity
const value_sign = (0 < amplitude_raw) - (amplitude_raw < 0);
const amplitude = Math.min(amplitude_raw * value_sign, 1.0) * value_sign;

const rgb = d3.rgb(color(amplitude));

const index = x * 4;
spectro_data[index] = rgb.r;
spectro_data[index + 1] = rgb.g;
spectro_data[index + 2] = rgb.b;
spectro_data[index + 3] = 255;
}

canvas_ctx.putImageData(spectrogram, 0, y);
};

CCWT.numericOutput(
fourier_transformed_signal,
padding,
frequencies,
0,
frequencies.length / 2,
output_width,
row_callback
);

return canvas_ctx.canvas;
}
Insert cell
CCWT = {
const fetch = window.fetch;
invalidation.then(() => window.fetch = fetch);
window.fetch = function(url) {
return url === "FFTW.wasm"
? FileAttachment("FFTW.wasm").blob().then(_ => new Response(_))
: fetch.apply(window, arguments);
};
const ccwt = await require("ccwt.js@1.0.4/demo/dist/ccwt.js");
return new Promise(resolve => {
ccwt.onReady = () => {
window.fetch = fetch;
resolve(ccwt);
}
});
}
Insert cell
sound1 = FileAttachment("Nouvel enregistrement.m4a")
Insert cell
sound2 = FileAttachment("female_french_numbers_1_10.wav")
Insert cell
d3 = require("d3-color@3", "d3-scale-chromatic@3")
Insert cell
color = d3.interpolateTurbo
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more