Linear or FIR interpolation
The Interpolator object interpolates real-valued inputs using linear or polyphase FIR interpolation.
To interpolate real-valued inputs:
H = dsp.Interpolator returns a handle to an interpolation object, H. The interpolation method defaults to Linear and the interpolation points default to a 5×1 vector.
H = dsp.Interpolator('PropertyName',PropertyValue,...) returns an interpolation object, H, with the specified property name and value pairs.
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.
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.
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.
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.
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.
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.
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.
|clone||Create interpolator object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs of step method|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|step||Linear or FIR interpolation|
A polyphase implementation of an FIR interpolation filter splits the lowpass FIR filter impulse response into a number of different subfilters. Let L represent the number of interpolation points per sample, or the upsampling factor, and P the half length of the polyphase subfilters. Indexing from zero, if h(n) is the impulse response of the FIR filter, the k-th subfilter is:
The following table describes the decomposition of an 18-coefficient FIR filter into 3 polyphase subfilters of length 6, the defaults for the FIR interpolator object:
|h(0),h(3),h(6), ..., h(15)||h0(n)|
|h(1),h(4),h(7), ..., h(16)||h1(n)|
|h(2),h(5),h(8), ..., h(17)||h2(n)|
The following code shows how to find the polyphase subfilters for the default FIR interpolator object:
H = dsp.Interpolator('Method','FIR'); L = H.InterpolationPointsPerSample; P = H.FilterHalfLength; FiltCoeffs = intfilt(L,P,H.Bandwidth); % Returns filter of length 2*P*L-1 FiltLen=length(FiltCoeffs); FiltCols = ceil(FiltLen/2/L); % We need 2*P*L coefficients % Prepending a zero does not affect the filter magnitude FiltCoeffs = [zeros(FiltCols*2*L-FiltLen,1); FiltCoeffs(:)]; % Each column of PolyPhaseCoeffs is a polyphase subfilter PolyPhaseCoeffs = reshape(FiltCoeffs,FiltCols,2*L)';
Compare linear interpolation with FIR interpolation:
x =[1 4]; x = repmat(x,1,4); x1 = 1:0.25:8; hFIR =dsp.Interpolator('Method','FIR','FilterHalfLength',2,... 'InterpolationPoints',x1','InterpolationPointsPerSample',4); hLin =dsp.Interpolator('InterpolationPoints',x1'); OutFIR = step(hFIR,x'); OutLin = step(hLin,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.
Interpolate a sinusoid with linear interpolation:
t = 0:.0001:.0511; x = sin(2*pi*20*t); x1 = x(1:50:end); I = 1:0.1:length(x1); H = dsp.Interpolator('InterpolationPointsSource',... 'Input port'); y = H.step(x1',I'); stem(I',y, 'r'); title('Original and Interpolated Signal'); hold on; stem(x1, 'Linewidth', 2); legend('Interpolated','Original');
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); % Decimate without aliasing H = dsp.Interpolator('Method','FIR',... 'FilterHalfLength',3,'InterpolationPointsSource','Input Port'); y = H.step(x1',I'); stem(I,y,'r'); hold on; axis([0 25 -2 2]); stem(x1,'b','linewidth',2); legend('Interpolated Signal','Original',... 'Location','Northeast');
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.|