spread.cpp
Go to the documentation of this file.
#include <itpp/comm/spread.h>
#include <itpp/base/converters.h>
#include <itpp/stat/misc_stat.h>
namespace itpp
{
//------------- Spread1d -------------------
Spread_1d::Spread_1d(const vec &incode)
{
set_code(incode);
}
void Spread_1d::set_code(const vec &incode)
{
N = incode.size();
code = incode;
code /= norm(code);
}
vec Spread_1d::get_code()
{
return code;
}
void Spread_1d::spread(const vec &symbols, vec &out)
{
out.set_size(symbols.length()*N, false);
for (int i = 0;i < symbols.length();i++)
out.replace_mid(i*N, symbols(i)*code);
}
void Spread_1d::despread(const vec &rec_signal, vec &out, int timing)
{
int nosymbols = (int)std::floor(double((rec_signal.length() - timing)) / N);
out.set_size(nosymbols);
for (int i = 0;i < nosymbols;i++)
out(i) = rec_signal.mid(i * N + timing, N) * code;
}
//---------------- Spread2d ----------------------
vec Spread_2d::get_codeI()
{
return spreadI.get_code();
}
vec Spread_2d::get_codeQ()
{
return spreadQ.get_code();
}
Spread_2d::Spread_2d(const vec &incodeI, const vec &incodeQ)
{
set_code(incodeI, incodeQ);
}
void Spread_2d::set_code(const vec &incodeI, const vec &incodeQ)
{
it_assert(incodeI.length() == incodeQ.length(), "Size of I and Q codes doesn't match");
spreadI.set_code(incodeI);
spreadQ.set_code(incodeQ);
}
void Spread_2d::spread(const cvec &symbols, cvec &out)
{
out = to_cvec(spreadI.spread(real(symbols)), spreadQ.spread(imag(symbols)));
}
void Spread_2d::despread(const cvec &rec_signal, cvec &out, int timing)
{
out = to_cvec(spreadI.despread(real(rec_signal), timing), spreadQ.despread(imag(rec_signal), timing));
}
//------------- Multicode_Spread_1d ----------------
Multicode_Spread_1d::Multicode_Spread_1d(const mat &incodes)
{
set_codes(incodes);
}
void Multicode_Spread_1d::set_codes(const mat &incodes)
{
codes = incodes;
N = incodes.cols();
L = incodes.rows();
for (int i = 0; i < L; i++)
codes.set_row(i, codes.get_row(i) / norm(codes.get_row(i)));
}
mat Multicode_Spread_1d::get_codes()
{
return codes;
}
vec Multicode_Spread_1d::spread(const vec &symbols)
{
int i;
int nomcsymbols = (int)std::floor(double(symbols.length() / L));
vec temp(nomcsymbols*N);
for (i = 0;i < nomcsymbols;i++) {
temp.replace_mid(i*N, codes.T() * symbols.mid(i*L, L)); // TODO: this is now very slow
}
return temp;
}
vec Multicode_Spread_1d::despread(const vec &receivedsignal, int timing)
{
int i;
int nosymbols = (int)std::floor(double((receivedsignal.length() - timing)) / N);
vec temp(nosymbols*L);
for (i = 0;i < nosymbols;i++) {
temp.replace_mid(i*L, codes*receivedsignal.mid(i*N + timing, N));
}
return temp;
}
//----------------- Multicode_Spread_2d -------------------
Multicode_Spread_2d::Multicode_Spread_2d(const mat &incodesI, const mat &incodesQ)
{
set_codes(incodesI, incodesQ);
}
mat Multicode_Spread_2d::get_codesI()
{
return mcspreadI.get_codes();
}
mat Multicode_Spread_2d::get_codesQ()
{
return mcspreadQ.get_codes();
}
void Multicode_Spread_2d::set_codes(const mat &incodesI, const mat &incodesQ)
{
it_assert(incodesI.rows() == incodesQ.rows() && incodesI.cols() == incodesQ.cols(),
"Multicode_Spread_2d::set_codes(): dimension mismatch");
mcspreadI.set_codes(incodesI);
mcspreadQ.set_codes(incodesQ);
}
cvec Multicode_Spread_2d::spread(const cvec &symbols)
{
return to_cvec(mcspreadI.spread(real(symbols)), mcspreadQ.spread(imag(symbols)));
}
cvec Multicode_Spread_2d::despread(const cvec &receivedsignal, int timing)
{
return to_cvec(mcspreadI.despread(real(receivedsignal), timing), mcspreadQ.despread(imag(receivedsignal), timing));
}
} // namespace itpp
itpp::Array
General array class.
Definition array.h:105
itpp::Array::mid
Array< T > mid(int pos, int n) const
Get n elements of the array starting from pos.
Definition array.h:377
itpp::Array::size
int size() const
Returns the number of data elements in the array object.
Definition array.h:155
itpp::Array::set_size
void set_size(int n, bool copy=false)
Resizing an Array<T>.
Definition array.h:257
itpp::Array::length
int length() const
Returns the number of data elements in the array object.
Definition array.h:157
itpp::Multicode_Spread_1d::L
int L
The number of multi-codes.
Definition spread.h:222
itpp::Multicode_Spread_1d::N
int N
The spreading factor.
Definition spread.h:224
itpp::Multicode_Spread_1d::spread
vec spread(const vec &symbols)
Spreading function.
Definition spread.cpp:132
itpp::Multicode_Spread_1d::get_codes
mat get_codes()
Returns the matrix containing the spreading codes used as rows in the matrix.
Definition spread.cpp:127
itpp::Multicode_Spread_1d::Multicode_Spread_1d
Multicode_Spread_1d()
Constructor.
Definition spread.h:203
itpp::Multicode_Spread_1d::despread
vec despread(const vec &receivedsignal, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:145
itpp::Multicode_Spread_1d::set_codes
void set_codes(const mat &incodes)
Set the spreading codes. Each row represent one spreading code. The spreading factor equals the numbe...
Definition spread.cpp:118
itpp::Multicode_Spread_1d::codes
mat codes
The spreading codes used size ( )
Definition spread.h:220
itpp::Multicode_Spread_2d::spread
cvec spread(const cvec &symbols)
Spreading of signal.
Definition spread.cpp:184
itpp::Multicode_Spread_2d::mcspreadI
Multicode_Spread_1d mcspreadI
Definition spread.h:274
itpp::Multicode_Spread_2d::get_codesQ
mat get_codesQ()
Return the matrix containing the quadrature-phase codes (as rows)
Definition spread.cpp:171
itpp::Multicode_Spread_2d::Multicode_Spread_2d
Multicode_Spread_2d()
Constructor.
Definition spread.h:251
itpp::Multicode_Spread_2d::get_codesI
mat get_codesI()
Return the matrix containing the in-phase codes (as rows)
Definition spread.cpp:166
itpp::Multicode_Spread_2d::mcspreadQ
Multicode_Spread_1d mcspreadQ
Definition spread.h:274
itpp::Multicode_Spread_2d::set_codes
void set_codes(const mat &incodesI, const mat &incodesQ)
Set the spreading codes.
Definition spread.cpp:176
itpp::Multicode_Spread_2d::despread
cvec despread(const cvec &receivedsignal, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:189
itpp::Spread_1d::N
int N
The spreading factor.
Definition spread.h:129
itpp::Spread_1d::despread
void despread(const vec &rec_signal, vec &out, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:64
itpp::Spread_1d::code
vec code
The spreading code.
Definition spread.h:127
itpp::Spread_1d::set_code
void set_code(const vec &incode)
Set the spreading code used for spreading.
Definition spread.cpp:44
itpp::Spread_1d::get_code
vec get_code()
Returns the spreading code used.
Definition spread.cpp:51
itpp::Spread_1d::Spread_1d
Spread_1d()
Constructor.
Definition spread.h:103
itpp::Spread_1d::spread
void spread(const vec &symbols, vec &out)
Spreading of signal return i out.
Definition spread.cpp:56
itpp::Spread_2d::spreadI
Spread_1d spreadI
Definition spread.h:183
itpp::Spread_2d::spread
void spread(const cvec &symbols, cvec &out)
Spreading of signal.
Definition spread.cpp:98
itpp::Spread_2d::despread
void despread(const cvec &rec_signal, cvec &out, int timing)
Despreading of signal. timing is the start position of the first symbol, given in number of samples.
Definition spread.cpp:103
itpp::Spread_2d::get_codeI
vec get_codeI()
Returns the in-phase spreading code.
Definition spread.cpp:76
itpp::Spread_2d::Spread_2d
Spread_2d()
Constructor.
Definition spread.h:156
itpp::Spread_2d::spreadQ
Spread_1d spreadQ
Definition spread.h:183
itpp::Spread_2d::get_codeQ
vec get_codeQ()
Returns the quadrature-phase spreading code.
Definition spread.cpp:81
itpp::Spread_2d::set_code
void set_code(const vec &incodeI, const vec &incodeQ)
Set the in-phase and the quadrature-phase spreading codes.
Definition spread.cpp:91
converters.h
Definitions of converters between different vector and matrix types.
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition itassert.h:94
itpp::imag
vec imag(const cvec &data)
Imaginary part of complex values.
Definition elem_math.cpp:180
itpp::real
vec real(const cvec &data)
Real part of complex values.
Definition elem_math.cpp:157
itpp::norm
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
Definition misc_stat.cpp:77
misc_stat.h
Miscellaneous statistics functions and classes - header file.
itpp
itpp namespace
Definition itmex.h:37
itpp::to_cvec
cvec to_cvec(const Vec< T > &v)
Converts a Vec<T> to cvec.
Definition converters.h:107
spread.h
Definition of spread spectrum classes and functions.

Generated on Mon Apr 22 2024 09:45:27 for IT++ by Doxygen 1.9.8