dsp.FIRRateConverter

Sample rate converter

Description

The dsp.FIRRateConverter System object™ performs sampling rate conversion by a rational factor on a vector or matrix input. The FIR rate convertor cascades an interpolator with a decimator. The interpolator upsamples the input by the upsampling factor, L, followed by a lowpass FIR filter. The FIR filter acts both as an anti-imaging filter and an anti-aliasing filter prior to decimation. The decimator downsamples the output of upsampling and FIR filtering by the downsampling factor M. You must use upsampling and downsampling factors that are relatively prime, or coprime. The resulting discrete-time signal has a sampling rate L/M times the original sampling rate.

To perform sampling rate conversion:

  1. Create the dsp.FIRRateConverter object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?.

Creation

Description

example

firrc = dsp.FIRRateConverter returns a FIR sample rate converter, firrc, that resamples an input signal at a rate 3/2 times the original sampling rate.

example

firrc = dsp.FIRRateConverter(L,M,NUM) returns an FIR sample rate converter, firrc, with the InterpolationFactor property set to L, the DecimationFactor property set to M, and the Numerator property set to NUM.

firrc = dsp.FIRRateConverter(___,Name,Value) returns an FIR sample rate converter, with additional properties specified by one or more Name,Value pair arguments.

Example: firrc = dsp.FIRRateConverter('FullPrecisionOverride','false') enables the fixed-point data types to be controlled through the individual fixed-point property settings.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Interpolation factor, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Decimation factor, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the FIR filter coefficients in powers of z-1. The length of filter coefficients must exceed the interpolation factor. Use a lowpass with normalized cutoff frequency no greater than min(1/InterpolationFactor, 1/DecimationFactor). All initial filter states are zero.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Fixed-Point Properties

Specify whether to use full precision rules. If you set FullPrecisionOverride to true, which is the default, the object computes all internal arithmetic and output data types using full precision rules. These rules provide the most accurate fixed-point numerics. It also turns off the display of other fixed-point properties because they do not apply individually. These rules guarantee that no quantization occurs within the object. Bits are added, as needed, to ensure that no roundoff or overflow occurs. If you set FullPrecisionOverride to false, fixed-point data types are controlled through individual fixed-point property settings. For more information, see Full Precision for Fixed-Point System Objects.

Specify the rounding method as one of | Ceiling | Convergent | Floor | Nearest | Round | Simplest | Zero |.

Dependencies

This property applies only if the object is not in full precision mode.

Specify the overflow action as one of | Wrap | Saturate |.

Dependencies

This property applies only if the object is not in full precision mode.

Specify the filter coefficient fixed-point data type as one of | Same word length as input | Custom |.

Specify the filter coefficient fixed-point type as a numerictype (Fixed-Point Designer) object with a Signedness of Auto.

Dependencies

This property applies only when the CoefficientsDataType property is Custom.

Specify the product fixed-point data type as one of | Full precision | Same as input | Custom |.

Specify the product fixed-point type as a scaled numerictype (Fixed-Point Designer) object with a Signedness of Auto.

Dependencies

This property applies only when the ProductDataType property is Custom.

Specify the accumulator fixed-point data type as one of | Full precision | Same as product | Same as input | Custom |.

Specify the accumulator fixed-point type as a scaled numerictype (Fixed-Point Designer) object with a Signedness of Auto.

Dependencies

This property applies only when the AccumulatorDataType property is Custom.

Specify the output fixed-point data type as one of | Same as accumulator | Same as product | Same as input | Custom |.

Specify the output fixed-point type as a scaled numerictype (Fixed-Point Designer) object with a Signedness of Auto.

Dependencies

This property applies only when the OutputDataType property is Custom.

Usage

Description

example

y = firrc(x) resamples the input x and returns the resampled signal y.

Input Arguments

expand all

Data input, specified as a column vector or a matrix. The number of input rows must be a multiple of the decimation factor. An M-by-N matrix input is treated as N independent channels.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Output Arguments

expand all

Resampled output, returned as a column vector or a matrix. The number of rows in the output signal is given by MI/D, where M is the number of input rows, I is the interpolation factor, and D is the decimation factor.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

freqzFrequency response of discrete-time filter System object
fvtoolVisualize frequency response of DSP filters
infoInformation about filter System object
costEstimate cost of implementing filter System object
coeffsReturns the filter System object coefficients in a structure
polyphasePolyphase decomposition of multirate filter
generatehdlGenerate HDL code for quantized DSP filter (requires Filter Design HDL Coder)
stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

This example shows how to resample a 100 Hz sine wave signal by a factor of 3:2.

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).

sine = dsp.SineWave(1, 100,'SampleRate', 5000,'SamplesPerFrame', 50);

Create a FIR rate converter filter. The default interpolation factor is 3 and decimation factor is 2.

firrc = dsp.FIRRateConverter; 
input = sine();
output = firrc(input);

Plot the original and resampled signals.

ndelay = round(length(firrc.Numerator)/2/firrc.DecimationFactor);
indx = ndelay+1:length(output);
x = (0:length(indx)-1)/sine.SampleRate*firrc.DecimationFactor/firrc.InterpolationFactor;
stem((0:38)/sine.SampleRate, input(1:39)); hold on;
stem(x, firrc.InterpolationFactor*output(indx),'r');
legend('Original','Resampled');

Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes step(obj,x).

Note: The audioDeviceWriter System object™ is not supported in MATLAB Online.

This example shows how to resample and play an audio signal from 48 kHz to 32 kHz on a Windows® platform.

afr = dsp.AudioFileReader('audio48kHz.wav', ...
    'OutputDataType', 'single', ...
    'SamplesPerFrame', 300);
adw = audioDeviceWriter(32000);

Create an FIRRateConverter System object with interpolation factor = 2, decimation factor = 3. Default FIR filter coefficients define a lowpass filter with normalized cutoff frequency of 1/3.

firrc = dsp.FIRRateConverter(2,3);

while ~isDone(afr)
    audio1 = afr();
    audio2 = firrc(audio1);
    adw(audio2);
end

release(afr);
release(adw);

Algorithms

This object implements the algorithm, inputs, and outputs described on the FIR Rate Conversion block reference page. The object properties correspond to the block parameters.

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced in R2012a