Multistage sample rate converter
the sample rate of an incoming signal.
To convert the sample rate of a signal:
Starting in R2016b, instead of using the
to perform the operation defined by the System
object, you can
call the object with arguments, as if it were a function. For example,
= step(obj,x) and
y = obj(x) perform
a multistage FIR sample rate converter System
src = dsp.SampleRateConverter
that converts the sample rate of each channel of an input signal.
a multistage FIR sample rate converter System
src = dsp.SampleRateConverter(
with properties and options specified by one or more
Bandwidth— Two-sided bandwidth of interest
Specify the two-sided bandwidth of interest (after rate conversion) as a positive scalar expressed in hertz. This property is the two-sided bandwidth of the information-carrying portion of the signal that you wish to retain. The default is 40 kHz.
InputSampleRate— Sample rate of input signal
Specify the sample rate of the input signal as a positive scalar expressed in hertz. The input sample rate must be greater than the bandwidth of interest. The default is 192 kHz.
OutputRateTolerance— Maximum allowed tolerance for output sample rate
Specify the maximum allowed tolerance for the sample rate of the output signal as a positive scalar between 0 and 1. The default is 0.
The output rate tolerance allows for a simpler design in many
cases. 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
OutputSampleRate ± 1%.
OutputSampleRate— Sample rate of output signal
Specify the sample rate of the output signal as a positive scalar expressed in hertz. The output sample rate must be greater than the bandwidth of interest. The default is 44.1 kHz.
StopbandAttenuation— Minimum dB attenuation for aliased components
Specify the stopband attenuation as a positive scalar expressed in decibels. This property is the minimum amount by which any aliasing involved in the process is attenuated. The default is 80 dB.
|cost||Compute implementation cost|
|getActualOutputRate||Get actual output rate|
|getFilters||Obtain single-stage filters|
|getRateChangeFactors||Overall interpolation and decimation factors|
|info||Display information about sample rate converter|
|reset||Reset internal states of multistage sample rate converter|
|step||Convert sample rate of signal|
|visualizeFilterStages||Visualize filter stages|
Convert the sample rate of an audio signal from 44.1 kHz (CD quality) to 96 kHz (DVD quality).
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).
fs1 = 44.1e3; fs2 = 96e3; SRC = dsp.SampleRateConverter('Bandwidth',40e3,... 'InputSampleRate',fs1,'OutputSampleRate',fs2); [L,M] = getRateChangeFactors(SRC); FrameSize = 10*M; AR = dsp.AudioFileReader('guitar10min.ogg', ... 'SamplesPerFrame',FrameSize); AW = dsp.AudioFileWriter('guitar10min_96k.wav', ... 'SampleRate',fs2);
Run the system for 15 s. Release all objects.
tic while toc < 15 x = AR(); y = SRC(x); AW(y); end release(AR); release(AW); release(SRC);
Plot the input and output signals. Use a different set of axes for each signal. Shift the output to compensate for the delay introduced by the filter.
t1 = 0:1/fs1:1/30-1/fs1; t2 = 0:1/fs2:1/30-1/fs2; delay = 114; el1 = 1:length(t1)-delay; el2 = 1:length(t2); el2(1:delay) = ; subplot(2,1,1) plot(t1(1:length(el1)),x(el1,1)) hold on plot(t1(1:length(el1)),x(el1,2)) title('Input') 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')
Zoom in to see the difference in sample rates. Use a different set of axes for each channel.
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.01 0.0103]) title('First channel') 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.01 0.0103]) xlabel('Time (s)') title('Second channel')
A signal output from an A/D converter is sampled at 98.304 MHz. The signal has a bandwidth of 20 MHz. Reduce the sample rate of the signal to 22 MHz, which is the bandwidth of 802.11 channels. Make the conversion exactly and then redo it with an output rate tolerance of 1%.
SRC1 = dsp.SampleRateConverter('Bandwidth',20e6, ... 'InputSampleRate',98.304e6,'OutputSampleRate',22e6, ... 'OutputRateTolerance',0); SRC2 = dsp.SampleRateConverter('Bandwidth',20e6, ... 'InputSampleRate',98.304e6,'OutputSampleRate',22e6, ... 'OutputRateTolerance',0.01);
cost method to determine the cost of each sample rate conversion. The zero-tolerance process requires more than 500 times as many coefficients as the 1% process.
c1 = cost(SRC1) c2 = cost(SRC2)
c1 = struct with fields: NumCoefficients: 84779 NumStates: 133 MultiplicationsPerInputSample: 27.0422 AdditionsPerInputSample: 26.0684 c2 = struct with fields: NumCoefficients: 150 NumStates: 127 MultiplicationsPerInputSample: 22.6667 AdditionsPerInputSample: 22.1111
Find the integer upsampling and downsampling factors used in each conversion.
[L1,M1] = getRateChangeFactors(SRC1) [L2,M2] = getRateChangeFactors(SRC2)
L1 = 1375 M1 = 6144 L2 = 2 M2 = 9
Compute the actual sample rate of the output signal when the sample rate conversion has a tolerance of 1%.
ans = 2.1845e+07
The general multistage sample rate converter performs a multistage decimation, a single-stage sample rate conversion, and a multistage interpolation, in that order. Actual designs include at most two of those steps.
The procedure determines automatically the optimal number of decimation or interpolation stages. In special cases, the decimation or the interpolation can be performed in a single stage.
The algorithm always attempts to start by reducing the sample rate. This decreases the amount of computation required. The decimation step is designed so that no intermediate sample rate goes below the bandwidth of interest. This ensures that no information is filtered out.
Each individual stage uses halfband or Nyquist filters to minimize the number of nonzero coefficients.
Transition-band aliasing is allowed because it decreases
the implementation cost. The signal within the bandwidth of interest
is kept alias free up to the value specified by the
Usage notes and limitations:
See System Objects in MATLAB Code Generation (MATLAB Coder).