| Contents | Index |
Communications System Toolbox software includes several functions that can help you design and use filters. Other filtering capabilities are in Signal Processing Toolbox software. The sections of this chapter are as follows.
For a demonstration involving raised cosine filters, type showdemo rcosdemo.
Without propagation delays, both Hilbert filters and raised cosine filters are noncausal. This means that the current output depends on the system's future input. In order to design only realizable filters, the hilbiir function delays the input signal before producing an output. This delay, known as the filter's group delay, is the time between the filter's initial response and its peak response. The group delay is defined as
![]()
where θ represents the phase of the filter and ω represents the frequency in radians. This delay is set so that the impulse response before time zero is negligible and can safely be ignored by the function.
For example, the Hilbert filter whose impulse is shown below uses a group delay of one second. In the figure, the impulse response near time 0 is small and the large impulse response values occur near time 1.

Filtering tasks that Communications System Toolbox supports using blocks include:
Filtering using a raised cosine filter. Raised cosine filters are very commonly used for pulse shaping and matched filtering. The following block diagram illustrates two typical uses of raised cosine filters.

Filtering using a Gaussian filter.
Shaping a signal using ideal rectangular pulses.
Implementing an integrate-and-dump operation or a windowed integrator. An integrate-and-dump operation is often used in a receiver model when the system's transmitter uses an ideal rectangular-pulse model. Integrate-and-dump can also be used in fiber optics and in spread-spectrum communication systems such as CDMA (code division multiple access) applications.
Additional filtering capabilities exist in the Filter Designs and Multirate Filters libraries of the DSP System Toolbox product.
For more background information about filters and pulse shaping, see the works listed in the Selected Bibliography for Communications Filters.
This example uses a pair of square root raised cosine filters to perform pulse shaping and matched filtering at the transmitter and receiver, respectively. This example implements cosine filters using the fdesign.pulseshaping function from the DSP System Toolbox product.
Setup the example by defining the size of signal constellation, number of bits per symbol, number of bits to process, and the oversampling rate by entering the following syntax at the MATLAB command line:
M = 16; k = log2(M); n = 3e4; nSamp = 4;
Create a 16-QAM modulator that accepts a bit input signal and uses Gray coded mapping.
hMod = modem.qammod(M); hMod.InputType = 'Bit'; hMod.SymbolOrder = 'Gray';
Create a 16-QAM demodulator.
hDemod = modem.qamdemod(hMod);
Design a square root raised cosine filter. Set the filter order to 40 and the roll-off factor to 0.25.
N = 40;
rolloff = 0.25;
filtDef = fdesign.pulseshaping(nSamp, 'Square Root Raised Cosine', ...
'N,Beta', N, rolloff);
rrcFilter = design(filtDef);
rrcFilter.Numerator = rrcFilter.Numerator * sqrt(nSamp);
Plot impulse response.
fvtool(rrcFilter, 'impulse')
The Filter Visualization Tool generates an image similar to the following:

Create a random binary data stream as a column vector.
x = randi([0 1],n,1);
Modulate the input data stream using the 16-QAM modulation technique.
y = modulate(hMod,x);
Upsample and filter the signal.
yUp = upsample(y, nSamp); yTx = filter(rrcFilter, yUp);
Create eye diagram for the filtered signal.
ploteye(yTx(N/2:2000), nSamp);
The Figure window opens.

Pass the signal through an AWGN channel. Use an EbNo value of 10 in your signal-to-noise calculations.
EbNo = 10; SNR = EbNo + 10*log10(k) - 10*log10(nSamp); yNoisy = awgn(yTx,SNR,'measured');
Downsample the received signal using a square root raised cosine filter to. Then, calculate the group delay.
yRx = filter(rrcFilter, yNoisy); yRx = downsample(yRx, nSamp); delay = N/(nSamp*2); yRx = yRx(2*delay+1:end-2*delay);
Create a scatter plot that illustrates the noisy signal and the ideal constellation points.
hScatter = commscope.ScatterPlot;
hScatter.Constellation = hMod.Constellation;
hScatter.SamplesPerSymbol = nSamp;
hScatter.PlotSettings.Constellation = 'on';
update(hScatter, yRx)
title('Received Signal');The Figure window opens, displaying the scatter plot.

