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 2, 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>
30 // ----------------------------------------------------------------
32 gr_complex_to_float_sptr
33 gr_make_complex_to_float (unsigned int vlen)
35 return gr_complex_to_float_sptr (new gr_complex_to_float (vlen));
38 gr_complex_to_float::gr_complex_to_float (unsigned int vlen)
39 : gr_sync_block ("complex_to_float",
40 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
41 gr_make_io_signature (1, 2, sizeof (float) * vlen)),
47 gr_complex_to_float::work (int noutput_items,
48 gr_vector_const_void_star &input_items,
49 gr_vector_void_star &output_items)
51 const gr_complex *in = (const gr_complex *) input_items[0];
52 float *out0 = (float *) output_items[0];
53 float *out1 = (float *) output_items[1];
54 int noi = noutput_items * d_vlen;
56 switch (output_items.size ()){
58 for (int i = 0; i < noi; i++){
59 out0[i] = in[i].real ();
64 for (int i = 0; i < noi; i++){
65 out0[i] = in[i].real ();
66 out1[i] = in[i].imag ();
77 // ----------------------------------------------------------------
79 gr_complex_to_real_sptr
80 gr_make_complex_to_real (unsigned int vlen)
82 return gr_complex_to_real_sptr (new gr_complex_to_real (vlen));
85 gr_complex_to_real::gr_complex_to_real (unsigned int vlen)
86 : gr_sync_block ("complex_to_real",
87 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
88 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
94 gr_complex_to_real::work (int noutput_items,
95 gr_vector_const_void_star &input_items,
96 gr_vector_void_star &output_items)
98 const gr_complex *in = (const gr_complex *) input_items[0];
99 float *out = (float *) output_items[0];
100 int noi = noutput_items * d_vlen;
102 for (int i = 0; i < noi; i++){
103 out[i] = in[i].real ();
105 return noutput_items;
108 // ----------------------------------------------------------------
110 gr_complex_to_imag_sptr
111 gr_make_complex_to_imag (unsigned int vlen)
113 return gr_complex_to_imag_sptr (new gr_complex_to_imag (vlen));
116 gr_complex_to_imag::gr_complex_to_imag (unsigned int vlen)
117 : gr_sync_block ("complex_to_imag",
118 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
119 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
125 gr_complex_to_imag::work (int noutput_items,
126 gr_vector_const_void_star &input_items,
127 gr_vector_void_star &output_items)
129 const gr_complex *in = (const gr_complex *) input_items[0];
130 float *out = (float *) output_items[0];
131 int noi = noutput_items * d_vlen;
133 for (int i = 0; i < noi; i++){
134 out[i] = in[i].imag ();
136 return noutput_items;
139 // ----------------------------------------------------------------
141 gr_complex_to_mag_sptr
142 gr_make_complex_to_mag (unsigned int vlen)
144 return gr_complex_to_mag_sptr (new gr_complex_to_mag (vlen));
147 gr_complex_to_mag::gr_complex_to_mag (unsigned int vlen)
148 : gr_sync_block ("complex_to_mag",
149 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
150 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
156 gr_complex_to_mag::work (int noutput_items,
157 gr_vector_const_void_star &input_items,
158 gr_vector_void_star &output_items)
160 const gr_complex *in = (const gr_complex *) input_items[0];
161 float *out = (float *) output_items[0];
162 int noi = noutput_items * d_vlen;
164 for (int i = 0; i < noi; i++){
165 out[i] = std::abs (in[i]);
167 return noutput_items;
170 // ----------------------------------------------------------------
172 gr_complex_to_mag_squared_sptr
173 gr_make_complex_to_mag_squared (unsigned int vlen)
175 return gr_complex_to_mag_squared_sptr (new gr_complex_to_mag_squared (vlen));
178 gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen)
179 : gr_sync_block ("complex_to_mag_squared",
180 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
181 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
187 gr_complex_to_mag_squared::work (int noutput_items,
188 gr_vector_const_void_star &input_items,
189 gr_vector_void_star &output_items)
191 const gr_complex *in = (const gr_complex *) input_items[0];
192 float *out = (float *) output_items[0];
193 int noi = noutput_items * d_vlen;
195 for (int i = 0; i < noi; i++){
196 const float __x = in[i].real();
197 const float __y = in[i].imag();
198 out[i] = __x * __x + __y * __y;
200 return noutput_items;
203 // ----------------------------------------------------------------
205 gr_complex_to_arg_sptr
206 gr_make_complex_to_arg (unsigned int vlen)
208 return gr_complex_to_arg_sptr (new gr_complex_to_arg (vlen));
211 gr_complex_to_arg::gr_complex_to_arg (unsigned int vlen)
212 : gr_sync_block ("complex_to_arg",
213 gr_make_io_signature (1, 1, sizeof (gr_complex) * vlen),
214 gr_make_io_signature (1, 1, sizeof (float) * vlen)),
220 gr_complex_to_arg::work (int noutput_items,
221 gr_vector_const_void_star &input_items,
222 gr_vector_void_star &output_items)
224 const gr_complex *in = (const gr_complex *) input_items[0];
225 float *out = (float *) output_items[0];
226 int noi = noutput_items * d_vlen;
228 for (int i = 0; i < noi; i++){
229 out[i] = std::arg (in[i]);
231 return noutput_items;