import type { DataXY } from 'cheminfo-types'; import type { SGGOptions } from 'ml-savitzky-golay-generalized'; import { sgg } from 'ml-savitzky-golay-generalized'; export interface FirstDerivativeFilter { name: 'firstDerivative'; options?: FirstDerivativeOptions; } export type FirstDerivativeOptions = Omit; /** * Calculate the first derivative using Savitzky–Golay filter. * @param data * @param options */ export function firstDerivative( data: DataXY, options: FirstDerivativeOptions = {}, ): { data: DataXY } { const { x, y } = data; return { data: { x, y: sgg(y, x, { ...options, derivative: 1 }) } }; }