Demodulate the input data stream using the 16-QAM modulation technique.
z = demodulate(hDemod,yRx);
Compare x and z to obtain the number of errors and then calculate the bit error rate.
[number_of_errors,bit_error_rate] = biterr(x(1:end-4*delay*k),z)
The raised cosine and Gaussian filter blocks in this library implement realizable filters by delaying the peak response. This delay, known as the filter's group delay, is the length of time between the filter's initial response and its peak response. The filter blocks in this library have a Group delay parameter that is an integer representing the number of symbol periods.
For example, the square root raised cosine filter whose impulse response shown in the following figure uses a Group delay parameter of 4 in the filter block. In the figure, the initial impulse response is small and the peak impulse response occurs at the fourth symbol.

A filter block's Group delay parameter value has implications for other parts of your model. For example, suppose you compare the symbol streams marked Symbols In and Symbols Out in the schematics in Filter Features by plotting or computing an error rate. Use one of these methods to make sure you are comparing symbols that truly correspond to each other:
Use the Delay block in DSP System Toolbox to delay the Symbols In signal, thus aligning it with the Symbols Out signal. Set the Delay parameter equal to the filter's Group delay parameter (or the sum of both values, if your model uses a pair of square root raised cosine filter blocks). The following figure illustrates this usage.

Use the Align Signals block to align the two signals.
When using the Error Rate Calculation block to compare the two signals, increase the Receive delay parameter by the Group delay parameter value (or the sum of both values, if your model uses a pair of square root raised cosine filter blocks). The Receive delay parameter might include other delays as well, depending on the contents of your model.
For more information about how to manage delays in a model, see Delays.
Comparing filtered with unfiltered data might be easier if you delay the unfiltered signal by the filter's group delay. For example, suppose you use the code below to filter x and produce y.
tx = 0:4; % Times for data samples x = [0 1 1 1 1]'; % Binary data samples % Filter the data and use a delay of 2 seconds. delay = 2; [y,ty] = rcosflt(x,1,8,'fir',.3,delay);
The elements of tx and ty represent the times of each sample of x and y, respectively. However, y is delayed relative to x, so corresponding elements of x and y do not have the same time values. Plotting y against ty and x against tx is less useful than plotting y against ty and x against a delayed version of tx.
% Top plot subplot(2,1,1), plot(tx,x,'*',ty,y); legend('Data','Filtered data'); title('Data with No Added Delay'); % Bottom plot delays tx. subplot(2,1,2), plot(tx+delay,x,'*',ty,y); legend('Data','Filtered data'); title('Data with an Added Delay');
For another example of compensating for group delay, see the raised cosine filter demo by typing showdemo rcosdemo.

