libosmodsp: include/osmocom/dsp/cxvec_math.h Source File

libosmodsp 0.4.0.12-f6f4 Osmocom DSP library

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)
53static inline float
54osmo_sinc(float x)
55{
56 if ((x >= 0.01f) || (x <= -0.01f)) return (sinf(x)/x);
57 return 1.0f;
58}
59
64static inline float
65osmo_normsqf(float complex c)
66{
67 return crealf(c) * crealf(c) + cimagf(c) * cimagf(c);
68}
69
70
71 /* Complex vector math */
72
73struct osmo_cxvec *
74 osmo_cxvec_scale(const struct osmo_cxvec *in, float complex scale,
75 struct osmo_cxvec *out);
76
77struct osmo_cxvec *
78 osmo_cxvec_rotate(const struct osmo_cxvec *in, float freq_shift,
79 struct osmo_cxvec *out);
80
81struct osmo_cxvec *
82 osmo_cxvec_delay(const struct osmo_cxvec *v, float delay,
83 struct osmo_cxvec *out);
84
86 enum osmo_cxvec_conv_type {
88 CONV_FULL_SPAN,
90 CONV_OVERLAP_ONLY,
92 CONV_NO_DELAY,
93};
94
95struct 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
99struct 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
103float complex
104 osmo_cxvec_interpolate_point(const struct osmo_cxvec *cv, float pos);
105
106int
107 osmo_cxvec_peaks_scan(const struct osmo_cxvec *cv, int *peaks_idx, int N);
108
110 enum osmo_cxvec_peak_alg {
112 PEAK_WEIGH_WIN,
114 PEAK_WEIGH_WIN_CENTER,
116 PEAK_EARLY_LATE,
117};
118
119float
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
124struct 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__ */
cxvec.h
Osmocom Complex vectors header.
osmo_normsqf
static float osmo_normsqf(float complex c)
Squared norm of a given complex.
Definition: cxvec_math.h:65
osmo_cxvec_conv_type
osmo_cxvec_conv_type
Various possible types of convolution span.
Definition: cxvec_math.h:86
osmo_cxvec_convolve
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
osmo_cxvec_sig_normalize
struct osmo_cxvec * osmo_cxvec_sig_normalize(const struct osmo_cxvec *sig, int decim, float freq_shift, struct osmo_cxvec *out)
'Normalize' an IQ signal and apply decimation/frequency shift
Definition: cxvec_math.c:613
osmo_cxvec_rotate
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
osmo_cxvec_peak_energy_find
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_sinc
static float osmo_sinc(float x)
Unnormalized sinc function.
Definition: cxvec_math.h:54
osmo_cxvec_scale
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
osmo_cxvec_peak_alg
osmo_cxvec_peak_alg
Various possible peak finding algorithms.
Definition: cxvec_math.h:110
osmo_cxvec_correlate
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
osmo_cxvec_delay
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
osmo_cxvec_interpolate_point
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
osmo_cxvec_peaks_scan
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
CONV_NO_DELAY
@ CONV_NO_DELAY
Center f sequence on every g sample.
Definition: cxvec_math.h:92
CONV_OVERLAP_ONLY
@ CONV_OVERLAP_ONLY
Every possible full overlap of f onto g.
Definition: cxvec_math.h:90
CONV_FULL_SPAN
@ CONV_FULL_SPAN
Full span (every possible overlap of f onto g)
Definition: cxvec_math.h:88
PEAK_EARLY_LATE
@ PEAK_EARLY_LATE
Early-Late balancing around peak.
Definition: cxvec_math.h:116
PEAK_WEIGH_WIN_CENTER
@ PEAK_WEIGH_WIN_CENTER
Weighted position of the peak centered window.
Definition: cxvec_math.h:114
PEAK_WEIGH_WIN
@ PEAK_WEIGH_WIN
Weigthed position for the max pwr window.
Definition: cxvec_math.h:112
osmo_cxvec
Complex vector.
Definition: cxvec.h:41