sequence.cpp
Go to the documentation of this file.
#include <itpp/comm/sequence.h>
#include <itpp/base/converters.h>
#include <itpp/base/math/log_exp.h>
namespace itpp
{
LFSR::LFSR(const bvec &connections)
{
set_connections(connections);
}
LFSR::LFSR(const ivec &connections)
{
set_connections(connections);
}
void LFSR::set_connections(const bvec &connections)
{
int N = connections.size() - 1;
memory.set_size(N, true); // Should this be true???
Connections = connections.right(N);
}
void LFSR::set_connections(const ivec &connections)
{
bvec temp = oct2bin(connections);
int N = temp.size() - 1;
memory.set_size(N, true); // Should this be true???
Connections = temp.right(N);
}
void LFSR::set_state(const bvec &state)
{
it_assert(state.length() == memory.size(), "LFSR::set_state(): dimension mismatch");
memory = state;
}
void LFSR::set_state(const ivec &state)
{
bvec temp = oct2bin(state, 1);
it_assert(temp.length() >= memory.size(), "LFSR::set_state(): dimension mismatch");
memory = temp.right(memory.size());
}
bvec LFSR::shift(int no_shifts)
{
it_assert(no_shifts > 0, "LFSR::shift(): shift must be positive");
bvec temp(no_shifts);
for (int i = 0;i < no_shifts;i++) {
temp(i) = shift();
}
return temp;
}
//--------------------------- class Gold -------------------------
Gold::Gold(int degree)
{
bvec mseq1_connections, mseq2_connections;
switch (degree) {
case 5:
mseq1_connections = bvec("1 0 1 0 0 1");
mseq2_connections = bvec("1 0 1 1 1 1");
break;
case 7:
mseq1_connections = bvec("1 0 0 1 0 0 0 1");
mseq2_connections = bvec("1 1 1 1 0 0 0 1");
break;
case 8:
mseq1_connections = bvec("1 1 1 0 0 1 1 1 1");
mseq2_connections = bvec("1 1 0 0 0 0 1 1 1");
break;
case 9:
mseq1_connections = bvec("1 0 0 0 1 0 0 0 0 1");
mseq2_connections = bvec("1 0 0 1 1 0 1 0 0 1");
break;
default:
it_error("This degree of Gold sequence is not available");
}
mseq1.set_connections(mseq1_connections);
mseq2.set_connections(mseq2_connections);
N = pow2i(mseq1.get_length()) - 1;
}
Gold::Gold(const bvec &mseq1_connections, const bvec &mseq2_connections)
{
it_assert(mseq1_connections.size() == mseq2_connections.size(), "Gold::Gold(): dimension mismatch");
mseq1.set_connections(mseq1_connections);
mseq2.set_connections(mseq2_connections);
N = pow2i(mseq1.get_length()) - 1;
}
Gold::Gold(const ivec &mseq1_connections, const ivec &mseq2_connections)
{
mseq1.set_connections(mseq1_connections);
mseq2.set_connections(mseq2_connections);
it_assert(mseq1.get_length() == mseq1.get_length(), "Gold::Gold(): dimension mismatch");
N = pow2i(mseq1.get_length()) - 1;
}
void Gold::set_state(const bvec &state1, const bvec &state2)
{
mseq1.set_state(state1);
mseq2.set_state(state2);
}
void Gold::set_state(const ivec &state1, const ivec &state2)
{
mseq1.set_state(state1);
mseq2.set_state(state2);
}
bvec Gold::shift(int no_shifts)
{
it_assert(no_shifts > 0, "Gold::shift(): shift must be positive");
bvec temp(no_shifts);
for (int i = 0;i < no_shifts;i++) {
temp(i) = shift();
}
return temp;
}
bmat Gold::get_family(void)
{
bmat codes(N + 2, N);
bvec temp = dec2bin(mseq1.get_length(), 1);
set_state(temp, temp);
// The two m-seq.
codes.set_row(0, mseq1.shift(N));
codes.set_row(1, mseq2.shift(N));
// The sum of mseq1 and all time shifts of mseq2
for (int i = 0;i < N;i++) {
codes.set_row(i + 2, codes.get_row(0) + concat((codes.get_row(1)).right(i), (codes.get_row(1)).left(N - i)));
}
return codes;
}
smat wcdma_spreading_codes(int SF)
{
it_assert((SF == 1) || (SF == 2) || (SF == 4) || (SF == 8) || (SF == 16) || (SF == 32) || (SF == 64) || (SF == 128) || (SF == 256) || (SF == 512),
"wcdma_spreading_codes: SF must equal 1, 2, 4, 8, 16, 32, 64, 128, 256, or 512");
smat codes(SF, SF);
if (SF == 1) {
codes(0, 0) = short(1);
}
else {
int i;
smat prev_codes(SF / 2, SF / 2);
prev_codes = wcdma_spreading_codes(SF / 2);
for (i = 0; i < SF / 2; i++) {
codes.set_row(2*i, concat(prev_codes.get_row(i), prev_codes.get_row(i)));
codes.set_row(2*i + 1, concat(prev_codes.get_row(i), (-prev_codes.get_row(i))));
}
}
return codes;
}
} // namespace itpp
itpp::Mat::get_row
Vec< Num_T > get_row(int r) const
Get row r.
Definition: mat.h:852
sequence.h
Definitions of binary sequence classes and functions.
itpp::Gold::shift
bin shift(void)
Shift one step and output binary symbol.
Definition: sequence.h:129
itpp::Mat< bin >
itpp::Gold::Gold
Gold(int degree)
Class constructor.
Definition: sequence.cpp:86
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition: itassert.h:94
log_exp.h
Logarithmic and exponenential functions - header file.
converters.h
Definitions of converters between different vector and matrix types.
itpp::LFSR::shift
bin shift(void)
Shift one step and output binary symbol.
Definition: sequence.h:125
itpp::pow2i
int pow2i(int x)
Calculate two to the power of x (2^x); x is integer.
Definition: log_exp.h:53
itpp::Mat::set_row
void set_row(int r, const Vec< Num_T > &v)
Set row r to vector v.
Definition: mat.h:927
itpp::wcdma_spreading_codes
smat wcdma_spreading_codes(int SF)
Generates the OVSF (orthogonal variable spreading factor) spreading codes used in WCDMA...
Definition: sequence.cpp:168
itpp
itpp namespace
Definition: itmex.h:36
itpp::dec2bin
ITPP_EXPORT bvec dec2bin(int length, int index)
Convert a decimal int index to bvec using length bits in the representation.
itpp::Gold::get_family
bmat get_family(void)
Returns the code family.
Definition: sequence.cpp:152
it_error
#define it_error(s)
Abort unconditionally.
Definition: itassert.h:126
itpp::oct2bin
ITPP_EXPORT bvec oct2bin(const ivec &octalindex, short keepzeros=0)
Convert ivec of octal form to bvec.
itpp::Gold::set_state
void set_state(const bvec &state1, const bvec &state2)
Set state (contents in the shift registers) in bvec format.
Definition: sequence.cpp:130
itpp::LFSR::set_state
void set_state(const bvec &state)
Set state (contents in the shift registers) in bvec format.
Definition: sequence.cpp:62
itpp::LFSR::LFSR
LFSR(void)
Constructor.
Definition: sequence.h:57
itpp::LFSR::set_connections
void set_connections(const bvec &connections)
Input connect_polynomial=1+g1*D+g2*D^2+...+gr*D^r in bvec format [g0,g1,...,gr].
Definition: sequence.cpp:47
itpp::concat
const Array< T > concat(const Array< T > &a, const T &e)
Append element e to the end of the Array a.
Definition: array.h:486

Generated on Sat Sep 30 2017 07:04:09 for IT++ by Doxygen 1.8.13