The hilbiir function designs a Hilbert transform filter and produces either
A plot of the filter's impulse response
A quantitative characterization of the filter, using either a transfer function model or a state-space model
For example, typing
hilbiir
plots the impulse response of a fourth-order digital Hilbert transform filter having a one-second group delay. The sample time is 2/7 seconds. In this particular design, the tolerance index is 0.05. The plot also displays the impulse response of the ideal Hilbert transform filter having a one-second group delay. The plot is in the figure in Group Delay.
To compute this filter's transfer function, use the command below.
[num,den] = hilbiir
num =
-0.3183 -0.3041 -0.5160 -1.8453 3.3105
den =
1.0000 -0.4459 -0.1012 -0.0479 -0.0372
The vectors num and den contain the coefficients of the numerator and denominator, respectively, of the transfer function in ascending order of powers of z-1.
The commands in this section use the function's default parameters. You can also control the filter design by specifying the sample time, group delay, bandwidth, and tolerance index. The reference entry for hilbiir explains these parameters. The group delay is also mentioned in Group Delay.
The rcosflt function applies a raised cosine filter to data. Because rcosflt is a versatile function, you can
Use rcosflt to both design and implement the filter.
Specify a raised cosine filter and use rcosflt only to filter the data.
Design and implement either raised cosine filters or square-root raised cosine filters.
Specify the rolloff factor and/or group delay of the filter, if rcosflt designs the filter.
Design and implement either FIR or IIR filters.
This section discusses the use of sampling rates in filtering and then covers these options. For an additional example, type showdemo rcosdemo in the MATLAB Command Window.
The basic rcosflt syntax
y = rcosflt(x,Fd,Fs...) % Basic syntax
assumes by default that you want to apply the filter to a digital signal x whose sampling rate is Fd. The filter's sampling rate is Fs. The ratio of Fs to Fd must be an integer. By default, the function upsamples the input data by a factor of Fs/Fd before filtering. It upsamples by inserting Fs/Fd-1 zeros between consecutive input data samples. The upsampled data consists of Fs/Fd samples per symbol and has a sampling rate of Fs.
An example using this syntax is below. The output sampling rate is four times the input sampling rate.
y1 = rcosflt([1;0;0],1,4,'fir'); % Upsample by factor of 4/1.
Maintaining the Input Sampling Rate. You can also override the default upsampling behavior. In this case, the function assumes that the input signal already has a sampling rate of Fs and consists of Fs/Fd samples per symbol. You might want to maintain the sampling rate in a receiver's filter if the corresponding transmitter's filter has already upsampled sufficiently.
To maintain the sampling rate, modify the fourth input argument in rcosflt to include the string Fs. For example, in the first command below, rcosflt uses its default upsampling behavior and the output sampling rate is four times the input sampling rate. By contrast, the second command below uses Fs in the string argument and thus maintains the sampling rate throughout.
y1 = rcosflt([1;0;0],1,4,'fir'); % Upsample by factor of 4/1. y2 = rcosflt([1;0;0],1,4,'fir/Fs'); % Maintain sampling rate.
The second command assumes that the sampling rate of the input signal is 4, and that the input signal contains 4/1 samples per symbol.
An example that uses the 'Fs' option at the receiver is in Combining Two Square-Root Raised Cosine Filters.
The simplest syntax of rcosflt assumes that the function should both design and implement the raised cosine filter. For example, the command below designs an FIR raised cosine filter and then filters the input vector [1;0;0] with it. The second and third input arguments indicate that the function should upsample the data by a factor of 8 (that is, 8/1) during the filtering process.
y = rcosflt([1;0;0],1,8);
Types of Raised Cosine Filters. You can have rcosflt design other types of raised cosine filters by using a fourth input argument. Variations on the previous example are below.
y = rcosflt([1;0;0],1,8,'fir'); % Same as original example y = rcosflt([1;0;0],1,8,'fir/sqrt'); % FIR square-root RC filter y = rcosflt([1;0;0],1,8,'iir'); % IIR raised cosine filter y = rcosflt([1;0;0],1,8,'iir/sqrt'); % IIR square-root RC filter
If you have a transfer function for a raised cosine filter, then you can provide it as an input to rcosflt so that rcosflt does not design its own filter. This is useful if you want to use rcosine to design the filter once and then use the filter many times. For example, the rcosflt command below uses the 'filter' flag to indicate that the transfer function is an input argument. The input num is a vector that represents the FIR transfer function by listing its coefficients.
num = rcosine(1,8); y = rcosflt([1;0;0],1,8,'filter',num);This syntax for rcosflt works whether num represents the transfer function for a square-root raised cosine FIR filter or an ordinary raised cosine FIR filter. For example, the code below uses a square-root raised cosine FIR filter. Only the definition of num is different.
num = rcosine(1,8,'sqrt'); y = rcosflt([1;0;0],1,8,'filter',num);
You can also use a raised cosine IIR filter. To do this, modify the fourth input argument of the rcosflt command above so that it contains the string 'iir' and provide a denominator argument. An example is below.
delay = 8; [num,den] = rcosine(1,8,'iir',.5,delay); y = rcosflt([1;0;0],1,8,'iir/filter',num,den,delay);
If rcosflt designs the filter automatically, then you can control the rolloff factor of the filter, as described below. If you specify your own filter, then rcosflt does not need to know its rolloff factor.
The rolloff factor determines the excess bandwidth of the filter. For example, a rolloff factor of .5 means that the bandwidth of the filter is 1.5 times the input sampling frequency, Fd. This also means that the transition band of the filter extends from .5 * Fd to 1.5 * Fd.
The default rolloff factor is .5, but if you want to use a value of .2, then you can use a command such as the one below. Typical values for the rolloff factor are between .2 and .5.
y = rcosflt([1;0;0],1,8,'fir',.2); % Rolloff factor is .2.
If rcosflt designs the filter automatically, then you can control the group delay of the filter, as described below. If you specify your own FIR filter, then rcosflt does not need to know its group delay.
The filter's group delay is the time between the filter's initial response and its peak response. The default group delay in the implementation is three input samples. To specify a different value, measure it in input symbol periods and provide it as the sixth input argument. For example, the command below specifies a group delay of six input samples, which is equivalent to 6 *8 /1 output samples.
y = rcosflt([1;0;0],1,8,'fir',.2,6); % Delay is 6 input samples.
The group delay influences the size of the output, as well as the order of the filter if rcosflt designs the filter automatically. See the reference page for rcosflt for details that relate to the syntax you want to use.
Example: Raised Cosine Filter Delays. The code below filters a signal using two different group delays. A larger delay results in a smaller error in the frequency response of the filter. The plot shows how the two filtered signals differ, and the output pt indicates that the first peak occurs at different times for the two filtered signals. In the plot, the solid line corresponds to a delay of six samples, while the dashed line corresponds to a delay of eight samples.
[y,t] = rcosflt(ones(10,1),1,8,'fir',.5,6); % Delay = 6 samples [y1,t1] = rcosflt(ones(10,1),1,8,'fir',.5,8); % Delay = 8 samples plot(t,y,t1,y1,'--') % Two curves indicate the different delays. legend('Delay = 6 samples','Delay = 8 samples','Location','NorthOutside'); peak = t(find(y == max(y))); % Times where first curve peaks peak1 = t1(find(y1 == max(y1))); % Times where second curve peaks pt = [min(peak), min(peak1)] % First peak time for both curves
The output is below.
pt = 14.6250 16.6250
If Fs/Fd is at least 4, then a group delay value of at least 8 works well in many cases. In the examples of this section, Fs/Fd is 8.
Delays of Six Samples (Solid Line) and Eight Samples (Dashed Line)

