Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / lib / general / gr_complex_to_xxx.cc @ b15586bb

History | View | Annotate | Download (6.1 kB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2004 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 2, 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., 59 Temple Place - Suite 330,
20
 * Boston, MA 02111-1307, 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
30
// ----------------------------------------------------------------
31
32
gr_complex_to_float_sptr
33
gr_make_complex_to_float (unsigned int vlen)
34
{
35
  return gr_complex_to_float_sptr (new gr_complex_to_float (vlen));
36
}
37
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)),
42
    d_vlen(vlen)
43
{
44
}
45
46
int
47
gr_complex_to_float::work (int noutput_items,
48
                           gr_vector_const_void_star &input_items,
49
                           gr_vector_void_star &output_items)
50
{
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;
55
56
  switch (output_items.size ()){
57
  case 1:
58
    for (int i = 0; i < noi; i++){
59
      out0[i] = in[i].real ();
60
    }
61
    break;
62
63
  case 2:
64
    for (int i = 0; i < noi; i++){
65
      out0[i] = in[i].real ();
66
      out1[i] = in[i].imag ();
67
    }
68
    break;
69
70
  default:
71
    abort ();
72
  }
73
74
  return noutput_items;
75
}
76
77
// ----------------------------------------------------------------
78
79
gr_complex_to_real_sptr
80
gr_make_complex_to_real (unsigned int vlen)
81
{
82
  return gr_complex_to_real_sptr (new gr_complex_to_real (vlen));
83
}
84
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)),
89
    d_vlen(vlen)
90
{
91
}
92
93
int
94
gr_complex_to_real::work (int noutput_items,
95
                          gr_vector_const_void_star &input_items,
96
                          gr_vector_void_star &output_items)
97
{
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;
101
102
  for (int i = 0; i < noi; i++){
103
    out[i] = in[i].real ();
104
  }
105
  return noutput_items;
106
}
107
108
// ----------------------------------------------------------------
109
110
gr_complex_to_imag_sptr
111
gr_make_complex_to_imag (unsigned int vlen)
112
{
113
  return gr_complex_to_imag_sptr (new gr_complex_to_imag (vlen));
114
}
115
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)),
120
    d_vlen(vlen)
121
{
122
}
123
124
int
125
gr_complex_to_imag::work (int noutput_items,
126
                          gr_vector_const_void_star &input_items,
127
                          gr_vector_void_star &output_items)
128
{
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;
132
133
  for (int i = 0; i < noi; i++){
134
    out[i] = in[i].imag ();
135
  }
136
  return noutput_items;
137
}
138
139
// ----------------------------------------------------------------
140
141
gr_complex_to_mag_sptr
142
gr_make_complex_to_mag (unsigned int vlen)
143
{
144
  return gr_complex_to_mag_sptr (new gr_complex_to_mag (vlen));
145
}
146
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)),
151
    d_vlen(vlen)
152
{
153
}
154
155
int
156
gr_complex_to_mag::work (int noutput_items,
157
                          gr_vector_const_void_star &input_items,
158
                          gr_vector_void_star &output_items)
159
{
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;
163
164
  for (int i = 0; i < noi; i++){
165
    out[i] = std::abs (in[i]);
166
  }
167
  return noutput_items;
168
}
169
170
// ----------------------------------------------------------------
171
172
gr_complex_to_mag_squared_sptr
173
gr_make_complex_to_mag_squared (unsigned int vlen)
174
{
175
  return gr_complex_to_mag_squared_sptr (new gr_complex_to_mag_squared (vlen));
176
}
177
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)),
182
    d_vlen(vlen)
183
{
184
}
185
186
int
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)
190
{
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;
194
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;
199
  }
200
  return noutput_items;
201
}
202
203
// ----------------------------------------------------------------
204
205
gr_complex_to_arg_sptr
206
gr_make_complex_to_arg (unsigned int vlen)
207
{
208
  return gr_complex_to_arg_sptr (new gr_complex_to_arg (vlen));
209
}
210
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)),
215
    d_vlen(vlen)
216
{
217
}
218
219
int
220
gr_complex_to_arg::work (int noutput_items,
221
                          gr_vector_const_void_star &input_items,
222
                          gr_vector_void_star &output_items)
223
{
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;
227
228
  for (int i = 0; i < noi; i++){
229
    out[i] = std::arg (in[i]);
230
  }
231
  return noutput_items;
232
}