3 * Copyright 2004,2008 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
27 #include <gr_complex_to_xxx.h>
28 #include <gr_io_signature.h>
31 // ----------------------------------------------------------------
33 gr_complex_to_float_sptr
34 gr_make_complex_to_float (unsigned int vlen)
36 return gr_complex_to_float_sptr (new gr_complex_to_float (vlen));
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)),
48 gr_complex_to_float::work (int noutput_items,
49 gr_vector_const_void_star &input_items,
50 gr_vector_void_star &output_items)
52 const gr_complex *in = (const gr_complex *) input_items[0];
53 float *out0 = (float *) output_items[0];
55 int noi = noutput_items * d_vlen;
57 switch (output_items.size ()){
59 for (int i = 0; i < noi; i++){
60 out0[i] = in[i].real ();
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 ();
79 // ----------------------------------------------------------------
81 gr_complex_to_real_sptr
82 gr_make_complex_to_real (unsigned int vlen)
84 return gr_complex_to_real_sptr (new gr_complex_to_real (vlen));
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)),
96 gr_complex_to_real::work (int noutput_items,
97 gr_vector_const_void_star &input_items,
98 gr_vector_void_star &output_items)
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;
104 for (int i = 0; i < noi; i++){
105 out[i] = in[i].real ();
107 return noutput_items;
110 // ----------------------------------------------------------------
112 gr_complex_to_imag_sptr
113 gr_make_complex_to_imag (unsigned int vlen)
115 return gr_complex_to_imag_sptr (new gr_complex_to_imag (vlen));
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)),
127 gr_complex_to_imag::work (int noutput_items,
128 gr_vector_const_void_star &input_items,
129 gr_vector_void_star &output_items)
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;
135 for (int i = 0; i < noi; i++){
136 out[i] = in[i].imag ();
138 return noutput_items;
141 // ----------------------------------------------------------------
143 gr_complex_to_mag_sptr
144 gr_make_complex_to_mag (unsigned int vlen)
146 return gr_complex_to_mag_sptr (new gr_complex_to_mag (vlen));
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)),
158 gr_complex_to_mag::work (int noutput_items,
159 gr_vector_const_void_star &input_items,
160 gr_vector_void_star &output_items)
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;
166 for (int i = 0; i < noi; i++){
167 out[i] = std::abs (in[i]);
169 return noutput_items;
172 // ----------------------------------------------------------------
174 gr_complex_to_mag_squared_sptr
175 gr_make_complex_to_mag_squared (unsigned int vlen)
177 return gr_complex_to_mag_squared_sptr (new gr_complex_to_mag_squared (vlen));
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)),
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)
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;
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;
202 return noutput_items;
205 // ----------------------------------------------------------------
207 gr_complex_to_arg_sptr
208 gr_make_complex_to_arg (unsigned int vlen)
210 return gr_complex_to_arg_sptr (new gr_complex_to_arg (vlen));
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)),
222 gr_complex_to_arg::work (int noutput_items,
223 gr_vector_const_void_star &input_items,
224 gr_vector_void_star &output_items)
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;
230 for (int i = 0; i < noi; i++){
231 // out[i] = std::arg (in[i]);
232 out[i] = gr_fast_atan2f(in[i]);
234 return noutput_items;