From: jcorgan Date: Sat, 12 Apr 2008 20:03:11 +0000 (+0000) Subject: Addes gr.cpfsk_bc(), a continuous phase frequency shift keying modulator block. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;ds=sidebyside;h=ccea950c146d2f724fb37f18e27fc2857d191cfe;hp=92c6303550042adc00a33801cb9f5650009f3877;p=debian%2Fgnuradio Addes gr.cpfsk_bc(), a continuous phase frequency shift keying modulator block. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8193 221aa14e-8319-0410-a670-987f0aec2ac5 --- diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am index ef5354cf..5a12a739 100644 --- a/gnuradio-core/src/lib/general/Makefile.am +++ b/gnuradio-core/src/lib/general/Makefile.am @@ -55,6 +55,7 @@ libgeneral_la_SOURCES = \ gr_correlate_access_code_bb.cc \ gr_costas_loop_cc.cc \ gr_count_bits.cc \ + gr_cpfsk_bc.cc \ gr_crc32.cc \ gr_ctcss_squelch_ff.cc \ gr_dd_mpsk_sync_cc.cc \ @@ -197,7 +198,8 @@ grinclude_HEADERS = \ gr_correlate_access_code_bb.h \ gr_costas_loop_cc.h \ gr_count_bits.h \ - gr_crc32.h \ + gr_cpfsk_bc.h \ + gr_crc32.h \ gr_ctcss_squelch_ff.h \ gr_dd_mpsk_sync_cc.h \ gr_diff_decoder_bb.h \ @@ -352,6 +354,7 @@ swiginclude_HEADERS = \ gr_constellation_decoder_cb.i \ gr_correlate_access_code_bb.i \ gr_costas_loop_cc.i \ + gr_cpfsk_bc.i \ gr_crc32.i \ gr_ctcss_squelch_ff.i \ gr_dd_mpsk_sync_cc.i \ diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 64aa2d88..724ea031 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2005,2006,2007 Free Software Foundation, Inc. + * Copyright 2004,2005,2006,2007,2008 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -130,6 +130,7 @@ #include #include #include +#include %} %include "gr_nop.i" @@ -240,3 +241,4 @@ %include "gr_glfsr_source_f.i" %include "gr_peak_detector2_fb.i" %include "gr_repeat.i" +%include "gr_cpfsk_bc.i" diff --git a/gnuradio-core/src/lib/general/gr_cpfsk_bc.cc b/gnuradio-core/src/lib/general/gr_cpfsk_bc.cc new file mode 100644 index 00000000..95d7c175 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_cpfsk_bc.cc @@ -0,0 +1,78 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * GNU Radio 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 3, or (at your option) + * any later version. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#define M_TWOPI (2*M_PI) + +gr_cpfsk_bc_sptr +gr_make_cpfsk_bc(float k, float ampl, int samples_per_sym) +{ + return gr_cpfsk_bc_sptr(new gr_cpfsk_bc(k, ampl, samples_per_sym)); +} + +gr_cpfsk_bc::gr_cpfsk_bc(float k, float ampl, int samples_per_sym) + : gr_sync_interpolator("cpfsk_bc", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(1, 1, sizeof(gr_complex)), + samples_per_sym) +{ + d_samples_per_sym = samples_per_sym; + d_freq = k*M_PI/samples_per_sym; + d_ampl = ampl; + d_phase = 0.0; +} + +gr_cpfsk_bc::~gr_cpfsk_bc() +{ +} + +int +gr_cpfsk_bc::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char *in = (const char *)input_items[0]; + gr_complex *out = (gr_complex *)output_items[0]; + + for (int i = 0; i < noutput_items/d_samples_per_sym; i++) { + for (int j = 0; j < d_samples_per_sym; j++) { + if (in[i] == 1) + d_phase += d_freq; + else + d_phase -= d_freq; + + while (d_phase > M_TWOPI) + d_phase -= M_TWOPI; + while (d_phase < -M_TWOPI) + d_phase += M_TWOPI; + + *out++ = gr_expj(d_phase)*d_ampl; + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_cpfsk_bc.h b/gnuradio-core/src/lib/general/gr_cpfsk_bc.h new file mode 100644 index 00000000..38429543 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_cpfsk_bc.h @@ -0,0 +1,63 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * GNU Radio 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 3, or (at your option) + * any later version. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ +#ifndef INCLUDED_GR_CPFSK_BC_H +#define INCLUDED_GR_CPFSK_BC_H + +#include + +class gr_cpfsk_bc; + +typedef boost::shared_ptr gr_cpfsk_bc_sptr; + +gr_cpfsk_bc_sptr gr_make_cpfsk_bc(float k, float ampl, int samples_per_sym); + +/*! + * \brief Perform continuous phase 2-level frequncy modulation on an input stream + * of unpacked bits. + * \ingroup modulation + * + * \param k modulation index + * \param ampl output amplitude + * \param samples_per_sym number of output samples per input bit + */ + +class gr_cpfsk_bc : public gr_sync_interpolator +{ +private: + friend gr_cpfsk_bc_sptr gr_make_cpfsk_bc(float k, float ampl, int samples_per_sym); + + gr_cpfsk_bc(float k, float ampl, int samples_per_sym); + + int d_samples_per_sym; // Samples per symbol, square pulse + float d_freq; // Modulation index*pi/samples_per_sym + float d_ampl; // Output amplitude + float d_phase; // Current phase + + public: + ~gr_cpfsk_bc(); + + void set_amplitude(float amplitude) { d_ampl = amplitude; } + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_CPFSK_BC_H */ diff --git a/gnuradio-core/src/lib/general/gr_cpfsk_bc.i b/gnuradio-core/src/lib/general/gr_cpfsk_bc.i new file mode 100644 index 00000000..918766a6 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_cpfsk_bc.i @@ -0,0 +1,34 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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 3, or (at your option) + * any later version. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,cpfsk_bc); + +gr_cpfsk_bc_sptr gr_make_cpfsk_bc(float k, float ampl, int samples_per_sym); + +class gr_cpfsk_bc : public gr_sync_interpolator +{ +private: + gr_cpfsk_bc(float k, float ampl, int samples_per_sym); + +public: + void set_amplitude(float amplitude); +};