0

I am trying to think of / find an algorithm that will allow interleaving on an array size that isn't a power of two. The current method that I am using takes the array size, finds the square root (n) and creates an n x n matrix. The rows and columns are then exchanged and the matrix is then extended back to an array.

I'm trying to find some sort of indexing system that is flexible with any input array size but also allows for a decent distribution of data and allows for reconstruction of the original array. I provided some example code explicitly showing how the nxn interleaver is working.

import numpy as np
import math
N = 75
input_stream = np.random.random_integers(0,100,size=N)

#############
# Interleaver
#############
mat_dim = int(math.sqrt(len(input_stream)))
interleave_mat = np.zeros((mat_dim,mat_dim), dtype=np.int)
interleave_out = np.zeros(mat_dim**2, dtype=np.int)

for i in range(0,mat_dim):
    for j in range(0,mat_dim):
        interleave_mat[i][j] = input_stream[i*mat_dim + j]
for i in range(0,mat_dim):
    for j in range(0,mat_dim):
        interleave_out[i*mat_dim + j] = interleave_mat[j][i]

################
# De-Interleaver
################
deinterleave_mat = np.zeros((mat_dim,mat_dim), dtype=np.int)
deinterleave_out = np.zeros(mat_dim**2, dtype=np.int)
for i in range(0,mat_dim):
    for j in range(0,mat_dim):
        deinterleave_mat[i][j] = interleave_out[i*mat_dim + j]
for i in range(0,mat_dim):
    for j in range(0,mat_dim):
        deinterleave_out[i*mat_dim + j] = deinterleave_mat[j][i]
output_stream = deinterleave_out

error_count = sum(1 for a,b in zip(input_stream, output_stream) if a != b)
if len(input_stream) > len(output_stream):
    error_count += len(input_stream) - len(output_stream)
print("Number of errors: {}").format(error_count)
print("input stream: {}").format(input_stream)
print("output stream: {}").format(output_stream)
gutelfuldead
  • 562
  • 4
  • 22
  • 1
    Is http://stackoverflow.com/questions/37973116/iterate-over-an-array-in-a-certain-order-so-that-it-is-sampled-fairly/37973896#37973896 helpful? – Edward Peters Jul 06 '16 at 19:36
  • Yeah it does - I was thinking something along similar lines... I'm just not sure how to index it appropriately so that I get the maximum amount of shift between the previously intermediate values. Essentially sticking to my row<->column swap but done between two separate arrays. – gutelfuldead Jul 07 '16 at 13:21

0 Answers0