Public
Edited
Feb 20, 2023
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
signal = Array.from(
{ length: 2 ** 10 },
(_, i) =>
40 * Math.sin((i * Math.PI * 2) / freq2) +
70 * Math.sin((i * Math.PI * 2) / freq1)
)
Insert cell
fft = new FFT(signal.length)
Insert cell
fftOutput = {
const fftOutput = [];
fft.realTransform(fftOutput, signal);
fft.completeSpectrum(fftOutput);
return fftOutput;
}
Insert cell
frequencies = signal.map((v, i) => [
signal.length / (i || 1e-10),
(1 / signal.length) * Math.hypot(fftOutput[i * 2], fftOutput[i * 2 + 1])
])
Insert cell
signalReconstructed = {
const signalReconstructed = [];
fft.inverseTransform(signalReconstructed, fftOutput);

return signalReconstructed;
}
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