Spectrum of OFDM with raised cosine window
This spectral shaping technique is applied in time domain, after adding the guard interval (GI). But I find it easier to add GI and the cyclic extension for windowing in one step. Let $x(n)$ be an $N$ subcarriers OFDM symbol without guard interval. Then $W + G$ samples are copied to the beginning accounting for guard interval and windowing samples. Additionaly, $W$ samples are copied to the end, also for windowing:
$$
y(n) =
\begin{cases}
x(n+N) &amp; \text{for} &amp; -G-W \leq n \leq -1 \\
x(n) &amp; \text{for} &amp; 0 \leq n \leq N -1 \\
x(n-N) &amp; \text{for} &amp; N \leq n \leq N + W -1
\end{cases}
$$
In the next step, the raised cosine function is applied to the first and last $W$ samples of $y(n)$, respectively. The windowing function $w(n)$ is given by:
$$
w(n)=
\begin{cases}
\cos^2\left( \frac{n+G+1}{W-1} \frac{\pi}{2}\right) &amp; \text{for} &amp; -G-W \leq n \leq -G-1 \\
1 &amp; \text{for} &amp; -G \leq n \leq N - 1 \\
\cos^2\left( \frac{n-N}{W-1} \frac{\pi}{2}\right) &amp; \text{for} &amp; N \leq n \leq N+W-1 \\
0 &amp; \text{otherwise} 
\end{cases}
$$
$w(n)$ is similar but not equal to the transfer function of a raised cosine filter often used as impulse shaper in single carrier transmission systems. The two differences are: (1) the raised cosine function is applied in time domain for OFDM systems and in frequency domain for single carrier systems and (2) the "flat top" is usually much longer for OFDM systems, whereas its length is in a fixed relation with the flanks' length, given by the roll-off factor, for single carrier systems.

Finally, the OFDM symbol including GI and spectral shaping is calculated by
$$
z(n) = w(n)y(n)
$$

When transmitting several OFDM symbols $z_i(n)$, two consecutive symbols overlap at $W$ samples. The discrete transmit signal $u(n)$ is therefore given by
$$
u(n)=\sum_{i=-\infty}^\infty z_i(n-i(N+G+W))
$$

The implementation in Matlab should now be straightforward by substituting $n$ with $n' = n + G+ W+ 1$ in the above equations. Leave a comment if not.