A library with SDR DSP primitives
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.5 KiB

* cxvec_math.h
* Complex vectors math and signal processing
* Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
* All Rights Reserved
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
/*! \defgroup cxvec_math Complex vectors math and signal processing
* \ingroup cxvec
* @{
/*! \file cxvec_math.h
* \brief Osmocom Complex vectors math header
#include <complex.h>
#include <math.h>
#include <osmocom/dsp/cxvec.h>
/* Generic math stuff */
#define M_PIf (3.14159265358979323846264338327f) /*!< \brief PI value float */
/*! \brief Unnormalized sinc function
* \param[in] x Value for which to compute the sinc function.
* \returns The sinc(x) value
* The function is defined as \f$\frac{\sin(x)}{x}\f$
static inline float
osmo_sinc(float x)
if ((x >= 0.01f) || (x <= -0.01f)) return (sinf(x)/x);
return 1.0f;
/*! \brief Squared norm of a given complex
* \param[in] c Complex number for which to compute the squared norm
* \returns \f$|c|^2\f$
static inline float
osmo_normsqf(float complex c)
return crealf(c) * crealf(c) + cimagf(c) * cimagf(c);
/* Complex vector math */
struct osmo_cxvec *
osmo_cxvec_scale(struct osmo_cxvec *in, float complex scale,
struct osmo_cxvec *out);
struct osmo_cxvec *
osmo_cxvec_rotate(struct osmo_cxvec *in, float freq_shift,
struct osmo_cxvec *out);
/*! \brief Various possible types of convolution span */
enum osmo_cxvec_conv_type {
/*! \brief Full span (every possible overlap of f onto g) */
/*! \brief Every possible full overlap of f onto g */
/*! \brief Center f sequence on every g sample */
struct osmo_cxvec *
osmo_cxvec_convolve(struct osmo_cxvec *f, struct osmo_cxvec *g,
enum osmo_cxvec_conv_type type, struct osmo_cxvec *out);
struct osmo_cxvec *
osmo_cxvec_correlate(struct osmo_cxvec *f, struct osmo_cxvec *g, int g_corr_step,
struct osmo_cxvec *out);
float complex
osmo_cxvec_interpolate_point(struct osmo_cxvec *cv, float pos);
/*! \brief Various possible peak finding algorithms */
enum osmo_cxvec_peak_alg {
/*! \brief Weigthed position for the max pwr window */
/*! \brief Weighted position of the peak centered window */
/*! \brief Early-Late balancing around peak */
osmo_cxvec_peak_energy_find(struct osmo_cxvec *cv, int win_size,
enum osmo_cxvec_peak_alg alg,
float complex *peak_val_p);
struct osmo_cxvec *
osmo_cxvec_sig_normalize(struct osmo_cxvec *sig, int decim, float freq_shift,
struct osmo_cxvec *out);
/*! @} */
#endif /* __OSMO_DSP_CXVEC_MATH_H__ */