DSP Blockset
  Go to block:
    Search    Help Desk 

Rate Conversion

In a DSP Blockset model, there are two types of periods that you will commonly be concerned with: frame periods and sample periods. The sample periods of block inputs and outputs are related to their respective frame periods by

where the subscripts i and o indicate input and output, respectively.

The combined buffering and rate-conversion capabilities of the DSP Blockset generally allow you to independently vary any two of the three parameters (Tsi, Tfi, Mi). In most cases, the sample period and the frame size are the two parameters of primary interest; the frame period is decided by your choices for Tso and Mo.

There are two common types of operations that impact the frame and sample rates of a signal:

Both operations are discussed in the next sections, along with ways to avoid unintentional rate conversions.

Note
Technically, when a Simulink model contains signals with various frame periods (rates), the model is called multirate. You can find a discussion of multirate models in the "Discrete Time Systems" section in Chapter 9 of Using Simulink.

Direct Rate Conversion

Rate conversion blocks accept an input signal at one rate, and output the same signal at a new rate. Several of these blocks contain a Framing parameter offering two options for adjusting the rate of the signal:

The examples following the list of rate conversion blocks below illustrate both modes.

Rate Conversion Blocks.    The following table lists the principal rate conversion blocks in the DSP Blockset. Blocks marked with an asterisk (*) offer the option of changing the rate by either adjusting the frame size or frame rate.

Block
Library
Downsample *
Signal Operations, in General DSP
Dyadic Analysis Filter Bank
Multirate Filters, in Filtering
Dyadic Synthesis Filter Bank
Multirate Filters, in Filtering
FIR Decimation *
Multirate Filters, in Filtering
FIR Interpolation *
Multirate Filters, in Filtering
FIR Rate Conversion
Multirate Filters, in Filtering
Repeat *
Signal Operations, in General DSP
Upsample *
Signal Operations, in General DSP

Example: Rate Conversion by Frame-Rate Adjustment.    A common example of direct rate conversion is shown below, where the signal is directly downsampled to half its original rate. The values next to input and output ports are the line widths, displayed by selecting Vector Line Widths from the model window's Format menu.

The sample period and frame size of the original signal are set to 0.125 seconds and 8 samples per frame, respectively, by the Sample time and Samples per frame parameters in the Signal From Workspace block. This results in a frame period of 1 second (0.125*8), as shown by the first Probe block.

The Downsample block is configured to downsample the signal by changing the frame rate rather than the frame size. The dialog box with this setting is shown below.

The second Probe block in the model verifies that the output from the Downsample block has a frame period of 2, twice that of the input (half the rate). As a result, the sequence sample period is doubled to 0.25 seconds without any change to the frame size.

Example: Rate Conversion by Frame-Size Adjustment.    The same model is shown again below, but this time with the rate conversion implemented by adjusting the frame size, rather than the frame rate.

As before, the frame period of the original signal is 1 second (0.125*8), shown by the first Probe block. Now the Downsample block is configured to downsample the signal by changing the frame size rather than the frame rate. The dialog box with this setting is shown below.

The line width display on the Downsample output port verifies that the downsampled output has a frame size of 4, half that of the input. As a result, the sequence sample period is doubled to 0.25 seconds without any change to the frame rate.

Frame Rebuffering

Buffering operations are another common cause of rate changes in DSP models. The purpose of many buffering operations is to adjust the frame size of the signal without altering the sequence sample rate, in essence changing M while holding Ts fixed. Usually, this type of buffering operation results in a change to the signal's frame rate, Tf, according to the relation

discussed earlier.

However, this is only true when the original signal is preserved in the buffering operation, with no samples added or deleted. Buffering operations that generate overlapping frames, or that only partially unbuffer frames, alter the data sequence by adding or deleting samples. In this case the above relation is not valid.

The sections following the list of buffering blocks below discuss both buffering with preservation of the signal and buffering with alteration of the signal.

Buffering Blocks.    The following table lists the principle buffering blocks in the DSP Blockset.

Block
Library
Buffer
Buffers, in General DSP
Partial Unbuffer
Buffers, in General DSP
Rebuffer
Buffers, in General DSP
Shift Register
Buffers, in General DSP
Unbuffer
Buffers, in General DSP
Variable Selector
Elementary Functions, in Math Functions
Zero Pad
Signal Operations, in General DSP

Buffering with Preservation of the Signal.    There are various reasons that you may need to rebuffer a signal to a new frame size at some point in a model. For example, your data acquisition hardware may internally buffer the sampled signal to a frame size that is not optimal for the DSP algorithm in the model. In this case, you would want to rebuffer the signal to a frame size more appropriate for the intended operations, but without introducing any change to the data or sample rate.

