Files
templates/c/set-protocol/include/set_signal.h

31 lines
1.6 KiB
C

/** @file set_signal.h Portable interpolation and DAC waveform preparation. */
#ifndef SET_SIGNAL_H
#define SET_SIGNAL_H
#include "pcan_abi.h"
#ifdef __cplusplus
extern "C" {
#endif
enum { SET_SIGNAL_POLYNOMIAL, SET_SIGNAL_LINEAR, SET_SIGNAL_PCHIP, SET_SIGNAL_SPLINE };
/* Caller-owned workspace: at least 14*count+128 doubles. No heap or globals.
* Inputs may be unsorted; duplicate times are averaged. No extrapolation.
* meta[0..2] = original count, unique count, RMSE at original measurements.
* endpoint=1 includes the last time; 0 samples a cyclic period [first,last).
* On success, workspace blocks used by host formula annotations are:
* work[0..2*count): sorted original interleaved x,y pairs;
* work[2*count..3*count): unique x normalized to [0,1];
* work[3*count..4*count): unique averaged y divided by max(1,max(abs(y)));
* work[4*count..5*count): PCHIP first / spline second derivatives in these
* normalized coordinates (only meta[1] entries in each unique-data block).
* Return: 0 success, 1 bounds, 2 nonfinite/degenerate data, 3 rank deficient. */
PCAN_ABI_API int set_signal_reconstruct(const double *x, const double *y, size_t count,
int method, unsigned degree, size_t output_count, int endpoint,
double *out_x, double *out_y, double *meta, double *work, size_t work_count);
/* Reject out-of-range voltages, never silently clip. vref must be positive.
* All input is validated before any output is written. */
PCAN_ABI_API int set_signal_dac12(const double *volts, size_t count, double vref,
uint16_t *codes);
#ifdef __cplusplus
}
#endif
#endif