# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# dsp.Interpolator System object

Package: dsp

Linear or FIR interpolation

## Description

The `Interpolator` object interpolates real-valued inputs using linear or polyphase FIR interpolation.

To interpolate real-valued inputs:

1. Define and set up your interpolation object. See Construction.

2. Call `step` to interpolate the input according to the properties of `dsp.Interpolator`. The behavior of `step` is specific to each object in the toolbox.

 Note:   Starting in R2016b, instead of using the `step` method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, ```y = step(obj,x)``` and `y = obj(x)` perform equivalent operations.

## Construction

`interp = dsp.Interpolator` returns a handle to an interpolation object, `interp`. The interpolation method defaults to `Linear` and the interpolation points default to a 5×1 vector.

`interp = dsp.Interpolator('PropertyName',PropertyValue,...)` returns an interpolation object, `interp`, with the specified property name and value pairs.

## Properties

 `InterpolationPointsSource` Source of interpolation points You can select a value of `Property` or `Input port`. If you set this property to `Input port`, you must provide the interpolation points as an input to the `step` method when you interpolate the input. The default is `Property`. `InterpolationPoints` Interpolation points This property only applies when you set the `InterpolationPointsSource` property to `Property`. Specify the interpolation points as a column vector or a matrix with the same number of channels as the input. The valid range of the values in the interpolation vector is from `1` to the number of samples in each channel of the input. If you specify interpolation points outside the valid range, the object clips the point to the nearest point in the valid range. For example, if the input is ```[2 3.1 -2.1]```, the valid range of interpolation points is from `1` to `3`. If you specify the following vector of interpolation points ```[-1 1.5 2 2.5 3 3.5]```, the interpolator object clips `-1` to `1` and `3.5` to `3`. This clipping results in the interpolation points ```[1 1.5 2 2.5 3 3]```. The default is `[1.1;4.8;2.67;1.6;3.2]`. This property is tunable. `Method` Interpolation method Specify the interpolation method as `Linear` or `FIR`. When this property is `Linear`, the interpolator object interpolates data values by assuming that the data varies linearly between adjacent samples. When this property is `FIR`, the interpolator object uses polyphase interpolation to replace filtering (convolution) at the upsampled rate with a series of convolutions at the lower rate. The interpolator object always performs linear interpolation if there are insufficient low-rate samples to perform FIR interpolation as explained in the description of the `FilterHalfLength` property. The default is `Linear`. `FilterHalfLength` Interpolation filter half length This property applies only when you set the `Method` property to `FIR`. For a filter half length of P, the polyphase FIR subfilters have length 2P. FIR interpolation always requires 2P low-rate samples for every interpolation point. If the interpolation point does not correspond to a low-rate sample, FIR interpolation requires P low-rate samples below and P low-rate samples above the interpolation point.If the interpolation point corresponds to a low-rate sample, the 2P-sample requirement includes the low-rate sample. If there are less than 2P neighboring low-rate samples, the interpolator object uses linear interpolation. For example, for an input `[1 4 1 4 1 4 1 4]`, upsampling by a factor of four results in the equally spaced interpolation points `InterP = 1:0.25:8;`. The points `InterP(9:12)` are ```[3.0 3.25 3.5 3.75]```. Assuming a `FilterHalfLength` property equal to 2, interpolating at these points uses the four low-rate samples from the input with indices `(2,3,4,5)`. If you set the `FilterHalfLength` property to 4 in this case, the interpolator object uses linear interpolation because there are not enough low-rate samples to perform FIR interpolation. The longer the `FilterHalfLength` property, the better the quality of the interpolation. However, the costs are increased computation and requiring more low-rate samples below and above the interpolation point. In general, setting the `FilterHalfLength` property between 4 and 6 provides reasonably accurate interpolation. `InterpolationPointsPerSample` Interpolation points per input sample This property only applies when you set the `Method` property to `FIR` and indicates the upsampling factor, L. An upsampling factor of L inserts L–1 zeros between low-rate samples. Interpolation results from filtering the upsampled sequence with a lowpass anti-imaging filter. The interpolator object uses a polyphase FIR implementation with `InterpolationPointsPerSample` subfilters of length 2P, where P is the `FilterHalfLength` property. Denoting the low-rate samples in the upsampled input by nL, n=1,2,..., the interpolator object uses exactly one of the `InterpolationPointsPerSample` subfilters, or filter arms, to interpolate at the points nL+i/L, where i=0,1,2,...,L-1. If you specify interpolation points which do not correspond to a polyphase subfilter, the object rounds the point down to the nearest interpolation point associated with a polyphase subfilter. For example, you set the `InterpolationPointsPerSample` property to `4` and interpolate at the points ```[3 3.2 3.4 3.6 3.8]```. The interpolator object uses the first polyphase subfilter for the points `[3.0 3.2]`, the second subfilter for the point `3.4`, the third subfilter for the point `3.6`, and the fourth subfilter for the point `3.8`. `Bandwidth` Normalized input bandwidth This property applies only when you set the `Method` property to `FIR`. The normalized bandwidth is a real-valued scalar between 0 and 1, where 1 equals the Nyquist frequency, or 1/2 the sampling frequency (Fs). You may know that your input does not have frequency content above some cutoff frequency less than the Nyquist frequency. You can use this information to improve the FIR interpolation filters by relaxing the stopband requirements in frequency regions where the signal has no energy. For example, if the input signal does not have frequency content above Fs/8, you can specify a value of `0.25` for the `Bandwidth` property. The default value is `0.5`.

