root / gnuradio-core / src / lib / general / gr_complex_to_xxx.cc @ 4a63bc91
History | View | Annotate | Download (6.2 kB)
| 1 | /* -*- c++ -*- */
|
|---|---|
| 2 | /*
|
| 3 | * Copyright 2004,2008,2010 Free Software Foundation, Inc. |
| 4 | * |
| 5 | * This file is part of GNU Radio |
| 6 | * |
| 7 | * GNU Radio is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * GNU Radio is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Radio; see the file COPYING. If not, write to |
| 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H
|
| 24 | #include "config.h" |
| 25 | #endif
|
| 26 | |
| 27 | #include <gr_complex_to_xxx.h> |
| 28 | #include <gr_io_signature.h> |
| 29 | #include <gr_math.h> |
| 30 | |
| 31 | // ----------------------------------------------------------------
|
| 32 | |
| 33 | gr_complex_to_float_sptr |
| 34 | gr_make_complex_to_float (unsigned int vlen) |
| 35 | {
|
| 36 | return gnuradio::get_initial_sptr(new gr_complex_to_float (vlen)); |
| 37 | } |
| 38 | |
| 39 | gr_complex_to_float::gr_complex_to_float (unsigned int vlen) |
| 40 | : gr_sync_block ("complex_to_float",
|
| 41 | gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen), |
| 42 | gr_make_io_signature (1, 2, sizeof (float) * vlen)), |
| 43 | d_vlen(vlen) |
| 44 | {
|
| 45 | } |
| 46 | |
| 47 | int
|
| 48 | gr_complex_to_float::work (int noutput_items,
|
| 49 | gr_vector_const_void_star &input_items, |
| 50 | gr_vector_void_star &output_items) |
| 51 | {
|
| 52 | const gr_complex *in = (const gr_complex *) input_items[0]; |
| 53 | float *out0 = (float *) output_items[0]; |
| 54 | float* out1;
|
| 55 | int noi = noutput_items * d_vlen;
|
| 56 | |
| 57 | switch (output_items.size ()){
|
| 58 | case 1: |
| 59 | for (int i = 0; i < noi; i++){ |
| 60 | out0[i] = in[i].real (); |
| 61 | } |
| 62 | break;
|
| 63 | |
| 64 | case 2: |
| 65 | out1 = (float *) output_items[1]; |
| 66 | for (int i = 0; i < noi; i++){ |
| 67 | out0[i] = in[i].real (); |
| 68 | out1[i] = in[i].imag (); |
| 69 | } |
| 70 | break;
|
| 71 | |
| 72 | default:
|
| 73 | abort (); |
| 74 | } |
| 75 | |
| 76 | return noutput_items;
|
| 77 | } |
| 78 | |
| 79 | // ----------------------------------------------------------------
|
| 80 | |
| 81 | gr_complex_to_real_sptr |
| 82 | gr_make_complex_to_real (unsigned int vlen) |
| 83 | {
|
| 84 | return gnuradio::get_initial_sptr(new gr_complex_to_real (vlen)); |
| 85 | } |
| 86 | |
| 87 | gr_complex_to_real::gr_complex_to_real (unsigned int vlen) |
| 88 | : gr_sync_block ("complex_to_real",
|
| 89 | gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen), |
| 90 | gr_make_io_signature (1, 1, sizeof (float) * vlen)), |
| 91 | d_vlen(vlen) |
| 92 | {
|
| 93 | } |
| 94 | |
| 95 | int
|
| 96 | gr_complex_to_real::work (int noutput_items,
|
| 97 | gr_vector_const_void_star &input_items, |
| 98 | gr_vector_void_star &output_items) |
| 99 | {
|
| 100 | const gr_complex *in = (const gr_complex *) input_items[0]; |
| 101 | float *out = (float *) output_items[0]; |
| 102 | int noi = noutput_items * d_vlen;
|
| 103 | |
| 104 | for (int i = 0; i < noi; i++){ |
| 105 | out[i] = in[i].real (); |
| 106 | } |
| 107 | return noutput_items;
|
| 108 | } |
| 109 | |
| 110 | // ----------------------------------------------------------------
|
| 111 | |
| 112 | gr_complex_to_imag_sptr |
| 113 | gr_make_complex_to_imag (unsigned int vlen) |
| 114 | {
|
| 115 | return gnuradio::get_initial_sptr(new gr_complex_to_imag (vlen)); |
| 116 | } |
| 117 | |
| 118 | gr_complex_to_imag::gr_complex_to_imag (unsigned int vlen) |
| 119 | : gr_sync_block ("complex_to_imag",
|
| 120 | gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen), |
| 121 | gr_make_io_signature (1, 1, sizeof (float) * vlen)), |
| 122 | d_vlen(vlen) |
| 123 | {
|
| 124 | } |
| 125 | |
| 126 | int
|
| 127 | gr_complex_to_imag::work (int noutput_items,
|
| 128 | gr_vector_const_void_star &input_items, |
| 129 | gr_vector_void_star &output_items) |
| 130 | {
|
| 131 | const gr_complex *in = (const gr_complex *) input_items[0]; |
| 132 | float *out = (float *) output_items[0]; |
| 133 | int noi = noutput_items * d_vlen;
|
| 134 | |
| 135 | for (int i = 0; i < noi; i++){ |
| 136 | out[i] = in[i].imag (); |
| 137 | } |
| 138 | return noutput_items;
|
| 139 | } |
| 140 | |
| 141 | // ----------------------------------------------------------------
|
| 142 | |
| 143 | gr_complex_to_mag_sptr |
| 144 | gr_make_complex_to_mag (unsigned int vlen) |
| 145 | {
|
| 146 | return gnuradio::get_initial_sptr(new gr_complex_to_mag (vlen)); |
| 147 | } |
| 148 | |
| 149 | gr_complex_to_mag::gr_complex_to_mag (unsigned int vlen) |
| 150 | : gr_sync_block ("complex_to_mag",
|
| 151 | gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen), |
| 152 | gr_make_io_signature (1, 1, sizeof (float) * vlen)), |
| 153 | d_vlen(vlen) |
| 154 | {
|
| 155 | } |
| 156 | |
| 157 | int
|
| 158 | gr_complex_to_mag::work (int noutput_items,
|
| 159 | gr_vector_const_void_star &input_items, |
| 160 | gr_vector_void_star &output_items) |
| 161 | {
|
| 162 | const gr_complex *in = (const gr_complex *) input_items[0]; |
| 163 | float *out = (float *) output_items[0]; |
| 164 | int noi = noutput_items * d_vlen;
|
| 165 | |
| 166 | for (int i = 0; i < noi; i++){ |
| 167 | out[i] = std::abs (in[i]); |
| 168 | } |
| 169 | return noutput_items;
|
| 170 | } |
| 171 | |
| 172 | // ----------------------------------------------------------------
|
| 173 | |
| 174 | gr_complex_to_mag_squared_sptr |
| 175 | gr_make_complex_to_mag_squared (unsigned int vlen) |
| 176 | {
|
| 177 | return gnuradio::get_initial_sptr(new gr_complex_to_mag_squared (vlen)); |
| 178 | } |
| 179 | |
| 180 | gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen) |
| 181 | : gr_sync_block ("complex_to_mag_squared",
|
| 182 | gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen), |
| 183 | gr_make_io_signature (1, 1, sizeof (float) * vlen)), |
| 184 | d_vlen(vlen) |
| 185 | {
|
| 186 | } |
| 187 | |
| 188 | int
|
| 189 | gr_complex_to_mag_squared::work (int noutput_items,
|
| 190 | gr_vector_const_void_star &input_items, |
| 191 | gr_vector_void_star &output_items) |
| 192 | {
|
| 193 | const gr_complex *in = (const gr_complex *) input_items[0]; |
| 194 | float *out = (float *) output_items[0]; |
| 195 | int noi = noutput_items * d_vlen;
|
| 196 | |
| 197 | for (int i = 0; i < noi; i++){ |
| 198 | const float __x = in[i].real(); |
| 199 | const float __y = in[i].imag(); |
| 200 | out[i] = __x * __x + __y * __y; |
| 201 | } |
| 202 | return noutput_items;
|
| 203 | } |
| 204 | |
| 205 | // ----------------------------------------------------------------
|
| 206 | |
| 207 | gr_complex_to_arg_sptr |
| 208 | gr_make_complex_to_arg (unsigned int vlen) |
| 209 | {
|
| 210 | return gnuradio::get_initial_sptr(new gr_complex_to_arg (vlen)); |
| 211 | } |
| 212 | |
| 213 | gr_complex_to_arg::gr_complex_to_arg (unsigned int vlen) |
| 214 | : gr_sync_block ("complex_to_arg",
|
| 215 | gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen), |
| 216 | gr_make_io_signature (1, 1, sizeof (float) * vlen)), |
| 217 | d_vlen(vlen) |
| 218 | {
|
| 219 | } |
| 220 | |
| 221 | int
|
| 222 | gr_complex_to_arg::work (int noutput_items,
|
| 223 | gr_vector_const_void_star &input_items, |
| 224 | gr_vector_void_star &output_items) |
| 225 | {
|
| 226 | const gr_complex *in = (const gr_complex *) input_items[0]; |
| 227 | float *out = (float *) output_items[0]; |
| 228 | int noi = noutput_items * d_vlen;
|
| 229 | |
| 230 | for (int i = 0; i < noi; i++){ |
| 231 | // out[i] = std::arg (in[i]);
|
| 232 | out[i] = gr_fast_atan2f(in[i]); |
| 233 | } |
| 234 | return noutput_items;
|
| 235 | } |