aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2011-10-15 00:28:48 +0200
committerSylvain Munaut <tnt@246tNt.com>2011-10-15 16:53:51 +0200
commit7c73e82a2b2d94854267a54a49bf119998982fff (patch)
treed29fda322aa935d776a0039da1b687f58f8fbed8 /include
parent2276f58368f44a19fb5fb5a8274f444e89221c87 (diff)
Initial import of the actual sources/headers
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'include')
-rw-r--r--include/osmocom/sdr/cfile.h50
-rw-r--r--include/osmocom/sdr/cxvec.h67
-rw-r--r--include/osmocom/sdr/cxvec_math.h123
3 files changed, 240 insertions, 0 deletions
diff --git a/include/osmocom/sdr/cfile.h b/include/osmocom/sdr/cfile.h
new file mode 100644
index 0000000..58c65c5
--- /dev/null
+++ b/include/osmocom/sdr/cfile.h
@@ -0,0 +1,50 @@
+/*
+ * cfile.h
+ *
+ * Helpers to read .cfile (complex samples from gnuradio)
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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.
+ */
+
+#ifndef __OSMO_SDR_CFILE_H__
+#define __OSMO_SDR_CFILE_H__
+
+/*! \defgroup cfile .cfile helpers
+ * @{
+ */
+
+/*! \file cfile.h
+ * \brief Osmocom .cfile helpers header
+ */
+
+#include <complex.h>
+
+/*! \brief Structure representing a currently mapped .cfile */
+struct cfile {
+ float complex *data; /*!< \brief Data array (read only !) */
+ unsigned int len; /*!< \brief Length (in samples) of the data */
+ size_t _blen; /*!< \brief Length (in bytes) of the data */
+};
+
+struct cfile *cfile_load(const char *filename);
+void cfile_release(struct cfile *cf);
+
+/*! }@ */
+
+#endif /* __OSMO_SDR_CFILE_H__ */
diff --git a/include/osmocom/sdr/cxvec.h b/include/osmocom/sdr/cxvec.h
new file mode 100644
index 0000000..284d161
--- /dev/null
+++ b/include/osmocom/sdr/cxvec.h
@@ -0,0 +1,67 @@
+/*
+ * cxvec.h
+ *
+ * Complex vectors handling
+ *
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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.
+ */
+
+#ifndef __OSMO_SDR_CXVEC_H__
+#define __OSMO_SDR_CXVEC_H__
+
+/*! \defgroup cxvec Complex vectors
+ * @{
+ */
+
+/*! \file cxvec.h
+ * \brief Osmocom Complex vectors header
+ */
+
+#include <complex.h>
+
+#define CXVEC_FLG_REAL_ONLY (1<<0) /*!< \brief Real values only */
+
+/*! \brief Complex vector */
+struct osmo_cxvec {
+ int len; /*!< \brief Valid length */
+ int max_len; /*!< \brief Maximum length in data field */
+ int flags; /*!< \brief Flags, see CXVEC_FLG_xxx */
+ float complex *data; /*!< \brief Data field */
+ float complex _data[0]; /*!< \brief Optional inline data array */
+};
+
+void
+osmo_cxvec_init_from_data(struct osmo_cxvec *cv,
+ float complex *data, int len);
+
+struct osmo_cxvec *
+osmo_cxvec_alloc_from_data(float complex *data, int len);
+
+struct osmo_cxvec *
+osmo_cxvec_alloc(int max_len);
+
+void
+osmo_cxvec_free(struct osmo_cxvec *cv);
+
+void
+osmo_cxvec_dbg_dump(struct osmo_cxvec *cv, const char *fname);
+
+/*! }@ */
+
+#endif /* __OSMO_SDR_CXVEC_H__ */
diff --git a/include/osmocom/sdr/cxvec_math.h b/include/osmocom/sdr/cxvec_math.h
new file mode 100644
index 0000000..adf3657
--- /dev/null
+++ b/include/osmocom/sdr/cxvec_math.h
@@ -0,0 +1,123 @@
+/*
+ * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * 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.
+ */
+
+#ifndef __OSMO_SDR_CXVEC_MATH_H__
+#define __OSMO_SDR_CXVEC_MATH_H__
+
+/*! \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/sdr/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) */
+ CONV_FULL_SPAN,
+ /*! \brief Every possible full overlap of f onto g */
+ CONV_OVERLAP_ONLY,
+ /*! \brief Center f sequence on every g sample */
+ CONV_NO_DELAY,
+};
+
+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 */
+ PEAK_WEIGH_WIN,
+ /*! \brief Weighted position of the peak centered window */
+ PEAK_WEIGH_WIN_CENTER,
+ /*! \brief Early-Late balancing around peak */
+ PEAK_EARLY_LATE,
+};
+
+float
+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_SDR_CXVEC_MATH_H__ */