14 const double PI = 3.14159265358979323846;
15 const double PI_2 = 6.28318530717958647692;
21 arma_inline
double sinc(
double x)
26 return std::sin(PI * x) / (PI * x);
33 arma_inline arma::vec
sinc(
const arma::vec &x)
37 for (
unsigned int n = 0; n < out.size(); 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);
67 template <
typename T>
double angle(
const std::complex<T> &x)
76 arma_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));
89 arma_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));
103 arma_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);
133 arma_inline arma::vec
timevec(
const int N,
const double Fs)
135 return arma::regspace(0, N - 1.0) / Fs;
143 template <
typename T> arma::Col<T>
fftshift(
const arma::Col<T> &Pxx)
145 arma::Col<T> x(Pxx.n_elem);
146 x = shift(Pxx, floor(Pxx.n_elem / 2));
155 template <
typename T> arma::Col<T>
ifftshift(
const arma::Col<T> &Pxx)
157 arma::Col<T> x(Pxx.n_elem);
158 x = shift(Pxx, -ceil(Pxx.n_elem / 2));
167 template <
typename T> arma::Mat<T>
fftshift(
const arma::Mat<T> &Pxx)
169 arma::uword R = Pxx.n_rows;
170 arma::uword C = Pxx.n_cols;
171 arma::Mat<T> x(R, C);
172 x = arma::shift(Pxx, static_cast<arma::sword>(floor(R / 2)), 0);
173 x = arma::shift(x, static_cast<arma::sword>(floor(C / 2)), 1);
182 template <
typename T> arma::Mat<T>
ifftshift(
const arma::Mat<T> &Pxx)
184 arma::uword R = Pxx.n_rows;
185 arma::uword C = Pxx.n_cols;
186 arma::Mat<T> x(R, C);
187 x = shift(Pxx, -ceil(R / 2), 0);
188 x = shift(x, -ceil(C / 2), 1);
213 #define err_handler(msg) \ 215 std::cout << "SigPack Error [" << __FILE__ << "@" << __LINE__ \ 216 << "]: " << msg << std::endl; \ 218 exit(EXIT_FAILURE); \ 224 #define wrn_handler(msg) \ 226 std::cout << "SigPack warning [" << __FILE__ << "@" << __LINE__ \ 227 << "]: " << msg << std::endl; \ arma_inline double sinc(double x)
A sinc, sin(x)/x, function.
double angle(const std::complex< T > &x)
Calculates angle in radians for complex input.
arma::Col< T > ifftshift(const arma::Col< T > &Pxx)
1D FFT inverse/reverse shift.
arma_inline std::string sp_version(void)
SigPack version string.
arma_inline arma::vec unwrap(const arma::vec &x)
Unwraps the angle vector x, accumulates phase.
arma_inline double besseli0(double x)
Modified first kind bessel function order zero.
arma_inline arma::vec timevec(const int N, const double Fs)
Generates a linear time vector with specified sample rate. Delta time=1/Fs.
arma::Col< T > fftshift(const arma::Col< T > &Pxx)
1D FFT shift.
const double PI
... or use arma::datum::pi