36 #include <itpp/itexports.h>
85 int rows, cols, input_length;
131 Vec<T> tempvec, zerostemp;
187 ivec interleaver_sequence;
188 int interleaver_depth, input_length;
208 input_length = input.
length();
209 int steps = (int)
std::ceil(
double(input_length) / double(rows * cols));
210 int output_length = steps * rows * cols;
214 if (input_length == output_length) {
216 for (s = 0; s < steps; s++) {
217 for (c = 0; c < cols; c++) {
218 for (r = 0; r < rows; r++) {
219 output(s*rows*cols + r*cols + c) = input(s * rows * cols + c * rows + r);
226 for (s = 0; s < steps - 1; s++) {
227 for (c = 0; c < cols; c++) {
228 for (r = 0; r < rows; r++) {
229 output(s*rows*cols + r*cols + c) = input(s * rows * cols + c * rows + r);
234 Vec<T> zerovect(output_length - input_length);
237 for (c = 0; c < cols; c++) {
238 for (r = 0; r < rows; r++) {
239 output((steps - 1)*rows*cols + r*cols + c) = temp_last_input(c * rows + r);
249 interleave(input, output);
256 int thisinput_length = input.
length();
257 int steps = (int)
std::ceil(
double(thisinput_length) / double(rows * cols));
258 int output_length = steps * rows * cols;
259 output.
set_size(output_length,
false);
262 if (thisinput_length == output_length) {
264 for (s = 0; s < steps; s++) {
265 for (r = 0; r < rows; r++) {
266 for (c = 0; c < cols; c++) {
267 output(s*rows*cols + c*rows + r) = input(s * rows * cols + r * cols + c);
274 for (s = 0; s < steps - 1; s++) {
275 for (r = 0; r < rows; r++) {
276 for (c = 0; c < cols; c++) {
277 output(s*rows*cols + c*rows + r) = input(s * rows * cols + r * cols + c);
282 Vec<T> zerovect(output_length - thisinput_length);
285 for (r = 0; r < rows; r++) {
286 for (c = 0; c < cols; c++) {
287 output((steps - 1)*rows*cols + c*rows + r) = temp_last_input(r * cols + c);
292 output.
set_size(input_length,
true);
299 deinterleave(input, output, keepzeros);
310 inter_matrix.set_size(order, order,
false);
311 tempvec.set_size(order,
false);
312 zerostemp.set_size(order,
false);
318 input_length = input.
length();
319 int steps = (int)
std::ceil(
float(input_length) / order) + order;
320 int output_length = steps * order;
324 inter_matrix.clear();
328 for (i = 0; i < steps; i++) {
331 for (c = order - 1; c > 0; c--)
332 inter_matrix.set_col(c, inter_matrix.get_col(c - 1));
335 if ((i*order + order) < input_length)
336 tempvec = input.
mid(i * order, order);
337 else if ((i*order) < input_length)
338 tempvec =
concat(input.
right(input_length - i * order), zerostemp.
left(order - (input_length - i * order)));
341 inter_matrix.set_col(0, tempvec);
344 for (r = 0; r < order; r++)
345 output(i*order + r) = inter_matrix(r, r);
353 interleave(input, output);
360 int thisinput_length = input.
length();
361 int steps = (int)
std::ceil(
float(thisinput_length) / order) + order;
362 int output_length = steps * order;
363 output.
set_size(output_length,
false);
366 inter_matrix.clear();
370 for (i = 0; i < steps; i++) {
373 for (c = order - 1; c > 0; c--)
374 inter_matrix.set_col(c, inter_matrix.get_col(c - 1));
377 if ((i*order + order) < thisinput_length)
378 tempvec = input.
mid(i * order, order);
379 else if ((i*order) < thisinput_length)
380 tempvec =
concat(input.
right(thisinput_length - i * order), zerostemp.
left(order - (thisinput_length - i * order)));
383 inter_matrix.set_col(0, tempvec);
386 for (r = 0; r < order; r++)
387 output(i*order + r) = inter_matrix(r, order - 1 - r);
397 deinterleave(input, output, keepzeros);
406 inter_matrix.set_size(order, order,
false);
407 tempvec.set_size(order,
false);
408 zerostemp.set_size(order,
false);
416 interleaver_depth = in_interleaver_depth;
417 interleaver_sequence = sort_index(
randu(in_interleaver_depth));
424 interleaver_depth = in_interleaver_sequence.length();
425 interleaver_sequence = in_interleaver_sequence;
432 input_length = input.
length();
433 int steps = (int)
std::ceil(
double(input_length) / double(interleaver_depth));
434 int output_length = steps * interleaver_depth;
435 output.
set_size(output_length,
false);
438 if (input_length == output_length) {
441 for (s = 0; s < steps; s++) {
442 for (i = 0; i < interleaver_depth; i++) {
443 output(s*interleaver_depth + i) = input(s * interleaver_depth + interleaver_sequence(i));
451 for (s = 0; s < steps - 1; s++) {
452 for (i = 0; i < interleaver_depth; i++) {
453 output(s*interleaver_depth + i) = input(s * interleaver_depth + interleaver_sequence(i));
457 Vec<T> zerovect(output_length - input_length);
460 for (i = 0; i < interleaver_depth; i++) {
461 output((steps - 1)*interleaver_depth + i) = temp_last_input(interleaver_sequence(i));
471 interleave(input, output);
478 int thisinput_length = input.
length();
479 int steps = (int)
std::ceil(
double(thisinput_length) / double(interleaver_depth));
480 int output_length = steps * interleaver_depth;
484 if (thisinput_length == output_length) {
487 for (s = 0; s < steps; s++) {
488 for (i = 0; i < interleaver_depth; i++) {
489 output(s*interleaver_depth + interleaver_sequence(i)) = input(s * interleaver_depth + i);
496 for (s = 0; s < steps - 1; s++) {
497 for (i = 0; i < interleaver_depth; i++) {
498 output(s*interleaver_depth + interleaver_sequence(i)) = input(s * interleaver_depth + i);
502 Vec<T> zerovect(output_length - thisinput_length);
505 for (i = 0; i < interleaver_depth; i++) {
506 output((steps - 1)*interleaver_depth + interleaver_sequence(i)) = temp_last_input(i);
509 output.
set_size(input_length,
true);
518 deinterleave(input, output, keepzeros);
525 interleaver_sequence = sort_index(
randu(interleaver_depth));
531 return interleaver_sequence;
537 interleaver_sequence = in_interleaver_sequence;
538 interleaver_depth = interleaver_sequence.size();
569 #endif // #ifndef INTERLEAVE_H