There are three blocks in the Buffers library that can be used to change a signal's frame size without altering the signal itself:

Rebuffer is the most general of the three blocks, allowing conversions between any two frame sizes. Buffer is specialized for buffering scalar samples. Both Buffer and Rebuffer preserve the signal's data and sample period only when their Buffer overlap parameter is set to 0. The output frame periods, Tfo, of the two blocks are

Buffer block:

Rebuffer block:

where Tsi is the scalar input sample period to the Buffer block, Tfi is the input frame period to the Rebuffer block, Mi is the input frame size, and Mo is the output frame size, specified by the Buffer size parameter.

The Unbuffer block is specialized for unbuffering scalar samples, and always preserves the signal's data and sample period.

where Tfi and Mi are the period and size, respectively, of the frame-based input.

In all three cases listed above, the sample period of the sequence is preserved in the conversion (Tso = Tsi).

Example: Buffering with Preservation of the Signal.    In the model below, a signal with a sample period of 0.125 seconds is rebuffered from a frame size of 8 to a frame size of 16. This doubles the frame period from 1 to 2 seconds, but does not change the sample period of the signal (Tso = Tsi = 0.125).

Buffering with Alteration of the Signal.    Other forms of buffering alter the signal's data or sample period, in addition to adjusting the frame size. There are many instances when this type of buffering is desirable. Examples are creating sliding windows by overlapping consecutive frames of a signal, and selecting a subset of samples from each input frame for processing.

The blocks that alter a signal while adjusting its frame size are listed below. In this list, Tsi is the input sequence sample period, and Tfi and Tfo are the input and output frame periods, respectively.

In all of these cases, the sample period of the output sequence is not equal to the sample period of the input sequence.

Example: Buffering with Alteration of the Signal.    In the model below, a signal with a sample period of 0.125 seconds is rebuffered from a frame size of 8 to a frame size of 16 with an overlap of 4.

The relation for the output frame period,

indicates that Tfo should be (16-4)*0.125, or 1.5 seconds, which is confirmed by the second Probe block. The sample period of the signal at the output of the Rebuffer block is no longer 0.125 seconds, but rather 0.0938 seconds (1.5/16). Thus, both the signal's data and the signal's sample period have been altered by the rebuffering operation.

Avoiding Unintended Rate Conversions

The previous sections discussed a number of the blocks that are responsible for rate conversions. It is important to be aware of where in a model these rate conversions are taking place; in a few cases, unintentional rate conversions can produce misleading results. The model below provides an example.

The model plots the periodogram of a signal composed of two sine waves, with frequencies of 1 Hz and 3 Hz. Both Sine Wave blocks have the following parameter settings:

The Probe block confirms that the frame period is 12.8 seconds (128*0.1).

No Rate Conversion.    In the first case, the Short-Time FFT block uses the default settings for all parameters except for the FFT length, which is set to -1. This setting instructs the block to use the input frame size (128) as the FFT length (which is also the output size).

The plot generated by the Frequency Frame Scope is shown below. (The y-axis limits have been adjusted to better display the trace: Minimum Y-limit = -50 and Maximum Y-limit = 20).

The Frequency Frame Scope uses the input frame size (128) and period (12.8) to deduce the original signal's sample period (0.1), which allows it to correctly display the peaks at 1 Hz and 3 Hz.

Unintended Rate Conversion.    In the next case, the Short-Time FFT block uses the default settings for all parameters, including the FFT length setting of 256. This setting instructs the block to zero-pad the length-128 input frame to a length of 256 before performing the FFT. The line-width display on the new version of the model shows that the output of the Short-Time FFT block is now a length-256 frame.

The plot generated by the Frequency Frame Scope is shown below.

In this case, based on the input frame size (256) and period (12.8), the Frequency Frame Scope calculates the original signal's sample period to be 0.05 seconds (12.8/256), which is wrong. As a result, the spectral peaks appear at the incorrect frequencies, 2 Hz and 6 Hz rather than 1 Hz and 3 Hz.

The problem is that the zero-pad operation performed by the Short-Time FFT block halves the sample period of the sequence by appending 128 zeros to each frame. The Frequency Frame Scope, however, needs to know the sample period of the original signal. The problem is easily solved by changing the Sample time of original time series setting in the Frequency Frame Scope block from -1 (auto-detect) to the actual sample period of 0.1. The plot generated with this setting is identical to the first Frequency Frame Scope plot above.

In general, be aware that when you do zero-padding, overlapping buffering, or partial unbuffering, you are changing the sample period of the signal. As long as you keep this in mind, you should be able to anticipate and correct problems like the one above.



[ Previous | Help Desk | Next ]