Package: dsp
Sample rate converter
The FIRRateConverter
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 antiimaging
filter and an antialiasing 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 discretetime
signal has a sampling rate L/M times the original
sampling rate.
To perform sampling rate conversion:
Define and set up your FIR sample rate converter. See Construction.
Call step
to perform sampling rate
conversion according to the properties of dsp.FIRRateConverter
.
The behavior of step
is specific to each object in
the toolbox.
H = dsp.FIRRateConverter
returns
a FIR sample rate converter, H
, that resamples an
input signal at a rate 3/2 times the original sampling rate.
H = dsp.FIRRateConverter('
returns an FIR sample rate converter, PropertyName
',PropertyValue
,
...)H
,
with each property set to the specified value.
H = dsp.FIRRateConverter(L,M,NUM,'
returns an FIR sample rate converter, PropertyName
', PropertyValue
,
...)H
,
with the InterpolationFactor
property set to L
,
the DecimationFactor
property set to M
,
the Numerator
property set to NUM
,
and other specified properties set to the specified values.

Interpolation factor Specify the integer upsampling factor. The default is 

Decimation factor Specify the integer downsampling factor. The default is 

FIR filter coefficients 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 
clone  Create FIR sample rate convertor 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 
reset  Reset states of FIR sample rate converter 
step  Resample input with FIR rate converter 
Resample a 100 Hz sine wave signal by a factor of 3:2:
hsin = 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. hfirrc = dsp.FIRRateConverter; input = step(hsin); output = step(hfirrc, input); % Plot the original and resampled signals. ndelay = round(length(hfirrc.Numerator)/2/hfirrc.DecimationFactor); indx = ndelay+1:length(output); x = (0:length(indx)1)/hsin.SampleRate*hfirrc.DecimationFactor/hfirrc.InterpolationFactor; stem((0:38)/hsin.SampleRate, input(1:39)); hold on; stem(x, hfirrc.InterpolationFactor*output(indx),'r'); legend('Original','Resampled');
Resample and play an audio signal from 48 kHz to 32 kHz (Windows^{®} only):
hmfr = dsp.AudioFileReader('audio48kHz.wav', ... 'OutputDataType', 'single', ... 'SamplesPerFrame', 300); hap = dsp.AudioPlayer(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. hfirrc = dsp.FIRRateConverter(2,3); while ~isDone(hmfr) audio1 = step(hmfr); audio2 = step(hfirrc, audio1); step(hap, audio2); end release(hmfr); release(hap);
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.