Interleaver and deinterleaver MATLAB source code

This section of MATLAB source code covers interleaver matlab code. Deinterleaver matlab code is provided to validate the interleaver.

Setting up input parameters

%SETTING UP parameters required for Interleaver module to function
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 number of data carriers in 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

% 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

% 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

% 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/');

input to interleaver
interleaver deinterleaver matlab output

Useful Links to MATLAB codes

Refer following as well as links mentioned on left side panel for useful MATLAB codes.
OFDM Preamble generation  Time off estimation corr  Freq off estimation corr  channel estimation  11a WLAN channel  PN sequence generation  OFDMA Tx Rx  AES DES  carrier aggregation  CCDF  FIR Filter  IIR Filter  Low Pass FIR  Viterbi decoder  CRC8 CRC32 

RF and Wireless tutorials

WLAN  802.11ac  802.11ad  wimax  Zigbee  z-wave  GSM  LTE  UMTS  Bluetooth  UWB  IoT  satellite  Antenna  RADAR