If you want to split the filtering equally between the transmitter's filter and the receiver's filter, then you can use a pair of square-root raised cosine filters. In theory, the combination of two square-root raised cosine filters is equivalent to a single normal raised cosine filter. However, the limited impulse response of practical square-root raised cosine filters causes a slight difference between the response of two successive square-root raised cosine filters and the response of one raised cosine filter.
Using rcosine and rcosflt to Implement Square-Root Raised Cosine Filters. One way to implement the pair of square-root raised cosine filters is to follow these steps:
Use rcosine with the 'sqrt' flag to design a square-root raised cosine filter.
Use rcosflt in the transmitter section of code to upsample and filter the data.
Use rcosflt in the receiver section of code to filter the received data without upsampling it. Use the 'Fs' flag to avoid upsampling.
An example of this approach is below. The syntaxes for rcosflt use the 'filter' flag to indicate that you are providing the filter's transfer function as an input.
% First approach s = RandStream.create('mt19937ar', 'seed',123); prevStream = RandStream.setGlobalStream(s); % Set stream for repeatability x = randi([0 1],100,1); % Data num = rcosine(1,8,'sqrt'); % Transfer function of filter y1 = rcosflt(x,1,8,'filter',num); % Filter the data. z1 = rcosflt(y1,1,8,'Fs/filter',num); % Filter the received data % but do not upsample it. RandStream.setGlobalStream(prevStream); % Restore default stream
Using rcosflt Alone. Another way to implement the pair of square-root raised cosine filters is to have rcosflt both design and use the square-root raised cosine filter. This approach avoids using rcosine. The corresponding example code is below. The syntaxes for rcosflt use the 'sqrt' flag to indicate that you want it to design a square-root raised cosine filter.
% Second approach s = RandStream.create('mt19937ar', 'seed',123); prevStream = RandStream.setGlobalStream(s); % Set stream for repeatability x = randi([0 1],100,1); % Data (again) y2 = rcosflt(x,1,8,'sqrt'); % Design and use a filter. z2 = rcosflt(y2,1,8,'sqrt/Fs'); % Design and use a filter % but do not upsample the data. RandStream.setGlobalStream(prevStream); % Restore default stream
Because these two approaches are equivalent, y1 is the same as y2 and z1 is the same as z2.
The rcosine function designs (but does not apply) filters of these types:
Finite impulse response (FIR) raised cosine filter
Infinite impulse response (IIR) raised cosine filter
FIR square-root raised cosine filter
IIR square-root raised cosine filter
The function returns the transfer function as output. To learn about applying raised cosine filters, see Filter with Raised Cosine Filters in MATLAB.
The rcosine function assumes that you want to apply the filter to a digital signal whose sampling rate is Fd. The function also requires you to provide the filter's sampling rate, Fs. The ratio of Fs to Fd must be an integer.
For example, the command below designs a square-root raised cosine FIR filter with a sampling rate of 2, for use with a digital signal whose sampling rate is 1.
num = rcosine(1,2,'fir/sqrt')
num =
Columns 1 through 7
0.0021 -0.0106 0.0300 -0.0531 -0.0750 0.4092 0.8037
Columns 8 through 13
0.4092 -0.0750 -0.0531 0.0300 -0.0106 0.0021
Here, the vector num contains the coefficients of the filter, in ascending order of powers of z-1.
You can also control the filter design by specifying the rolloff factor, group delay, and (for IIR filters) tolerance index explicitly, instead of having rcosine use its default values. The reference page for rcosine explains these parameters. The group delay is also mentioned in Group Delay.
The Raised Cosine Transmit Filter and Raised Cosine Receive Filter blocks are designed for raised cosine filtering. Each block can apply a square root raised cosine filter or a normal raised cosine filter to a signal. You can vary the rolloff factor and group delay of the filter.
The Raised Cosine Transmit Filter and Raised Cosine Receive Filter blocks are tailored for use at the transmitter and receiver, respectively. In particular, the transmit filter outputs an upsampled signal, while the receive filter expects its input signal to be upsampled already. Also, the receive filter lets you choose whether to have the block downsample the filtered signal before sending it to the output port.
Both raised cosine filter blocks incur a propagation delay, described in Group Delay.
To split the filtering equally between the transmitter's filter and the receiver's filter, use a pair of square root raised cosine filters:
Use a Raised Cosine Transmit Filter block at the transmitter, setting the Filter type parameter to Square root.
Use a Raised Cosine Receive Filter block at the receiver, setting the Filter type parameter to Square root. In most cases, it is appropriate to set the Input samples per symbol parameter to match the transmit filter's Upsampling factor parameter.
In theory, the cascade of two square root raised cosine filters is equivalent to a single normal raised cosine filter. However, the limited impulse response of practical square root raised cosine filters causes a slight difference between the response of two cascaded square root raised cosine filters and the response of one raised cosine filter.
This example illustrates a typical setup in which a transmitter uses a square root raised cosine filter to perform pulse shaping and the corresponding receiver uses a square root raised cosine filter as a matched filter. The example plots an eye diagram from the filtered received signal.

