| Communications Toolbox | ![]() |
This section further extends the example by addressing the following problem:
Problem Modify the Gray-coded modulation example so that it uses a pair of square root raised cosine filters to perform pulse shaping and matched filtering at the transmitter and receiver, respectively. |
The solution uses the rcosine function to design the square root raised cosine filter and the rcosflt function to filter the signals. Alternatively, you can use the rcosflt function to perform both tasks in one command; see Filtering with Raised Cosine Filters or the rcosdemo demonstration for more details.
This solution modifies the code from . To view the original code in an editor window, enter the following command in the MATLAB Command Window.
edit commdoc_gray
To view a completed M-file for this example, enter edit commdoc_rrc in the MATLAB Command Window.
1. Define Filter-Related Parameters. In the Setup section of the example from , replace the definition of the oversampling rate, nsamp, with the following.
nsamp = 4; % Oversampling rate
Also, define other key parameters related to the filter by inserting the following after the Modulation section of the example and before the Transmitted signal section.
%% Filter Definition % Define filter-related parameters. filtorder = 40; % Filter order delay = filtorder/(nsamp*2); % Group delay (# of input samples) rolloff = 0.25; % Rolloff factor of filter
2. Create a Square Root Raised Cosine Filter. To design the filter and plot its impulse response, insert the following commands after the commands you added in the previous step.
% Create a square root raised cosine filter. rrcfilter = rcosine(1,nsamp,'fir/sqrt',rolloff,delay); % Plot impulse response. figure; impz(rrcfilter,1);

3. Filter the Modulated Signal. To filter the modulated signal, replace the Transmitted Signal section with following.
%% Transmitted Signal % Upsample and apply square root raised cosine filter. ytx = rcosflt(y,1,nsamp,'filter',rrcfilter); % Create eye diagram for part of filtered signal. eyediagram(ytx(1:2000),nsamp*2);
The rcosflt command internally upsamples the modulated signal, y, by a factor of nsamp, pads the upsampled signal with zeros at the end to flush the filter at the end of the filtering operation, and then applies the filter.
The eyediagram command creates an eye diagram for part of the filtered noiseless signal. This diagram illustrates the effect of the pulse shaping. Note that the signal shows significant intersymbol interference (ISI) because the filter is a square root raised cosine filter, not a full raised cosine filter.

To learn more about eyediagram, see Eye Diagrams.
4. Filter the Received Signal. To filter the received signal, replace the Received Signal section with the following.
%% Received Signal % Filter received signal using square root raised cosine filter. yrx = rcosflt(ynoisy,1,nsamp,'Fs/filter',rrcfilter); yrx = downsample(yrx,nsamp); % Downsample. yrx = yrx(2*delay+1:end-2*delay); % Account for delay.
These commands apply the same square root raised cosine filter that the transmitter used earlier, and then downsample the result by a factor of nsamp.
The last command removes the first 2*delay symbols and the last 2*delay symbols in the downsampled signal because they represent the cumulative delay of the two filtering operations. Now yrx, which is the input to the demodulator, and y, which is the output from the modulator, have the same vector size. In the part of the example that computes the bit error rate, it is important to compare two vectors that have the same size.
5. Adjust the Scatter Plot. For variety in this example, make the scatter plot show the received signal before and after the filtering operation. To do this, replace the Scatter Plot section of the example with the following.
%% Scatter Plot
% Create scatter plot of received signal before and
% after filtering.
h = scatterplot(sqrt(nsamp)*ynoisy(1:nsamp*5e3),nsamp,0,'g.');
hold on;
scatterplot(yrx(1:5e3),1,0,'kx',h);
title('Received Signal, Before and After Filtering');
legend('Before Filtering','After Filtering');
axis([-5 5 -5 5]); % Set axis ranges.
Notice that the first scatterplot command scales ynoisy by sqrt(nsamp) when plotting. This is because the filtering operation changes the signal's power.

| Plotting Signal Constellations | Using a Convolutional Code | ![]() |
© 1994-2005 The MathWorks, Inc.