Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.FarrowRateConverter System object

Polynomial sample rate converter with arbitrary conversion factor

Description

The FarrowRateConverter System object™ implements an efficient polynomial-fit sample rate conversion filter using a Farrow structure. You can use this object to convert the sample rate of a signal up or down by an arbitrary factor. This object supports fixed-point operations.

To convert the sample rate of a signal:

  1. Define and set up your sample rate converter. See Construction.

  2. Call step to convert the sample rate according to the properties of dsp.FarrowRateConverter. 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

src = dsp.FarrowRateConverter creates a polynomial filter-based sample rate converter System object, src. For each channel of an input signal, src converts the input sample rate to the output sampling rate.

src = dsp.FarrowRateConverter(Name,Value) uses additional rate and filter properties, specified by one or more Name,Value pair arguments.

src = dsp.FarrowRateConverter(FSIN,FSOUT,TOL,NP) returns a sample rate converter object, src, with InputSampleRate property set to FSIN, OutputSampleRate property set to FSOUT, OutputRateTolerance property set to TOL, and PolynomialOrder property set to NP.

Properties

expand all

Sample rate of the input signal, specified as a positive scalar in Hz. The input sample rate must be greater than the bandwidth of interest. The default is 44.1 kHz.

Sample rate of the output signal, specified as a positive scalar in Hz. The output sample rate can be higher or lower than the input sample rate. The default is 48 kHz.

Maximum allowed tolerance for the sample rate of the output signal, specified as a positive scalar from 0 through 0.5, inclusive. The default is 0.

The actual output sample rate varies but is within the specified range. For example, if OutputRateTolerance is specified as 0.01, then the actual output sample rate is in the range given by OutputSampleRate ± 1%. This flexibility allows for a simpler filter design often.

Method used to specify the polynomial interpolator coefficients, specified as one of the following:

  • 'Polynomial order' — Specify the order of the Lagrange interpolation filter polynomial through the PolynomialOrder property.

  • 'Coefficients' — Specify the polynomial coefficients directly through the Coefficients property.

Order of the Lagrange interpolation filter polynomial, specified as a positive integer less than or equal to 4. The default is 3. This property applies only when you set Specification to 'Polynomial order'.

Filter polynomial coefficients, specified as a real-valued square matrix. The default is [-1 1; 1 0]. This property applies only when you set Specification to 'Coefficients'.

Here is the signal flow graph for farrow rate converter with coefficients set to [1 2; 3 4].

Each branch of the FIR filter corresponds to each row of the coefficients matrix.

Fixed-Point Properties

Rounding method, specified as a character vector. For more information on the rounding modes, see Precision and Range.

This property is not tunable.

Overflow action, specified as Wrap|Saturate. For more details on the overflow modes, see the 'Overflow Handling' section of Precision and Range.

This property is not tunable.

Data type of the filter coefficients, specified as a signed numerictype object. The default, numerictype(1,16) corresponds to a signed numeric type object with 16-bit coefficients. To give the best possible precision, the fraction length of this data type is determined based on the coefficient values.

This property is not tunable.

Data type of the fractional delay, specified as an unsigned numerictype object. The default, numerictype(0,8) corresponds to an unsigned fixed-point fractional delay data type object with 8-bit word length. To give the best possible precision, the fraction length of this data type is determined based on the fractional delay values.

This property is not tunable.

Data type of the multiplicand, specified as a signed numerictype object. The default, numerictype(1,16,13) corresponds to a signed fixed-point multiplicand data type with 16-bit word length and 13-bit fraction length.

This property is not tunable.

Data type of the output data type, specified as one of the following:

  • Same word length as input (default) — Output word length and fraction lengths are the same as the input.

  • Same as accumulator — Output word length and fraction lengths are the same as the accumulator.

  • numerictype(1,16) — Signed fixed-point output data type with 16-bit word length. To give the best possible precision, the fraction length is computed based on the input range. The dynamic range of the input is preserved.

  • numerictype(1,16,0) — Signed fixed-point output data type with 16-bit word length and zero fraction length.

This property is not tunable.

Fixed-Point Data Types

The signal flow diagram shows the data types used within the farrow rate converter for fixed-point signals and floating-point signals. You can specify these data types in the Farrow rate converter. If the input is floating point, all the data types with in the signal flow diagram have the same data type as the input, which can be single or double.

If the input is fixed point, the FIR filter uses the rounding mode, overflow mode, and the coefficients data type data you provide to the Farrow rate converter. The accumulator data type and the product data type in the signal flow are full precision.

Methods

costImplementation cost
freqzFrequency response
getActualOutputRateActual output rate, accounting for tolerance
getPolynomialCoefficientsPolynomial filter coefficients
getRateChangeFactorsOverall interpolation and decimation factors
infoFilter implementation details
resetReset internal states of polynomial sample rate converter
stepConvert sample rate of signal
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).

