ofdm.cpp
Go to the documentation of this file.
#include <itpp/comm/ofdm.h>
#include <itpp/base/specmat.h>
#include <itpp/base/operators.h>
#include <itpp/signal/transforms.h>
namespace itpp
{
OFDM::OFDM(int inNfft, int inNcp, int inNupsample)
{
set_parameters(inNfft, inNcp, inNupsample);
}
void OFDM::set_parameters(const int inNfft, const int inNcp, const int inNupsample)
{
it_assert(inNfft >= 2, "OFDM: Nfft must be >=2.");
it_assert(inNcp >= 0 && inNcp <= inNfft, "OFDM: Ncp must be >=0 and <=Nfft.");
it_assert(inNupsample >= 1 && inNupsample <= 100, "OFDM: Ncp must be >=1 and <=100.");
Nfft = inNfft;
Ncp = inNcp;
Nupsample = inNupsample;
norm_factor = std::sqrt(static_cast<double>(Nupsample * Nfft * Nfft) / (Nfft + Ncp));
setup_done = true;
}
void OFDM::modulate(const cvec &input, cvec &output)
{
it_assert(setup_done == true, "OFDM::modulate: You must set the length of the FFT and the cyclic prefix!");
const int N = input.length() / Nfft;
it_assert(N*Nfft == input.length(), "OFDM::modulate: Length of input vector is not a multiple of Nfft.");
output.set_length(Nupsample*N*(Nfft + Ncp));
cvec outtemp(Nfft);
for (int i = 0; i < N; i++) {
outtemp = ifft(concat(input.mid(i * Nfft, Nfft / 2), zeros_c(Nfft * (Nupsample - 1)),
input.mid(i * Nfft + Nfft / 2, Nfft / 2))) * norm_factor;
output.replace_mid(Nupsample*(Nfft + Ncp)*i, concat(outtemp.right(Nupsample*Ncp), outtemp));
}
}
cvec OFDM::modulate(const cvec &input)
{
cvec output;
modulate(input, output);
return output;
}
void OFDM::demodulate(const cvec& input, cvec &output)
{
it_assert(setup_done == true, "OFDM::demodulate: You must set the length of the FFT and the cyclic prefix!");
const int N = input.length() / (Nfft + Ncp) / Nupsample;
it_assert(Nupsample*N*(Nfft + Ncp) == input.length(), "OFDM: Length of input vector is not a multiple of Nfft+Ncp.");
output.set_length(N*Nfft);
// normalize also taking the energy loss into the cyclic prefix into account
for (int i = 0; i < N; i++) {
cvec x = fft(input.mid(Nupsample * (i * (Nfft + Ncp) + Ncp), Nupsample * Nfft));
output.replace_mid(Nfft*i, concat(x.left(Nfft / 2), x.right(Nfft / 2)) / norm_factor);
}
}
cvec OFDM::demodulate(const cvec &input)
{
cvec output;
demodulate(input, output);
return output;
}
} //namespace itpp
itpp::OFDM::modulate
cvec modulate(const cvec &input)
Modulate complex data symbols. Length of input must be an integer multiple of Nfft.
Definition: ofdm.cpp:73
itpp::OFDM::OFDM
OFDM(void)
Empty constructor.
Definition: ofdm.h:50
ofdm.h
Interface of an Orthogonal Frequency Division Multiplex (OFDM) class.
itpp::OFDM
Class for modulating and demodulation of OFDM signals using the FFT.
Definition: ofdm.h:46
itpp
itpp namespace
Definition: itmex.h:36
transforms.h
Fourier, Hadamard, Walsh-Hadamard, and 2D Hadamard transforms - header file.
itpp::OFDM::set_parameters
void set_parameters(const int Nfft, const int Ncp, const int inNupsample=1)
Set parameters.
Definition: ofdm.cpp:45
specmat.h
Definitions of special vectors and matrices.
itpp::length
int length(const Vec< T > &v)
Length of vector.
Definition: matfunc.h:51
operators.h
Definitions of operators for vectors and matricies of different types.
it_assert
#define it_assert(t, s)
Abort if t is not true.
Definition: itassert.h:94

Generated on Mon Mar 23 2020 06:18:03 for IT++ by Doxygen 1.8.17