Documentation Center |
FIR filter-based interpolator
Hm = mfilt.firinterp(L)
Hm = mfilt.firinterp(L,num)
Hm = mfilt.firinterp(L) returns a FIR polyphase interpolator object Hm with an interpolation factor of L and gain equal to L. L defaults to 2 if unspecified.
Hm = mfilt.firinterp(L,num) uses the values in the vector num as the coefficients of the interpolation filter.
Make this filter a fixed-point or single-precision filter by changing the value of the Arithmetic property for the filter Hm as follows:
To change to single-precision filtering, enter
set(hm,'arithmetic','single');
To change to fixed-point filtering, enter
set(hm,'arithmetic','fixed');
The following table describes the input arguments for creating hm.
Input Argument | Description |
---|---|
l | Interpolation factor for the filter. l specifies the amount to increase the input sampling rate. It must be an integer. When you do not specify a value for l it defaults to 2. |
num | Vector containing the coefficients of the FIR lowpass filter used for interpolation. When num is not provided as an input, firinterp uses a lowpass Nyquist filter with gain equal to l and cutoff frequency equal to π/l by default. The default length for the Nyquist filter is 24*l. Therefore, each polyphase filter component has length 24. |
This section describes the properties for both floating-point filters (double-precision and single-precision) and fixed-point filters.
Every multirate filter object has properties that govern the way it behaves when you use it. Note that many of the properties are also input arguments for creating mfilt.firinterp objects. The next table describes each property for an mfilt.firinterp filter object.
Name | Values | Description |
---|---|---|
Arithmetic | Double, single, fixed | Defines the arithmetic the filter uses. Gives you the options double, single, and fixed. In short, this property defines the operation mode for your filter. |
FilterStructure | String | Reports the type of filter object. You cannot set this property — it is always read only and results from your choice of mfilt object. Describes the signal flow for the filter object. |
InterpolationFactor | Integer | Interpolation factor for the filter. l specifies the amount to increase the sampling rate of the input signal. It must be an integer. |
Numerator | Vector | Vector containing the coefficients of the FIR lowpass filter used for decimation. |
PersistentMemory | [false], true | Determines whether the filter states get restored to zeros for each filtering operation. The starting values are the values in place when you create the filter if you have not changed the filter since you constructed it. PersistentMemory set to false returns filter states to the default values after filtering. States that the filter does not change are not affected. Setting this to true allows you to modify the States property. |
States | Double, single, matching the filter arithmetic setting. | Contains the filter states before, during, and after filter operations. States act as filter memory between filtering runs or sessions. |
This table shows the properties associated with the fixed-point implementation of the mfilt.firinterp filter.
Note The table lists all of the properties that a fixed-point filter can have. Many of the properties listed are dynamic, meaning they exist only in response to the settings of other properties. To view all of the characteristics for a filter at any time, use info(hm) where hm is a filter. |
For further information about the properties of this filter or any mfilt object, refer to Multirate Filter Properties.
Name | Values | Description |
---|---|---|
AccumFracLength | Any positive or negative integer number of bits. [32] | Specifies the fraction length used to interpret data output by the accumulator. This is a property of FIR filters and lattice filters. IIR filters have two similar properties — DenAccumFracLength and NumAccumFracLength — that let you set the precision for numerator and denominator operations separately. |
AccumWordLength | Any integer number of bits[39] | Sets the word length used to store data in the accumulator. |
Arithmetic | fixed for fixed-point filters | Setting this to fixed allows you to modify other filter properties to customize your fixed-point filter. |
CoeffAutoScale | [true], false | Specifies whether the filter automatically chooses the proper fraction length to represent filter coefficients without overflowing. Turning this off by setting the value to false enables you to change the NumFracLength property value to specify the precision used. |
CoeffWordLength | Any integer number of bits [16] | Specifies the word length to apply to filter coefficients. |
FilterInternals | [FullPrecision], SpecifyPrecision | Controls whether the filter automatically sets the output word and fraction lengths, product word and fraction lengths, and the accumulator word and fraction lengths to maintain the best precision results during filtering. The default value, FullPrecision, sets automatic word and fraction length determination by the filter. SpecifyPrecision makes the output and accumulator-related properties available so you can set your own word and fraction lengths for them. |
InputFracLength | Any positive or negative integer number of bits [15] | Specifies the fraction length the filter uses to interpret input data. |
InputWordLength | Any integer number of bits [16] | Specifies the word length applied to interpret input data. |
NumFracLength | Any positive or negative integer number of bits [14] | Sets the fraction length used to interpret the numerator coefficients. |
OutputFracLength | Any positive or negative integer number of bits [32] | Determines how the filter interprets the filter output data. You can change the value of OutputFracLength when you set FilterInternals to SpecifyPrecision. |
OutputWordLength | Any integer number of bits [39] | Determines the word length used for the output data. You make this property editable by setting FilterInternals to SpecifyPrecision. |
OverflowMode | saturate, [wrap] | Sets the mode used to respond to overflow conditions in fixed-point arithmetic. Choose from either saturate (limit the output to the largest positive or negative representable value) or wrap (set overflowing values to the nearest representable value using modular arithmetic.) The choice you make affects only the accumulator and output arithmetic. Coefficient and input arithmetic always saturates. Finally, products never overflow — they maintain full precision. |
RoundMode | [convergent], ceil, fix, floor, nearest, round | Sets the mode the filter uses to quantize numeric values when the values lie between representable values for the data format (word and fraction lengths).
The choice you make affects only the accumulator and output arithmetic. Coefficient and input arithmetic always round. Finally, products never overflow — they maintain full precision. |
Signed | [true], false | Specifies whether the filter uses signed or unsigned fixed-point coefficients. Only coefficients reflect this property setting. |
States | fi object to match the filter arithmetic setting. | Contains the filter states before, during, and after filter operations. States act as filter memory between filtering runs or sessions. The states use fi objects, with the associated properties from those objects. For details, refer to fixed-point objects in Fixed-Point Designer™ documentation. |
To provide interpolation, mfilt.firinterp uses the following structure.
The following figure details the signal flow for the direct form FIR filter implemented by mfilt.firinterp. In the figure, the delay line updates happen at the lower input rate. The remainder of the filter — the sums and coefficients — operate at the higher output rate.
This example uses mfilt.firinterp to double the sample rate of a 22.05 kHz input signal. The output signal ends up at 44.1 kHz. Although l is set explicitly to 2, this represents the default interpolation value for mfilt.firinterp objects.
L = 2; % Interpolation factor. Hm = mfilt.firinterp(L); % Use the default filter. fs = 22.05e3; % Original sample freq: 22.05 kHz. n = 0:5119; % 5120 samples, 0.232s long signal. x = sin(2*pi*1e3/fs*n); % Original signal, sinusoid at 1 kHz. y = filter(Hm,x); % 10240 samples, still 0.232s. stem(n(1:22)/fs,x(1:22),'filled') % Plot original sampled at % 22.05 kHz. hold on; % Plot interpolated signal (44.1 kHz) in red stem(n(1:44)/(fs*L),y(25:68),'r') xlabel('Time (sec)');ylabel('Signal Value') legend('Original Signal','Interpolated Signal');
With interpolation by 2, the resulting signal perfectly matches the original, but with twice as many samples — one between each original sample, as shown in the following figure.
mfilt.cicinterp | mfilt.fftfirinterp | mfilt.firsrc | mfilt.holdinterp | mfilt.linearinterp