2 This file is part of a program that implements a Software-Defined Radio.
4 Copyright (C) 2004 by Frank Brickle, AB2KT and Bob McGwier, N4HY
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 The authors can be reached by email at
28 The DTTS Microwave Society
37 COMPLEX cxzero = {0.0, 0.0};
38 COMPLEX cxone = {1.0, 0.0};
39 COMPLEX cxJ = {0.0, 1.0};
40 COMPLEX cxminusone = {-1.0, 0.0};
41 COMPLEX cxminusJ = {0.0, -1.0};
46 Cscl(COMPLEX x, REAL a) {
48 c_re(z) = c_re(x) * a;
49 c_im(z) = c_im(x) * a;
54 Cadd(COMPLEX x, COMPLEX y) {
56 c_re(z) = c_re(x) + c_re(y);
57 c_im(z) = c_im(x) + c_im(y);
62 Csub(COMPLEX x, COMPLEX y) {
64 c_re(z) = c_re(x) - c_re(y);
65 c_im(z) = c_im(x) - c_im(y);
70 Cmul(COMPLEX x, COMPLEX y) {
72 c_re(z) = c_re(x) * c_re(y) - c_im(x) * c_im(y);
73 c_im(z) = c_im(x) * c_re(y) + c_re(x) * c_im(y);
78 Cdiv(COMPLEX x, COMPLEX y) {
79 REAL d = sqr(c_re(y)) + sqr(c_im(y));
81 c_re(z) = (c_re(x) * c_re(y) + c_im(x) * c_im(y)) / d;
82 c_im(z) = (c_re(y) * c_im(x) - c_im(y) * c_re(x)) / d;
87 Cmag(COMPLEX z) { return sqrt(sqr(z.re) + sqr(z.im)); }
90 Cabs(COMPLEX z) { return sqrt(sqr(z.re) + sqr(z.im)); }
93 Csqrmag(COMPLEX z) { return sqr(z.re) + sqr(z.im); }
96 Cmplx(REAL x, IMAG y) {
103 Conjg(COMPLEX z) { return Cmplx(z.re, -z.im); }
108 return Cmplx(r * cos(z.im), r * sin(z.im));