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