3 * Copyright 2004 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];
54 float *out1 = (float *) output_items[1];
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 for (int i = 0; i < noi; i++){
66 out0[i] = in[i].real ();
67 out1[i] = in[i].imag ();
78 // ----------------------------------------------------------------
80 gr_complex_to_real_sptr
81 gr_make_complex_to_real (unsigned int vlen)
83 return gr_complex_to_real_sptr (new gr_complex_to_real (vlen));
86 gr_complex_to_real::gr_complex_to_real (unsigned int vlen)
87 : gr_sync_block ("complex_to_real",
88 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
89 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
95 gr_complex_to_real::work (int noutput_items,
96 gr_vector_const_void_star &input_items,
97 gr_vector_void_star &output_items)
99 const gr_complex *in = (const gr_complex *) input_items[0];
100 float *out = (float *) output_items[0];
101 int noi = noutput_items * d_vlen;
103 for (int i = 0; i < noi; i++){
104 out[i] = in[i].real ();
106 return noutput_items;
109 // ----------------------------------------------------------------
111 gr_complex_to_imag_sptr
112 gr_make_complex_to_imag (unsigned int vlen)
114 return gr_complex_to_imag_sptr (new gr_complex_to_imag (vlen));
117 gr_complex_to_imag::gr_complex_to_imag (unsigned int vlen)
118 : gr_sync_block ("complex_to_imag",
119 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
120 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
126 gr_complex_to_imag::work (int noutput_items,
127 gr_vector_const_void_star &input_items,
128 gr_vector_void_star &output_items)
130 const gr_complex *in = (const gr_complex *) input_items[0];
131 float *out = (float *) output_items[0];
132 int noi = noutput_items * d_vlen;
134 for (int i = 0; i < noi; i++){
135 out[i] = in[i].imag ();
137 return noutput_items;
140 // ----------------------------------------------------------------
142 gr_complex_to_mag_sptr
143 gr_make_complex_to_mag (unsigned int vlen)
145 return gr_complex_to_mag_sptr (new gr_complex_to_mag (vlen));
148 gr_complex_to_mag::gr_complex_to_mag (unsigned int vlen)
149 : gr_sync_block ("complex_to_mag",
150 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
151 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
157 gr_complex_to_mag::work (int noutput_items,
158 gr_vector_const_void_star &input_items,
159 gr_vector_void_star &output_items)
161 const gr_complex *in = (const gr_complex *) input_items[0];
162 float *out = (float *) output_items[0];
163 int noi = noutput_items * d_vlen;
165 for (int i = 0; i < noi; i++){
166 out[i] = std::abs (in[i]);
168 return noutput_items;
171 // ----------------------------------------------------------------
173 gr_complex_to_mag_squared_sptr
174 gr_make_complex_to_mag_squared (unsigned int vlen)
176 return gr_complex_to_mag_squared_sptr (new gr_complex_to_mag_squared (vlen));
179 gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen)
180 : gr_sync_block ("complex_to_mag_squared",
181 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
182 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
188 gr_complex_to_mag_squared::work (int noutput_items,
189 gr_vector_const_void_star &input_items,
190 gr_vector_void_star &output_items)
192 const gr_complex *in = (const gr_complex *) input_items[0];
193 float *out = (float *) output_items[0];
194 int noi = noutput_items * d_vlen;
196 for (int i = 0; i < noi; i++){
197 const float __x = in[i].real();
198 const float __y = in[i].imag();
199 out[i] = __x * __x + __y * __y;
201 return noutput_items;
204 // ----------------------------------------------------------------
206 gr_complex_to_arg_sptr
207 gr_make_complex_to_arg (unsigned int vlen)
209 return gr_complex_to_arg_sptr (new gr_complex_to_arg (vlen));
212 gr_complex_to_arg::gr_complex_to_arg (unsigned int vlen)
213 : gr_sync_block ("complex_to_arg",
214 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
215 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
221 gr_complex_to_arg::work (int noutput_items,
222 gr_vector_const_void_star &input_items,
223 gr_vector_void_star &output_items)
225 const gr_complex *in = (const gr_complex *) input_items[0];
226 float *out = (float *) output_items[0];
227 int noi = noutput_items * d_vlen;
229 for (int i = 0; i < noi; i++){
230 // out[i] = std::arg (in[i]);
231 out[i] = gr_fast_atan2f(in[i]);
233 return noutput_items;