MATLAB Code for Raised Cosine Filter Pulse Shaping
clc; clear; close all;
%% =====================================================
%% PARAMETERS
%% =====================================================
N = 64; % Number of OFDM subcarriers
cpLen = 16; % Cyclic prefix length
modOrder = 4; % QPSK
oversample = 8; % Oversampling factor
span = 10; % RRC filter span in symbols
rolloff = 0.25; % RRC roll-off factor
%% =====================================================
%% Generate Baseband OFDM Symbols
%% =====================================================
data = randi([0 modOrder-1], N, 1); % Random bits
txSymbols = pskmod(data, modOrder, pi/4); % QPSK modulation
% IFFT to get OFDM symbol
tx_ofdm = ifft(txSymbols, N);
% Add cyclic prefix
tx_cp = [tx_ofdm(end-cpLen+1:end); tx_ofdm];
%% =====================================================
%% Oversample the Baseband Signal
%% =====================================================
tx_oversampled = upsample(tx_cp, oversample);
%% =====================================================
%% Root Raised Cosine (RRC) Pulse Shaping
%% =====================================================
rrcFilter = rcosdesign(rolloff, span, oversample, 'sqrt'); % RRC filter
tx_shaped = conv(tx_oversampled, rrcFilter, 'same');
%% =====================================================
%% Visualize Time-Domain Waveform
%% =====================================================
figure;
subplot(2,1,1);
plot(real(tx_oversampled), 'b'); hold on;
plot(real(tx_shaped), 'r');
xlabel('Sample Index'); ylabel('Amplitude');
title('OFDM Time-Domain Waveform');
legend('Before RRC','After RRC');
grid on;
%% =====================================================
%% Visualize Spectrum
%% =====================================================
subplot(2,1,2);
nFFT = 1024;
f = linspace(-0.5,0.5,nFFT)*oversample; % Normalized freq axis
TX_OS_F = fftshift(abs(fft(tx_oversampled,nFFT)));
TX_SH_F = fftshift(abs(fft(tx_shaped,nFFT)));
plot(f, TX_OS_F/max(TX_OS_F), 'b'); hold on;
plot(f, TX_SH_F/max(TX_SH_F), 'r');
xlabel('Normalized Frequency'); ylabel('Normalized Magnitude');
title('OFDM Spectrum');
legend('Before RRC','After RRC');
grid on;
%% =====================================================
Output