You are looking at historical revision 20187 of this page. It may differ significantly from its current revision.

## interp1d

One-dimensional numerical interpolation.

## Usage

(require-extension interp1d)

## Documentation

The `interp1d` library provides routines for linear and piecewise quadratic interpolation, as well as a facility for "sliding window" interpolation over a long, or possibly infinite, sequence of data.

### Procedures

*[procedure]*

`interp1d:nearest:: XDATA * YDATA * X -> Y`

Interpolates function `y=f(x)` at the point `x` using the data point nearest to `x`. Arguments `XDATA` and `YDATA` are lists of numeric values that correspond to sample points of the function being interpolated. Argument `X` must be within the range of values contained in `XDATA`.

*[procedure]*

`interp1d:linear:: XDATA * YDATA * X -> Y`

Interpolates function `y=f(x)` at the point `x` using the linear interpolation method. Arguments `XDATA` and `YDATA` are lists of numeric values that correspond to sample points of the function being interpolated. Argument `X` must be within the range of values contained in `XDATA`.

*[procedure]*

`interp1d:piecewise-quadratic:: XDATA * YDATA * X -> Y`

Interpolates function `y=f(x)` at the point `x` using the piecewise quadratic interpolation method. Arguments `XDATA` and `YDATA` are lists of numeric values that corresponds to sample points of the function being interpolated. Argument `X` must be within the range of values contained in `XDATA`.

<procedure>interp1d:from-sequence:: METHOD * STEP * YDATA [* START * CAR * CDR * NULL? *

DELTA-WINDOW-LEN * MAX-WINDOW-LEN] -> (LAMBDA X -> Y)</procedure>

Constructs a sliding window interpolation procedure, for a given sequence `YDATA` that contains uniformly sampled values of a function `y = f(x)`, where `X` has an initial value of `START` (default 0) and is incremented by `STEP` amount. The returned procedure performs interpolation using the given `METHOD` procedure, while the window is shifted forwards by the appropriate amount if `X` is outside the current window range. Backward shifting is not supported.

Argument `METHOD` is one of the interpolation procedures above.

Optional argument `START` specifies the initial (smallest) `X` and defaults to 0.

Optional arguments `CAR`, `CDR`, `NULL?` are used to access `YDATA` and default to the standard list procedures. If the input sequence is not a list (e.g. an SRFI-40 stream), these arguments can be used to specify the appropriate accessors and predicates.

Optional arguments `DELTA-WINDOW-LEN` and `MAX-WINDOW-LEN` specify the window increment (default 4) and maximum window size (default 128).

*[procedure]*

`interp1d:lbound:: XDATA * YDATA * X -> Y`

Returns the value of the data point nearest to `X` that does not exceed the value of `X`.

*[procedure]*

`interp1d:ubound:: XDATA * YDATA * X -> Y`

Returns the value of the data point nearest to `X` that is larger than `X`.

## Examples

## About this egg

### Author

### Version history

- 1.11
- Documentation converted to wiki format
- 1.10
- Ported to Chicken 4
- 1.9
- Removed testeez as a dependency
- 1.8
- Added lbound and ubound routines
- 1.7
- Added nearest interpolation method
- 1.6
- Bug fix in bounds routine
- 1.5
- Bug fix in the sliding window routine for the case of non-list input data
- 1.4
- Added a proper error message routine
- 1.3
- Added a boundary exceeded error message to the sliding window routine
- 1.2
- Build script updated for better cross-platform compatibility
- 1.1
- Documentation updates
- 1.0
- Initial release

### License

Copyright 2007-2010 Ivan Raikov and the Okinawa Institute of Science and Technology This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. A full copy of the GPL license can be found at <http://www.gnu.org/licenses/>.