14const double PI = 3.14159265358979323846;
15const double PI_2 = 6.28318530717958647692;
21arma_inline
double sinc(
double x )
26 return std::sin(
PI * x ) / (
PI * x );
33arma_inline arma::vec
sinc(
const arma::vec& x )
37 for(
unsigned int n = 0; n < out.size(); n++ )
39 out( n ) =
sinc( x( n ) );
53 double y = 1.0, s = 1.0, x2 = x * x, n = 1.0;
54 while( s > y * 1.0e-9 )
56 s *= x2 / 4.0 / ( n * n );
67template <
typename T>
double angle(
const std::complex<T>& x )
76arma_inline arma::vec
angle(
const arma::cx_vec& x )
80 for(
unsigned int r = 0; r < x.n_rows; r++ )
81 P( r ) = std::arg( x( r ) );
89arma_inline arma::mat
angle(
const arma::cx_mat& x )
93 for(
unsigned int r = 0; r < x.n_rows; r++ )
94 for(
unsigned int c = 0; c < x.n_cols; c++ )
95 P( r, c ) = std::arg( x( r, c ) );
103arma_inline arma::vec
unwrap(
const arma::vec& x )
106 double pacc = 0, pdiff = 0;
107 const double thr =
PI * 170 / 180;
110 for(
unsigned int r = 1; r < x.n_rows; r++ )
112 pdiff = x( r ) - x( r - 1 );
117 P( r ) = pacc + x( r );
134arma_inline arma::vec
timevec(
const int N,
const double Fs )
136 return arma::regspace( 0, N - 1.0 ) / Fs;
144template <
typename T> arma::Col<T>
fftshift(
const arma::Col<T>& Pxx )
146 arma::Col<T> x( Pxx.n_elem );
147 x = shift( Pxx, floor( Pxx.n_elem / 2 ) );
156template <
typename T> arma::Col<T>
ifftshift(
const arma::Col<T>& Pxx )
158 arma::Col<T> x( Pxx.n_elem );
159 x = shift( Pxx, -ceil( Pxx.n_elem / 2 ) );
168template <
typename T> arma::Mat<T>
fftshift(
const arma::Mat<T>& Pxx )
170 arma::uword R = Pxx.n_rows;
171 arma::uword C = Pxx.n_cols;
172 arma::Mat<T> x( R, C );
173 x = arma::shift( Pxx,
static_cast<arma::sword
>( floor( R / 2 ) ), 0 );
174 x = arma::shift( x,
static_cast<arma::sword
>( floor( C / 2 ) ), 1 );
183template <
typename T> arma::Mat<T>
ifftshift(
const arma::Mat<T>& Pxx )
185 arma::uword R = Pxx.n_rows;
186 arma::uword C = Pxx.n_cols;
187 arma::Mat<T> x( R, C );
188 x = shift( Pxx, -ceil( R / 2 ), 0 );
189 x = shift( x, -ceil( C / 2 ), 1 );
212#define err_handler( msg ) \
214 std::cout << "SigPack Error [" << __FILE__ << "@" << __LINE__ << "]: " << msg << std::endl; \
216 exit( EXIT_FAILURE ); \
222#define wrn_handler( msg ) \
224 std::cout << "SigPack warning [" << __FILE__ << "@" << __LINE__ << "]: " << msg << std::endl; \
arma::Col< T > fftshift(const arma::Col< T > &Pxx)
1D FFT shift.
arma::Col< T > ifftshift(const arma::Col< T > &Pxx)
1D FFT inverse/reverse shift.
arma_inline arma::vec timevec(const int N, const double Fs)
Generates a linear time vector with specified sample rate. Delta time=1/Fs.
const double PI
... or use arma::datum::pi
arma_inline double besseli0(double x)
Modified first kind bessel function order zero.
double angle(const std::complex< T > &x)
Calculates angle in radians for complex input.
arma_inline double sinc(double x)
A sinc, sin(x)/x, function.
arma_inline arma::vec unwrap(const arma::vec &x)
Unwraps the angle vector x, accumulates phase.
arma_inline std::string sp_version(void)
SigPack version string.