Skip to content

Signal analysis API

Import from nmrlink. All functions are synchronous and preserve the input samples. See analysis specifications for mathematical conventions.

analyzeMeasurement(record, options)

Runs baseline correction, complex FFT and peak selection across all frequencies, using record.raw and record.sampleIntervalMs.

OptionDefaultMeaning
startMs / endMs1 / 5FFT interval [ms], start included and end excluded
tailPoints100Tail sample count used for the baseline
truncatetrueTruncate corrected values toward zero
windowhannhann / rect
js
const { data, baseline, spectrum, peak } = analyzeMeasurement(record, {
  startMs: 1, endMs: 5, tailPoints: 100, truncate: true, window: "hann",
});

data is the corrected array; baseline is the correctBaseline result; spectrum is the computeSpectrum result; peak is the bin with the largest amplitude. Ties select the first bin in ascending frequency order. Zero input still returns a bin with amplitude:0. Display limits do not restrict peak selection.

correctBaseline(raw, options)

raw is an array of finite numeric pairs. Defaults are tailPoints=100 and truncate=true. tailPoints must be an integer from 1 to raw.length; truncate must be boolean.

Returns { base, data, tailPoints, truncate }. base contains the channel tail means; data is a new corrected array. Input length is not restricted to 2048. Incomplete pairs, non-finite numbers, invalid sample counts and arithmetic overflow throw.

computeSpectrum(data, options)

OptionDefaultMeaning
sampleIntervalMsRequiredPositive finite sample interval [ms]
startMs0Start time [ms], included
endMsdata.length × sampleIntervalMsEnd time [ms], excluded
windowhannhann: symmetric Hann; rect: rectangular

data is the corrected two-channel array; this function does not correct the baseline itself. At least four selected samples are required. Samples are padded to the next power of two, up to 2202^{20} FFT points. Invalid ranges, windows or non-finite values throw.

Result fieldMeaning
binsAll bins in ascending frequency order; each has hz, real, imaginary, amplitude, phaseRadians
startMs / endMsRequested interval
first / lastStart / exclusive end sample indexes
actualStartMs / actualEndExclusiveMsActual selected time interval [ms]
count / sizeSelected sample count / padded FFT size
durationMscount × sampleIntervalMs
spacingHz / resolutionHzBin spacing / observation-time 1/T1/T estimate
window / conventionWindow name / Data 1 + i Data 2

hz is the receiver-relative offset in Hz; phaseRadians uses the start of the selected interval as its time origin. amplitude is the magnitude of the complex component normalized by the sum of window weights.

Guide: Analyze signals · API index