The Communications System Toolbox™ software includes several functions, objects, and blocks that can help you design and use filters. Other filtering capabilities are in the Signal Processing Toolbox™ and the DSP System Toolbox™. The sections of this chapter are as follows:
For an example 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 per second. 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 blocks in the Communications System Toolbox support 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 a typical use of raised cosine filters.
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.
Set up the example by defining the size of signal constellation, number of bits per symbol, number of bits to process, and the oversampling factor 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 = comm.RectangularQAMModulator(M, ... 'BitInput', true, ... 'SymbolMapping', 'Gray');
Create a 16-QAM demodulator.
hDemod = comm.RectangularQAMDemodulator(M, ... 'BitOutput', true, ... 'SymbolMapping', 'Gray');
Design transmit and receive square-root raised cosine filters. Set the filter span to 10 symbols and the rolloff factor to 0.25. Calculate the group delay of the transmit filter in samples.
filtSpanInSymbols = 10; rolloff = 0.25; txDelay = filtSpanInSymbols * nSamp; hTxFilter = comm.RaisedCosineTransmitFilter(... 'RolloffFactor', rolloff, ... 'FilterSpanInSymbols', filtSpanInSymbols, ... 'OutputSamplesPerSymbol', nSamp); hRxFilter = comm.RaisedCosineReceiveFilter(... 'RolloffFactor', rolloff, ... 'FilterSpanInSymbols', filtSpanInSymbols, ... 'InputSamplesPerSymbol', nSamp, ... 'DecimationFactor', nSamp);
Plot the impulse response.
Create a constellation diagram to plot the received signal.
hConstDiag = comm.ConstellationDiagram(... 'SamplesPerSymbol', nSamp, ... 'SymbolsToDisplaySource', 'Input frame length', ... 'ReferenceConstellation', hMod.constellation, ... 'XLimits', [-4.5 4.5], 'YLimits', [-4.5 4.5], ... 'Title', 'Received Signal');
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 = step(hMod,x);
Filter the signal with the transmit filter.
yTx = step(hTxFilter, y);
Plot the eye diagram of the filtered signal.
Pass the signal through an AWGN channel. Use an Eb/N0 value of 10 dB.
EbNo = 10; SNR = EbNo + 10*log10(k) - 10*log10(nSamp); yNoisy = awgn(yTx,SNR,'measured');
Filter the noisy signal with the receive filter.
yRx = step(hRxFilter, yNoisy);
Plot the constellation diagram of the received signal.
Demodulate the input data stream using the 16-QAM modulation technique.
z = step(hDemod,yRx);
Compare x and z to obtain the number of errors and then calculate the bit error rate. Account for filter group delay by discarding the samples of the received signal z with indices smaller than the group delay.
[number_of_errors,bit_error_rate] = biterr(x(1:end-txDelay),z(txDelay+1:end))
number_of_errors = 45 bit_error_rate = 0.0015
The raised cosine filter blocks in the commfilt2 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 Filter span in symbols parameter, which is twice the group delay in symbols.
For example, the square-root raised cosine filter whose impulse response shown in the following figure uses a Filter span in symbols parameter of 8 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 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 (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 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.
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
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 rcosdesign function designs (but does not apply) filters of these types:
Finite impulse response (FIR) raised cosine filter
FIR square-root raised cosine filter
The function returns the FIR coefficients as output.
For example, the command below designs a square-root raised cosine FIR filter with a rolloff of 0.25, a filter span of 6 symbols, and an oversampling factor of 2.
sps = 2; num = rcosdesign(0.25, 6, sps)
num = Columns 1 through 7 -0.0265 0.0462 0.0375 -0.1205 -0.0454 0.4399 0.7558 Columns 8 through 13 0.4399 -0.0454 -0.1205 0.0375 0.0462 -0.0265
Here, the vector num contains the coefficients of the filter, in ascending order of powers of z-1.
You can use the upfirdn function to filter data with a raised cosine filter generated by rcosdesign. The following code illustrates this usage:
d = 2*randi([0 1], 100, 1)-1; f = upfirdn(d, num, sps); eyediagram(f(7:200),sps)
The eye diagram shows an imperfect eye because num is a square-root filter.
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 span 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 shape parameter to Square root.
Use a Raised Cosine Receive Filter block at the receiver, setting the Filter shape parameter to Square root. In most cases, it is appropriate to set the Input samples per symbol parameter to match the transmit filter's Output samples per symbol 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.
Random Integer Generator, in the Random Data Sources sublibrary of the Comm Sources library:
M-ary number is set to 16.
Sample time is set to 1/100.
Frame-based outputs is selected.
Samples per frame is set to 100.
Rectangular QAM Modulator Baseband, in the AM sublibrary of the Digital Baseband sublibrary of Modulation:
Normalization method is set to Peak Power.
Peak power is set to 1.
Raised Cosine Transmit Filter, in the Comm Filters library:
Filter span in symbols is set to 8.
Rolloff factor is set to 0.2
AWGN Channel, in the Channels library:
Mode is set to Signal to noise ratio (SNR).
SNR is set to 40.
Input signal power is set to 0.0694. The power gain of a 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:
Filter span in symbols is set to 8.
Rolloff factor is set to 0.2.
Discrete-Time Eye Diagram Scope, in the Comm Sinks library:
Symbols per trace is set to 2.
Traces displayed is set to 100.
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 an eye diagram with large eye openings. If you decrease the SNR parameter in the AWGN Channel block, the eyes in the diagram will close more.
 Korn, Israel, Digital Communications, New York, Van Nostrand Reinhold, 1985.
 Oppenheim, Alan V., and Ronald W. Schafer, Discrete-Time Signal Processing, Englewood Cliffs, NJ, Prentice Hall, 1989.
 Proakis, John G., Digital Communications, 3rd ed., New York, McGraw-Hill, 1995.
 Rappaport, Theodore S., Wireless Communications: Principles and Practice, Upper Saddle River, NJ, Prentice Hall, 1996.
 Sklar, Bernard, Digital Communications: Fundamentals and Applications, Englewood Cliffs, NJ, Prentice Hall, 1988.