% Define parameters.
M = 16; % Size of signal constellation
k = log2(M); % Number of bits per symbol
n = 5e5; % Number of bits to process
nsamp = 4; % Oversampling rate
% Create a binary data stream as a column vector.
x = randint(n,1); % Random binary data stream
% Plot first 40 bits in a stem plot.
stem(x(1:40),'filled');
title('Random Bits');
xlabel('Bit Index'); ylabel('Binary Value');
% Define a convolutional coding trellis and use it
% to encode the binary data.
t = poly2trellis([5 4],[23 35 0; 0 5 13]); % Trellis
code = convenc(x,t); % Encode.
coderate = 2/3;
mapping = [0 1 3 2 4 5 7 6 12 13 15 14 8 9 11 10].';
% B. Do ordinary binary-to-decimal mapping.
xsym = bi2de(reshape(code,k,length(code)/k).','left-msb');
% C. Map from binary coding to Gray coding.
xsym = mapping(xsym+1);
% Plot first 10 symbols in a stem plot.
figure; % Create new figure window.
stem(xsym(1:10));
title('Random Symbols');
xlabel('Symbol Index'); ylabel('Integer Value');
% Modulate using 16-QAM.
y = modulate(modem.qammod(M),xsym);
% Define filter-related parameters.
filtorder = 40; % Filter order
delay = filtorder/(nsamp*2); % Group delay (# of input samples)
rolloff = 0.25; % Rolloff factor of filter
% Create a square root raised cosine filter.
rrcfilter = rcosine(1,nsamp,'fir/sqrt',rolloff,delay);
% Plot impulse response.
figure; impz(rrcfilter,1)