## Methods

 step Linear or FIR interpolation
Common to All System Objects
`clone`

Create System object with same property values

`getNumInputs`

Expected number of inputs to a System object

`getNumOutputs`

Expected number of outputs of a System object

`isLocked`

Check locked states of a System object (logical)

`release`

Allow System object property value changes

## Examples

expand all

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

```x =[1 4]; x = repmat(x,1,4); x1 = 1:0.25:8; firInterp =dsp.Interpolator('Method','FIR','FilterHalfLength',2,... 'InterpolationPoints',x1','InterpolationPointsPerSample',4); linInterp = dsp.Interpolator('InterpolationPoints',x1'); OutFIR = firInterp(x'); OutLin = linInterp(x'); stem(OutFIR,'b-.','linewidth',2); hold on; stem(OutLin,'r','markerfacecolor',[1 0 0]); axis([0 30 0 5]); legend('FIR','Linear','Location','Northeast'); ```

For the indices 1 to 5 and 25 to 29, the interpolator object uses linear interpolation in both cases. The reason for this is that there are not enough low-rate samples surrounding the interpolation points at those indices to use FIR interpolation with the specified filter length.

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

```t = 0:.0001:.0511; x = sin(2*pi*20*t); x1 = x(1:50:end); I = 1:0.1:length(x1); interp = dsp.Interpolator('InterpolationPointsSource',... 'Input port'); y = interp(x1',I'); stem(I',y, 'r'); title('Original and Interpolated Signal'); hold on; stem(x1, 'Linewidth', 2); legend('Interpolated','Original'); ```

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent `step` syntax. For example, myObject(x) becomes step(myObject,x).

Interpolate a sum of sinusoids with FIR interpolation and `Input Port` as the source of interpolation points.

```Fs = 1000; t = 0:(1/Fs):0.1-(1/Fs); x = cos(2*pi*50*t)+0.5*sin(2*pi*100*t); x1 = x(1:4:end); I = 1:(1/4):length(x1); interp = dsp.Interpolator('Method','FIR',... 'FilterHalfLength',3,'InterpolationPointsSource','Input Port'); y = interp(x1',I'); stem(I,y,'r'); hold on; axis([0 25 -2 2]); stem(x1,'b','linewidth',2); legend('Interpolated Signal','Original',... 'Location','Northeast'); ```

expand all

## Algorithms

This object implements the algorithm, inputs, and outputs described on the Interpolation block reference page. The object properties correspond to the Simulink® block parameters, except:

 Out of range interpolation points — The interpolator object only has the `Clip` option. The Simulink block has the additional `Clip and warn` and `Error` options.