libosmodsp  0.4.0.6-1dfd
Osmocom DSP library
All Data Structures Files Functions Variables Enumerations Enumerator Modules
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 
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)
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 
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 
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 
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 *
125 osmo_cxvec_sig_normalize(const struct osmo_cxvec *sig,
126  int decim, float freq_shift,
127  struct osmo_cxvec *out);
128 
131 #endif /* __OSMO_DSP_CXVEC_MATH_H__ */
osmo_cxvec_conv_type
Various possible types of convolution span.
Definition: cxvec_math.h:86
Weighted position of the peak centered window.
Definition: cxvec_math.h:114
Osmocom Complex vectors header.
struct osmo_cxvec * osmo_cxvec_correlate(const struct osmo_cxvec *f, const struct osmo_cxvec *g, int g_corr_step, struct osmo_cxvec *out)
Cross-correlate two complex vectors.
Definition: cxvec_math.c:335
struct osmo_cxvec * osmo_cxvec_rotate(const struct osmo_cxvec *in, float freq_shift, struct osmo_cxvec *out)
Rotate a complex vector (frequency shift)
Definition: cxvec_math.c:112
Full span (every possible overlap of f onto g)
Definition: cxvec_math.h:88
struct osmo_cxvec * osmo_cxvec_scale(const struct osmo_cxvec *in, float complex scale, struct osmo_cxvec *out)
Scale a complex vector (multiply by a constant)
Definition: cxvec_math.c:55
static float osmo_normsqf(float complex c)
Squared norm of a given complex.
Definition: cxvec_math.h:65
int osmo_cxvec_peaks_scan(const struct osmo_cxvec *cv, int *peaks_idx, int N)
Find the index of the N highest energy ( ) peaks.
Definition: cxvec_math.c:438
float complex osmo_cxvec_interpolate_point(const struct osmo_cxvec *cv, float pos)
Interpolate any fractional position in a vector using sinc filtering.
Definition: cxvec_math.c:399
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)
Find the maximum energy ( ) peak in a sequence.
Definition: cxvec_math.c:484
osmo_cxvec_peak_alg
Various possible peak finding algorithms.
Definition: cxvec_math.h:110
struct osmo_cxvec * osmo_cxvec_sig_normalize(const struct osmo_cxvec *sig, int decim, float freq_shift, struct osmo_cxvec *out)
&#39;Normalize&#39; an IQ signal and apply decimation/frequency shift
Definition: cxvec_math.c:613
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)
Convolve two complex vectors.
Definition: cxvec_math.c:228
static float osmo_sinc(float x)
Unnormalized sinc function.
Definition: cxvec_math.h:54
struct osmo_cxvec * osmo_cxvec_delay(const struct osmo_cxvec *v, float delay, struct osmo_cxvec *out)
Fractionally delay a vector while maintaining its length.
Definition: cxvec_math.c:146
Every possible full overlap of f onto g.
Definition: cxvec_math.h:90
Weigthed position for the max pwr window.
Definition: cxvec_math.h:112
Center f sequence on every g sample.
Definition: cxvec_math.h:92
Complex vector.
Definition: cxvec.h:41
Early-Late balancing around peak.
Definition: cxvec_math.h:116