-
Notifications
You must be signed in to change notification settings - Fork 0
/
libEDM_interleaver.h
72 lines (55 loc) · 2.48 KB
/
libEDM_interleaver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#pragma once
#include <assert.h>
#include <libEDM_matrix.h>
template <class Type>
class SequenceInterleaver {
public:
Vector<Type> interleave (const Vector<Type> &input) const;
void interleave (const Vector<Type> &input, Vector<Type> &output) const;
Vector<Type> deinterleave (const Vector<Type> &input) const;
void deinterleave (const Vector<Type> &input, Vector<Type> &output) const;
uVector get_interleaver_sequence(void) const {return interleaver_sequence;}
size_t interleaver_depth(void) const {return interleaver_sequence.size();}
void set_interleaver_sequence(uVector interleaver_sequence) {this->interleaver_sequence = interleaver_sequence;}
SequenceInterleaver(const uVector interleaver_sequence) : interleaver_sequence(interleaver_sequence) {}
private:
uVector interleaver_sequence;
};
typedef SequenceInterleaver<bool> bSequenceInterleaver;
typedef SequenceInterleaver<double> dSequenceInterleaver;
template <class Type>
void SequenceInterleaver<Type>::interleave(const Vector<Type> &input, Vector<Type> &output) const
{
size_t steps = static_cast<size_t>(ceil(static_cast<double>(input.size()) / interleaver_depth()));
size_t output_length = steps * interleaver_depth();
assert( output_length == input.size() );
output.resize(output_length);
for (size_t s=0; s<steps; s++)
for (size_t i=0; i<interleaver_depth(); i++)
output[s*interleaver_depth() + i] = input[s*interleaver_depth() + interleaver_sequence[i]];
}
template <class Type>
Vector<Type> SequenceInterleaver<Type>::interleave(const Vector<Type> &input) const
{
Vector<Type> output;
interleave(input, output);
return output;
}
template <class Type>
void SequenceInterleaver<Type>::deinterleave(const Vector<Type> &input, Vector<Type> &output) const
{
size_t steps = static_cast<size_t>(ceil(divide(input.size(), interleaver_depth())));
size_t output_length = steps * interleaver_depth();
assert ( output_length == input.size() );
output.resize(output_length);
for (size_t s=0; s<steps; s++)
for (size_t i=0; i<interleaver_depth(); i++)
output[s*interleaver_depth() + interleaver_sequence[i]] = input[s*interleaver_depth() + i];
}
template <class Type>
Vector<Type> SequenceInterleaver<Type>::deinterleave(const Vector<Type> &input) const
{
Vector<Type> output;
deinterleave(input, output);
return output;
}