Skip to content

Analyze signals

Apply baseline correction and a complex FFT to examine frequency, amplitude, and phase. Analysis does not modify the original record.raw.

On this page

Try a simulated FID

The preview starts with noise. Switch to Ideal signal to compare the two. Change the time range or window and click Reanalyze; no hardware connection or new measurement is involved.

Simulated FID analysis

Preparing the preview…

FID / time-domain signal

FFT / amplitude spectrum

Both use the same simulated FID and constant offset; the noisy version adds a fixed noise sequence. Reanalysis and page reloads do not change the noise. Compare the corrected waveform and highlighted FFT interval. Invalid settings keep the previous graphs.

Correct the baseline and run the FFT

record is a measurement record received through controller.onResult or another acquisition method. Use this import for static HTML; for npm, change the path to nmrlink.

js
import { analyzeMeasurement } from "./nmrlink/index.js";

const analysis = analyzeMeasurement(record, {
  startMs: 1,
  endMs: 5,
  tailPoints: 100,
  window: "hann",
});

console.log(analysis.data);          // Corrected two-channel signal
console.log(analysis.baseline.base); // Tail mean for each channel
console.log(analysis.spectrum.bins); // Frequency, complex values, amplitude, phase
console.log(analysis.peak);          // Maximum peak across all frequencies

analyzeMeasurement(record) uses these settings by default.

Choose analysis settings

OptionDefaultMeaning
startMs1FFT start time [ms], inclusive.
endMs5FFT end time [ms], exclusive.
tailPoints100Number of final samples used for the baseline mean.
windowhannhann: Hann window; rect: rectangular window.
truncatetrueTruncate corrected values toward zero. Use false to keep fractional values.

The FFT range must lie within the acquisition, end after it starts, and contain at least four samples. A typical 2048-point record sampled every 0.02 ms covers 0–40.96 ms, excluding the endpoint.

If the beginning contains a large transient, inspect the FID and consider starting later. If the tail still contains signal, that signal contributes to the baseline estimate.

The FFT time range is separate from the displayed FID time range and the displayed spectrum frequency range.

Read peaks and frequencies

js
const { peak, spectrum } = analysis;
console.log(peak.hz);             // Offset from the receive frequency [Hz]
console.log(peak.amplitude);      // Amplitude [arbitrary units]
console.log(peak.phaseRadians);   // Phase [rad]
console.log(spectrum.count);      // Selected sample count
console.log(spectrum.size);       // FFT size after zero-padding
console.log(spectrum.resolutionHz); // Resolution estimate from observation time
console.log(spectrum.spacingHz);  // Frequency-bin spacing

The two channels form Data 1 + i Data 2, so the spectrum contains negative and positive frequencies. peak.hz is a receiver-relative offset, not the configured frequency itself.

The maximum peak is selected from all FFT bins without interpolation. It may lie outside the displayed frequency range. Phase is referenced to the start of the selected time range; do not interpret phase at near-zero amplitudes.

Zero-padding makes frequency bins more closely spaced, but does not improve the resolution set by the observation time.

Reanalyze the same record

js
const record = controller.result;
if (record) {
  const analysis = analyzeMeasurement(record, {
    startMs: 2, endMs: 6, window: "rect",
  });
  graphs.show(record, analysis);
}

graphs is the NMRGraphs view from Build your first Web UI. This code sends no measurement commands. The same analysis functions also work on saved records.

Use correction and FFT separately

js
import { correctBaseline, computeSpectrum } from "./nmrlink/index.js";

const corrected = correctBaseline(record.raw, {
  tailPoints: 100, truncate: false,
});
const spectrum = computeSpectrum(corrected.data, {
  sampleIntervalMs: record.sampleIntervalMs,
  startMs: 1, endMs: 5, window: "hann",
});

Use these functions when you need fractional corrected values or separate processing steps. On its own, computeSpectrum defaults to the entire input time range.

Invalid data and settings throw errors. Missing channel values and NaN are not replaced with zero. Use try / catch when your UI accepts editable inputs.

See Control measurements for acquisition, or Analysis specifications for FFT conventions and normalization details.

Next: Display graphs