Create a Farrow rate converter object to convert an audio signal from 44.1 kHz to 96 kHz. Set the polynomial order for the Farrow filter.

fs1 = 44.1e3;
fs2 = 96e3;
LagrangeOrder = 2; % 1 = linear interpolation
frc = dsp.FarrowRateConverter('InputSampleRate',fs1,...
                              'OutputSampleRate',fs2,...
                              'PolynomialOrder',LagrangeOrder);
ar = dsp.AudioFileReader('guitar10min.ogg','SamplesPerFrame',14700);
aw = dsp.AudioFileWriter('guitar10min_96kHz.wav','SampleRate',fs2);

Check the resulting interpolation (L) and decimation (M) factors.

[L,M] = getRateChangeFactors(frc)
L = 320
M = 147

Display the polynomial the object uses to fit the input samples.

coeffs = getPolynomialCoefficients(frc)
coeffs = 

    0.5000   -0.5000         0
   -1.0000         0    1.0000
    0.5000    0.5000         0

Convert 100 frames of the audio signal. Write the result to a file.

for n = 1:1:100
   x = ar();  
   y = frc(x);
   aw(y);
end

Release the AudioFileWriter object to complete creation of the output file.

release(aw)
release(ar)

Plot the input and output signals of the 100th frame of data. Delay the input to compensate for the latency introduced by the filter.

t1 = 0:1/fs1:1/30-1/fs1;
t2 = 0:1/fs2:1/30-1/fs2;

delay = ceil((LagrangeOrder+1)/2)/fs1;
el1 = 1:length(t1)-delay;
el2 = 1:length(t2);
el2(1:delay) = [];

figure

subplot(2,1,1)
plot(t1(1:length(el1)),x(el1,1))
hold on
plot(t1(1:length(el1)),x(el1,2))
title('Input channels')

subplot(2,1,2)
plot(t2(1:length(el2)),y(el2,1))
hold on
plot(t2(1:length(el2)),y(el2,2))
xlabel('Time (s)')
title('Output channels')

Zoom in to see the difference in sample rates.

figure

subplot(2,1,1)
plot(t1(1:length(el1)),x(el1,1),'o-')
hold on
plot(t2(1:length(el2)),y(el2,1),'d--')
xlim([0.0104 0.0107])
title('First channel')
legend('Input','Output')

subplot(2,1,2)
plot(t1(1:length(el1)),x(el1,2),'o-')
hold on
plot(t2(1:length(el2)),y(el2,2),'d--')
xlim([0.0104 0.0107])
xlabel('Time (s)')
title('Second channel')
legend('Input','Output')

Create a Farrow rate converter with 0% tolerance. The output rate matches OutputSampleRate exactly. However, the input size must be a multiple of the decimation factor, M. In this case M is 320.

frc = dsp.FarrowRateConverter('InputSampleRate', 96e3,'OutputSampleRate',44.1e3);
FsOut = getActualOutputRate(frc)
[L,M] = getRateChangeFactors(frc)
FsOut =

       44100


L =

   147


M =

   320

Allow a 1% tolerance on the output rate and observe the difference in decimation factor. M is now only 13. The lower decimation factor allows more flexibility in input size. The output rate is within the range OutputSampleRate 1%.

frc.OutputRateTolerance = 0.01;
FsOut = getActualOutputRate(frc)
[Le,Me] = getRateChangeFactors(frc)
FsOut =

   4.4308e+04


Le =

     6


Me =

    13

References

Hentschel, T., and G. Fettweis. “Continuous-Time Digital Filters for Sample-Rate Conversion in Reconfigurable Radio Terminals.” Frequenz. Volume 55, Issue 5-6, 2001, pp. 185–188.

Algorithms

Farrow filters implement piecewise polynomial interpolation using Horner’s rule to compute samples from the polynomial. The polynomial coefficients used to fit the input samples correspond to the Lagrange interpolation coefficients.

Once a polynomial is fitted to the input data, the value of the polynomial can be calculated at any point. Therefore, a polynomial filter allows for interpolation at arbitrary locations between input samples.

You can use a polynomial of any order to fit to the existing samples. However, since large order polynomials oscillate a lot, polynomials of order 1, 2, 3, or 4 are used in practice.

The block computes interpolated values at the desired locations by varying only the fractional interval, µ. This interval is the distance between the previous input sample and the current output sample. All filter coefficients remain constant.

  • The input samples, x, are filtered using M + 1 FIR filters, where M is the polynomial order.

  • The outputs of these filters are multiplied by the fractional delay, µ.

  • The output, y, is the sum of the multiplication results.

Extended Capabilities

Introduced in R2014b

Was this topic helpful?