To open the completed model, click here in the MATLAB Help browser. To build the model, gather and configure these blocks:
Random Integer Generator, in the Random Data Sources sublibrary of the Comm Sources library
Set M-ary number to 16.
Set Sample time to 1/100.
Select Frame-based outputs.
Set Samples per frame to 100.
Rectangular QAM Modulator Baseband, in the AM sublibrary of the Digital Baseband sublibrary of Modulation
Set Normalization method to Peak Power.
Set Peak power to 1.
Raised Cosine Transmit Filter, in the Comm Filters library
Set Group delay to 4.
AWGN Channel, in the Channels library
Set Mode to Signal to noise ratio (SNR).
Set SNR to 40.
Set Input signal power to 0.0694.
The power gain of square root raised cosine transmit filter is
, where N represents
the upsampling factor of the filter. The input signal power of filter
is 0.5556. Because the Peak power of
the 16-QAM Rectangular modulator is set to 1 Watt, it translates to
an average power of 0.5556. Therefore, the output signal power of
filter is
.
Raised Cosine Receive Filter, in the Comm Filters library
Set Group delay to 4.
Set Rolloff factor to 0.5.
Set Output mode to None.
Discrete-Time Eye Diagram Scope, in the Comm Sinks library
Set Symbols per trace to 2.
Set Traces displayed to 100.
Connect the blocks as in the figure. Running the simulation produces the following eye diagram. The eye diagram has two widely opened "eyes" that indicate appropriate instants at which to sample the filtered signal before demodulating. This illustrates the absence of intersymbol interference at the sampling instants of the received waveform.

The large signal-to-noise ratio in this example produces a low-noise eye diagram, while the model still illustrates where the raised cosine filter blocks typically belong in relation to a channel block. If you decrease the SNR parameter in the AWGN Channel block, the eyes in the diagram are less open.
[1] Korn, Israel, Digital Communications, New York, Van Nostrand Reinhold, 1985.
[2] Oppenheim, Alan V., and Ronald W. Schafer, Discrete-Time Signal Processing, Englewood Cliffs, NJ, Prentice Hall, 1989.
[3] Proakis, John G., Digital Communications, 3rd ed., New York, McGraw-Hill, 1995.
[4] Rappaport, Theodore S., Wireless Communications: Principles and Practice, Upper Saddle River, NJ, Prentice Hall, 1996.
[5] Sklar, Bernard, Digital Communications: Fundamentals and Applications, Englewood Cliffs, NJ, Prentice Hall, 1988.
![]() | Analog Passband Modulation | Synchronization | ![]() |

Learn how to apply early verification to your development process through these technical resources.
How much time do you spend on testing to ensure implementation meets system-level requirements?
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |