-
Notifications
You must be signed in to change notification settings - Fork 0
/
libEDM_spreading.h
62 lines (50 loc) · 1.92 KB
/
libEDM_spreading.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
#pragma once
#define _USE_MATH_DEFINES
#include <cmath>
#include <libEDM_matrix.h>
template <class VectorType>
class Spreader {
public:
Spreader (const dMatrix &spreadingCodes) : spreadingCodes(spreadingCodes) {}
void spread (const VectorType &input, const size_t spreadingCodeId, VectorType &output) const;
VectorType spread (const VectorType &input, const size_t spreadingCodeId) const;
void despread (const VectorType &input, const size_t spreadingCodeId, VectorType &output) const;
VectorType despread (const VectorType &input, const size_t spreadingCodeId) const;
size_t SF() const {return spreadingCodes.size();}
private:
const dMatrix spreadingCodes;
};
template <class VectorType>
void Spreader<VectorType>::spread (const VectorType &input, const size_t spreadingCodeId, VectorType &output) const
{
output.resize(0);
for (size_t i=0; i<input.size(); i++)
output.ins(output.size(), spreadingCodes[spreadingCodeId] * input[i]);
}
template <class VectorType>
VectorType Spreader<VectorType>::spread (const VectorType &input, const size_t spreadingCodeId) const
{
VectorType output;
spread(input, spreadingCodeId, output);
return output;
}
template <class VectorType>
void Spreader<VectorType>::despread (const VectorType &input, const size_t spreadingCodeId, VectorType &output) const
{
output.clear();
output.resize(input.size() / SF());
for (size_t i=0; i<output.size(); i++)
{
for (size_t j=0; j<SF(); j++)
output[i] += input[i*SF() + j] * spreadingCodes[spreadingCodeId][j];
output[i] /= SF();
}
}
template <class VectorType>
VectorType Spreader<VectorType>::despread (const VectorType &input, const size_t spreadingCodeId) const
{
VectorType output;
despread(input, spreadingCodeId, output);
return output;
}
dMatrix wcdma_spreading_codes(const size_t SF);