47 it_assert(inNfft >= 2,
"OFDM: Nfft must be >=2.");
48 it_assert(inNcp >= 0 && inNcp <= inNfft, "OFDM: Ncp must be >=0 and <=Nfft.
"); 49 it_assert(inNupsample >= 1 && inNupsample <= 100, "OFDM: Ncp must be >=1 and <=100.
"); 52 Nupsample = inNupsample; 53 norm_factor = std::sqrt(static_cast<double>(Nupsample * Nfft * Nfft) / (Nfft + Ncp)); 57 void OFDM::modulate(const cvec &input, cvec &output) 59 it_assert(setup_done == true, "OFDM::modulate: You must
set the
length of the FFT and the cyclic prefix!
"); 60 const int N = input.length() / Nfft; 61 it_assert(N*Nfft == input.length(), "OFDM::modulate: Length of input vector is not a multiple of Nfft.
"); 63 output.set_length(Nupsample*N*(Nfft + Ncp)); 66 for (int i = 0; i < N; i++) { 67 outtemp = ifft(concat(input.mid(i * Nfft, Nfft / 2), zeros_c(Nfft * (Nupsample - 1)), 68 input.mid(i * Nfft + Nfft / 2, Nfft / 2))) * norm_factor; 69 output.replace_mid(Nupsample*(Nfft + Ncp)*i, concat(outtemp.right(Nupsample*Ncp), outtemp)); 73 cvec OFDM::modulate(const cvec &input) 76 modulate(input, output); 80 void OFDM::demodulate(const cvec& input, cvec &output) 82 it_assert(setup_done == true, "OFDM::demodulate: You must
set the
length of the FFT and the cyclic prefix!
"); 83 const int N = input.length() / (Nfft + Ncp) / Nupsample; 84 it_assert(Nupsample*N*(Nfft + Ncp) == input.length(), "OFDM: Length of input vector is not a multiple of Nfft+Ncp.
"); 86 output.set_length(N*Nfft); 87 // normalize also taking the energy loss into the cyclic prefix into account 88 for (int i = 0; i < N; i++) { 89 cvec x = fft(input.mid(Nupsample * (i * (Nfft + Ncp) + Ncp), Nupsample * Nfft)); 90 output.replace_mid(Nfft*i, concat(x.left(Nfft / 2), x.right(Nfft / 2)) / norm_factor); 94 cvec OFDM::demodulate(const cvec &input) 97 demodulate(input, output); Class for modulating and demodulation of OFDM signals using the FFT.
#define it_assert(t, s)
Abort if t is not true.
int length(const Vec< T > &v)
Length of vector.
Definitions of operators for vectors and matricies of different types.
Definitions of special vectors and matrices.
void set_parameters(const int Nfft, const int Ncp, const int inNupsample=1)
Set parameters.
Interface of an Orthogonal Frequency Division Multiplex (OFDM) class.
cvec modulate(const cvec &input)
Modulate complex data symbols. Length of input must be an integer multiple of Nfft.
OFDM(void)
Empty constructor.