Interleaver and Deinterleaver Implementation in MATLAB

matlab
interleaver
deinterleaver
source code
implementation

This document presents MATLAB source code for implementing an interleaver and its corresponding deinterleaver. The deinterleaver is used to validate the functionality of the interleaver.

Setting Up Input Parameters

First, we need to set up the parameters required for the interleaver module to function correctly.

clc;
clear all;
Ndatasc = 192;   % Number of data subcarriers in the IFFT symbol
mod_type = input('Enter the modulation type[1 for BPSK,2 for QPSK,4 for 16QAM,6 for 64QAM]: ');
ncbps = Ndatasc * mod_type; % Number of coded bits per symbol, based on the number of data carriers in the OFDM symbol
ncpc = mod_type;      % Number of coded bits per carrier
x = randint(ncbps, 1, [1, 0]); % Generating binary data (ones and zeros)
interleaver_input = x';  % Interleaver binary input

Interleaver MATLAB Code

The following code implements the interleaver.

% Interleaver PART
s = ceil(ncpc / 2);
k = 0:ncbps - 1; % First permutation of interleaver
m = (ncbps / 12) * mod(k, 12) + floor(k / 12); % Second permutation of interleaver
n = s * floor(m / s) + mod(m + ncbps - floor(12 * m / ncbps), s);
interleaved_data_out(n + 1) = interleaver_input(k + 1);  % OUTPUT of interleaver

Deinterleaver MATLAB Code

Here’s the MATLAB code for the deinterleaver, which reverses the interleaving process.

% Deinterleaver PART
j = 0:ncbps - 1;
s = ceil(ncpc / 2); % First de-permutation of de-interleaver
d = s * floor(j / s) + mod(j + floor(12 * j / ncbps), s); % Second de-permutation of de-interleaver
e = 12 * d - (ncbps - 1) * floor(12 * d / ncbps);
deinterleaver_data_out(e + 1) = interleaved_data_out(j + 1);

OUTPUT Plots in MATLAB

This section provides the MATLAB code to plot the input, interleaved output, and deinterleaved output data.

% Plotting data
subplot(4, 1, 1), plot(1:length(interleaver_input), interleaver_input);
title('INTERLEAVER INPUT');
xlabel('binary input index');
ylabel('binary data');

subplot(4, 1, 2), plot(1:length(interleaved_data_out), interleaved_data_out);
title('INTERLEAVER OUTPUT');
xlabel('binary input index');
ylabel('binary data');

subplot(4, 1, 3), plot(1:length(deinterleaver_data_out), deinterleaver_data_out);
title('DE-INTERLEAVER OUTPUT');
xlabel('binary input index');
ylabel('binary data');

subplot(4, 1, 4), plot(1:length(deinterleaver_data_out), (interleaver_input - deinterleaver_data_out));
title('Difference between Interleaver-IN and Deinterleaver-OUT/');

Here’s what the input to the interleaver looks like:

input to interleaver

And here’s a sample output from the interleaver and deinterleaver:

interleaver deinterleaver matlab output

3-to-8 Decoder VHDL Source Code

VHDL source code for a 3-to-8 decoder implementation, demonstrating a basic digital logic circuit.

vhdl
decoder
source code
CRC MATLAB Source Code for CRC8 and CRC32

CRC MATLAB Source Code for CRC8 and CRC32

Explore CRC MATLAB source code implementations for CRC8 and CRC32 polynomials, used in error detection for wired and wireless communication systems. Includes code examples and explanations.

matlab
crc
source code