GNU Radio's TEST Package
cxvec_math.h
Go to the documentation of this file.
1 /*
2  * cxvec_math.h
3  *
4  * Complex vectors math and signal processing
5  *
6  * Copyright (C) 2011 Sylvain Munaut <tnt@246tNt.com>
7  *
8  * All Rights Reserved
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24 
25 #ifndef __OSMO_DSP_CXVEC_MATH_H__
26 #define __OSMO_DSP_CXVEC_MATH_H__
27 
28 /*! \defgroup cxvec_math Complex vectors math and signal processing
29  * \ingroup cxvec
30  * @{
31  */
32 
33 /*! \file cxvec_math.h
34  * \brief Osmocom Complex vectors math header
35  */
36 
37 #include <complex.h>
38 #include <math.h>
39 
40 #include <osmocom/dsp/cxvec.h>
41 
42 
43  /* Generic math stuff */
44 
45 #define M_PIf (3.14159265358979323846264338327f) /*!< \brief PI value float */
46 
47 /*! \brief Unnormalized sinc function
48  * \param[in] x Value for which to compute the sinc function.
49  * \returns The sinc(x) value
50  *
51  * The function is defined as \f$\frac{\sin(x)}{x}\f$
52  */
53 static inline float
54 osmo_sinc(float x)
55 {
56  if ((x >= 0.01f) || (x <= -0.01f)) return (sinf(x)/x);
57  return 1.0f;
58 }
59 
60 /*! \brief Squared norm of a given complex
61  * \param[in] c Complex number for which to compute the squared norm
62  * \returns \f$|c|^2\f$
63  */
64 static inline float
65 osmo_normsqf(float complex c)
66 {
67  return crealf(c) * crealf(c) + cimagf(c) * cimagf(c);
68 }
69 
70 
71  /* Complex vector math */
72 
73 struct osmo_cxvec *
74 osmo_cxvec_scale(const struct osmo_cxvec *in, float complex scale,
75  struct osmo_cxvec *out);
76 
77 struct osmo_cxvec *
78 osmo_cxvec_rotate(const struct osmo_cxvec *in, float freq_shift,
79  struct osmo_cxvec *out);
80 
81 struct osmo_cxvec *
82 osmo_cxvec_delay(const struct osmo_cxvec *v, float delay,
83  struct osmo_cxvec *out);
84 
85 /*! \brief Various possible types of convolution span */
87  /*! \brief Full span (every possible overlap of f onto g) */
89  /*! \brief Every possible full overlap of f onto g */
91  /*! \brief Center f sequence on every g sample */
93 };
94 
95 struct osmo_cxvec *
96 osmo_cxvec_convolve(const struct osmo_cxvec *f, const struct osmo_cxvec *g,
97  enum osmo_cxvec_conv_type type, struct osmo_cxvec *out);
98 
99 struct osmo_cxvec *
100 osmo_cxvec_correlate(const struct osmo_cxvec *f, const struct osmo_cxvec *g,
101  int g_corr_step, struct osmo_cxvec *out);
102 
103 float complex
104 osmo_cxvec_interpolate_point(const struct osmo_cxvec *cv, float pos);
105 
106 int
107 osmo_cxvec_peaks_scan(const struct osmo_cxvec *cv, int *peaks_idx, int N);
108 
109 /*! \brief Various possible peak finding algorithms */
111  /*! \brief Weigthed position for the max pwr window */
113  /*! \brief Weighted position of the peak centered window */
115  /*! \brief Early-Late balancing around peak */
117 };
118 
119 float
120 osmo_cxvec_peak_energy_find(const struct osmo_cxvec *cv, int win_size,
121  enum osmo_cxvec_peak_alg alg,
122  float complex *peak_val_p);
123 
124 struct osmo_cxvec *
126  int decim, float freq_shift,
127  struct osmo_cxvec *out);
128 
129 /*! @} */
130 
131 #endif /* __OSMO_DSP_CXVEC_MATH_H__ */
Osmocom Complex vectors header.
static float osmo_normsqf(float complex c)
Squared norm of a given complex.
Definition: cxvec_math.h:65
osmo_cxvec_conv_type
Various possible types of convolution span.
Definition: cxvec_math.h:86
struct osmo_cxvec * osmo_cxvec_delay(const struct osmo_cxvec *v, float delay, struct osmo_cxvec *out)
float osmo_cxvec_peak_energy_find(const struct osmo_cxvec *cv, int win_size, enum osmo_cxvec_peak_alg alg, float complex *peak_val_p)
static float osmo_sinc(float x)
Unnormalized sinc function.
Definition: cxvec_math.h:54
osmo_cxvec_peak_alg
Various possible peak finding algorithms.
Definition: cxvec_math.h:110
struct osmo_cxvec * osmo_cxvec_convolve(const struct osmo_cxvec *f, const struct osmo_cxvec *g, enum osmo_cxvec_conv_type type, struct osmo_cxvec *out)
struct osmo_cxvec * osmo_cxvec_scale(const struct osmo_cxvec *in, float complex scale, struct osmo_cxvec *out)
float complex osmo_cxvec_interpolate_point(const struct osmo_cxvec *cv, float pos)
int osmo_cxvec_peaks_scan(const struct osmo_cxvec *cv, int *peaks_idx, int N)
struct osmo_cxvec * osmo_cxvec_sig_normalize(const struct osmo_cxvec *sig, int decim, float freq_shift, struct osmo_cxvec *out)
struct osmo_cxvec * osmo_cxvec_rotate(const struct osmo_cxvec *in, float freq_shift, struct osmo_cxvec *out)
struct osmo_cxvec * osmo_cxvec_correlate(const struct osmo_cxvec *f, const struct osmo_cxvec *g, int g_corr_step, struct osmo_cxvec *out)
@ CONV_NO_DELAY
Center f sequence on every g sample.
Definition: cxvec_math.h:92
@ CONV_OVERLAP_ONLY
Every possible full overlap of f onto g.
Definition: cxvec_math.h:90
@ CONV_FULL_SPAN
Full span (every possible overlap of f onto g)
Definition: cxvec_math.h:88
@ PEAK_EARLY_LATE
Early-Late balancing around peak.
Definition: cxvec_math.h:116
@ PEAK_WEIGH_WIN_CENTER
Weighted position of the peak centered window.
Definition: cxvec_math.h:114
@ PEAK_WEIGH_WIN
Weigthed position for the max pwr window.
Definition: cxvec_math.h:112
Complex vector.
Definition: cxvec.h:41