72 template<
class T1,
class T2,
class T3>
251 template<
class T1,
class T2,
class T3>
256 upsampling_factor = 0;
260 template<
class T1,
class T2,
class T3>
263 set_pulse_shape(impulse_response, upsampling_factor);
266 template<
class T1,
class T2,
class T3>
269 it_error_if(impulse_response_in.
size() == 0,
"Pulse_Shape: impulse response is zero length");
270 it_error_if(upsampling_factor_in < 1,
"Pulse_Shape: incorrect upsampling factor");
272 pulse_length = (impulse_response_in.
size() - 1) / upsampling_factor_in;
273 upsampling_factor = upsampling_factor_in;
275 impulse_response = impulse_response_in;
276 shaping_filter.set_coeffs(impulse_response);
277 shaping_filter.
clear();
281 template<
class T1,
class T2,
class T3>
284 return impulse_response;
287 template<
class T1,
class T2,
class T3>
290 return upsampling_factor;
293 template<
class T1,
class T2,
class T3>
299 template<
class T1,
class T2,
class T3>
302 return impulse_response.size();
305 template<
class T1,
class T2,
class T3>
308 it_assert(setup_done,
"Pulse_Shape must be set up before using");
309 it_error_if(pulse_length == 0,
"Pulse_Shape: impulse response is zero length");
312 if (upsampling_factor > 1)
313 output = shaping_filter(upsample(input, upsampling_factor));
318 template<
class T1,
class T2,
class T3>
321 it_assert(setup_done,
"Pulse_Shape must be set up before using");
323 shape_symbols(input, temp);
327 template<
class T1,
class T2,
class T3>
330 it_assert(setup_done,
"Pulse_Shape must be set up before using");
331 it_error_if(pulse_length == 0,
"Pulse_Shape: impulse response is zero length");
334 if (upsampling_factor > 1)
335 output = shaping_filter(input);
340 template<
class T1,
class T2,
class T3>
343 it_assert(setup_done,
"Pulse_Shape must be set up before using");
345 shape_samples(input, temp);
349 template<
class T1,
class T2,
class T3>
352 it_assert(setup_done,
"Pulse_Shape must be set up before using");
353 shaping_filter.clear();
361 set_pulse_shape(roll_off_factor, filter_length, upsampling_factor);
367 it_error_if(roll_off_factor_in < 0 || roll_off_factor_in > 1,
"Raised_Cosine: roll-off out of range");
368 roll_off_factor = roll_off_factor_in;
374 this->upsampling_factor = upsampling_factor_in;
375 this->pulse_length = filter_length;
376 this->impulse_response.set_size(filter_length * upsampling_factor_in + 1,
379 for (i = 0; i < this->impulse_response.size(); i++) {
381 t = (double)(i - filter_length * upsampling_factor_in / 2)
382 / upsampling_factor_in;
383 den = 1 -
sqr(2 * roll_off_factor * t);
389 this->impulse_response(i) =
sinc(t) *
pi / 4;
392 this->impulse_response(i) =
std::cos(roll_off_factor *
pi * t)
402 this->shaping_filter.set_coeffs(this->impulse_response);
403 this->shaping_filter.clear();
404 this->setup_done =
true;
410 it_assert(this->setup_done,
"Pulse_Shape must be set up before using");
411 return roll_off_factor;
419 set_pulse_shape(roll_off_factor, filter_length, upsampling_factor);
425 it_error_if(roll_off_factor_in <= 0 || roll_off_factor_in > 1,
426 "Root_Raised_Cosine: roll-off out of range");
427 roll_off_factor = roll_off_factor_in;
430 "Root_Raised_Cosine: Filter length not even");
433 double t, num, den, tmp_arg;
434 this->upsampling_factor = upsampling_factor_in;
435 this->pulse_length = filter_length;
436 this->impulse_response.set_size(filter_length * upsampling_factor_in + 1,
439 for (i = 0; i < this->impulse_response.size(); i++) {
441 t = (double)(i - filter_length * upsampling_factor_in / 2)
442 / upsampling_factor_in;
443 den = 1 -
sqr(4 * roll_off_factor * t);
445 this->impulse_response(i) = 1 + (4 * roll_off_factor /
pi)
449 tmp_arg =
pi / (4 * roll_off_factor);
450 this->impulse_response(i) = roll_off_factor /
std::sqrt(2.0)
454 num =
std::sin(
pi * (1 - roll_off_factor) * t)
455 +
std::cos(
pi * (1 + roll_off_factor) * t) * 4 * roll_off_factor * t;
456 this->impulse_response(i) = num / (
pi * t * den);
460 this->impulse_response /=
std::sqrt(
double(upsampling_factor_in));
461 this->shaping_filter.set_coeffs(this->impulse_response);
462 this->shaping_filter.clear();
463 this->setup_done =
true;
469 it_assert(this->setup_done,
"Pulse_Shape must be set up before using");
470 return roll_off_factor;
481 std::complex<double> >;
483 std::complex<double> >;
495 #endif // #ifndef PULSE_SHAPE_H int size() const
The size of the vector.
#define it_error_if(t, s)
Abort if t is true.
Various functions on vectors and matrices - header file.
Root_Raised_Cosine()
Constructor.
Vec< T2 > impulse_response
The impulse resounse of the pulse shaping filter.
void set_pulse_shape(double roll_off_factor, int filter_length=6, int upsampling_factor=8)
Set pulse shape (roll_off_factor between 0 and 1, filter_length even)
void clear(void)
Clear internal states.
Definitions of Filter classes and functions.
bool is_even(int x)
Return true if x is an even integer.
void shape_samples(const Vec< T1 > &input, Vec< T3 > &output)
Shape the input samples already upsampled.
Pulse_Shape()
Constructor.
int upsampling_factor
Samples per input symbol.
double sinc(double x)
Sinc function: sinc(x) = sin(pi*x)/pi*x.
int get_filter_length() const
Get the length of the internal FIR filter.
MA_Filter< T1, T2, T3 > shaping_filter
The pulse shaping filter.
Raised Cosine (RC) Pulse Shaper.
#define it_assert(t, s)
Abort if t is not true.
void set_pulse_shape(const Vec< T2 > &impulse_response, int upsampling_factor)
Set the general impulse response of the FIR filter.
double roll_off_factor
The roll off factor (i.e. alpha)
double roll_off_factor
The roll off factor (i.e. alpha)
vec sin(const vec &x)
Sine function.
double get_roll_off(void) const
Get the roll-off factor.
const double pi
Constant Pi.
virtual ~Raised_Cosine()
Destructor.
Trigonometric and hyperbolic functions - header file.
Moving Average Filter Base Class.This class implements a moving average (MA) filter according to whe...
virtual ~Root_Raised_Cosine()
Destructor.
int get_pulse_length() const
Get the length of the pulse in number of symbols.
virtual ~Pulse_Shape()
Destructor.
bool setup_done
Ensures that setup is called before any other member function.
Resampling functions - header file.
Raised_Cosine()
Constructor.
double get_roll_off(void) const
Get the Roll-off factor.
vec sqr(const cvec &data)
Absolute square of elements.
void shape_symbols(const Vec< T1 > &input, Vec< T3 > &output)
Shape the input symbols performing upsampling.
int pulse_length
Length in symbols.
Vec< T2 > get_pulse_shape(void) const
Get the pulse shape.
vec sqrt(const vec &x)
Square root of the elements.
void clear()
Set the vector to the all zero vector.
int get_upsampling_factor() const
Get the over sampling factor.
void set_pulse_shape(double roll_off_factor, int filter_length=6, int upsampling_factor=8)
Set pulse_shape, roll_off_factor between 0 and 1, filter_length even.
vec cos(const vec &x)
Cosine function.
Templated Vector Class Definitions.
(Square) Root Raised Cosine (RRC) Pulse Shaper