MATLAB: How to make a causal interleaver in the Communications Toolbox

Communications Toolbox

I would like to interleave a data stream where N is the frame size and D is the interleaving depth as follows:
For N = 5 and D = 2,
input A0 A1 A2 A3 A4 B0 B1 B2 B3 B4 C0 C1 C2 C3 C4
output A0 0 A1 0 A2 B0 A3 B1 A4 B2 C0 B3 C1 B4 C2 …
For N = 5 and D = 3,
input A0 A1 A2 A3 A4 B0 B1 B2 B3 B4 C0 C1 C2 C3 C4
output A0 0 0 A1 0 B0 A2 0 B1 A3 C0 B2 A4 C1 B3
I believe this is called a causal interleaver. I would like to create this interleaver.

Best Answer

Causal Interleaving is not available in Communications Toolbox, as a workaround you can write your own function that does this. If you re-arrange your input to be:
[a0 a1 a2 a3 a4 b0 b1 b2 b3 b4 c0 c1 c2 c3 c4] as :
input = [0 0 0 0 0; a0 a1 a2 a3 a4; b0 b1 b2 b3 b4; c0 c1 c2 c3 c4]
The output is:
input =
[ 0, 0, 0, 0, 0 ]
[ a0, a1, a2, a3, a4 ]
[ b0, b1, b2, b3, b4]
[ c0, c1, c2, c3, c4 ]
Then you truncate zeros of the first 3 columns, and c3 and c4 of the last 2 columns to get the following matrix:
A1 =
[ a0, a1, a2, 0, 0 ]
[ b0, b1, b2, a3, a4]
[ c0, c1, c2, b3, b4]
You can see that the output A0 0 A1 0 A2 B0 A3 B1 A4 B2 C0 B3 C1 B4 C2 ...is done by the following operations on the matrix A1:
1. Leaving the first column unchanged,
2. Replacing the second column with the fourth column,
3. Replacing the third column with second column,
4. The fourth column with the fifth column,
5. and the fifth column with the third column,
The output is:
Output =
[ a0, 0, a1, 0, a2 ]
[ b0, a3, b1, a4, b2]
[ c0, b3, c1, b4, c2]
Note that you can use the following tips to get and change columns:
If input is A = [0 0 0 0 0; a0 a1 a2 a3; a4 b0 b1 b2 b3 b4; c0 c1 c2 c3 c4]
e1 = A(:,1); e2 = A(:,2)…to get columns of A
e1(1) = []; truncates the first element of the first column of A
e4(4) = []; truncates the last element of the last element of the last column of A
Related Question