root / gnuradio-core / src / lib / filter / gr_rotator.h @ e4eb47f0
History | View | Annotate | Download (1.6 kB)
| 1 | 5d69a524 | jcorgan | /* -*- c++ -*- */
|
|---|---|---|---|
| 2 | 5d69a524 | jcorgan | /*
|
| 3 | 5b313df4 | eb | * Copyright 2003,2008 Free Software Foundation, Inc. |
| 4 | 5d69a524 | jcorgan | * |
| 5 | 5d69a524 | jcorgan | * This file is part of GNU Radio |
| 6 | 5d69a524 | jcorgan | * |
| 7 | 5d69a524 | jcorgan | * GNU Radio is free software; you can redistribute it and/or modify |
| 8 | 5d69a524 | jcorgan | * it under the terms of the GNU General Public License as published by |
| 9 | 937b719d | eb | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | 5d69a524 | jcorgan | * any later version. |
| 11 | 5d69a524 | jcorgan | * |
| 12 | 5d69a524 | jcorgan | * GNU Radio is distributed in the hope that it will be useful, |
| 13 | 5d69a524 | jcorgan | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | 5d69a524 | jcorgan | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | 5d69a524 | jcorgan | * GNU General Public License for more details. |
| 16 | 5d69a524 | jcorgan | * |
| 17 | 5d69a524 | jcorgan | * You should have received a copy of the GNU General Public License |
| 18 | 5d69a524 | jcorgan | * along with GNU Radio; see the file COPYING. If not, write to |
| 19 | 86f5c924 | eb | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | 86f5c924 | eb | * Boston, MA 02110-1301, USA. |
| 21 | 5d69a524 | jcorgan | */ |
| 22 | 5d69a524 | jcorgan | |
| 23 | 5d69a524 | jcorgan | #ifndef _GR_ROTATOR_H_
|
| 24 | 5d69a524 | jcorgan | #define _GR_ROTATOR_H_
|
| 25 | 5d69a524 | jcorgan | |
| 26 | 5d69a524 | jcorgan | #include <gr_complex.h> |
| 27 | 5d69a524 | jcorgan | |
| 28 | 5d69a524 | jcorgan | class gr_rotator {
|
| 29 | 5d69a524 | jcorgan | gr_complex d_phase; |
| 30 | 5d69a524 | jcorgan | gr_complex d_phase_incr; |
| 31 | 5b313df4 | eb | unsigned int d_counter; |
| 32 | 5d69a524 | jcorgan | |
| 33 | 5d69a524 | jcorgan | public:
|
| 34 | 5b313df4 | eb | gr_rotator () : d_phase (1), d_phase_incr (1), d_counter(0) { } |
| 35 | 5d69a524 | jcorgan | |
| 36 | 5b313df4 | eb | void set_phase (gr_complex phase) { d_phase = phase / abs(phase); }
|
| 37 | 5b313df4 | eb | void set_phase_incr (gr_complex incr) { d_phase_incr = incr / abs(incr); }
|
| 38 | 5d69a524 | jcorgan | |
| 39 | 5d69a524 | jcorgan | gr_complex rotate (gr_complex in){
|
| 40 | 5b313df4 | eb | d_counter++; |
| 41 | 5d69a524 | jcorgan | |
| 42 | 5b313df4 | eb | gr_complex z = in * d_phase; // rotate in by phase
|
| 43 | 5b313df4 | eb | d_phase *= d_phase_incr; // incr our phase (complex mult == add phases)
|
| 44 | 5d69a524 | jcorgan | |
| 45 | 5b313df4 | eb | if ((d_counter % 512) == 0) |
| 46 | 5b313df4 | eb | d_phase /= abs(d_phase); // Normalize to ensure multiplication is rotation
|
| 47 | 5b313df4 | eb | |
| 48 | 5b313df4 | eb | return z;
|
| 49 | 5d69a524 | jcorgan | } |
| 50 | 5d69a524 | jcorgan | |
| 51 | 5d69a524 | jcorgan | }; |
| 52 | 5d69a524 | jcorgan | |
| 53 | 5d69a524 | jcorgan | #endif /* _GR_ROTATOR_H_ */ |