• API Main Page
  • Documentation
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

src/complex.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2010 by Matthias Ihrke   *
00003  *   ihrke@nld.ds.mpg.de
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include "complex.h"
00022 #include <math.h>
00023 #include "mathadd.h"
00024 
00030 Complex complex( double re, double im ){
00031   Complex a;
00032   a.re = re;
00033   a.im = im;
00034   return a;
00035 }
00036 
00039 Complex complex_add( Complex a, Complex b ){
00040   a.re += b.re;
00041   a.im += b.im;
00042   return a;
00043 }
00044 
00047 Complex complex_sub( Complex a, Complex b ){
00048   a.re -= b.re;
00049   a.im -= b.im;
00050   return a;
00051 }
00052 
00055 Complex complex_mul( Complex a, Complex b ){
00056   Complex r;
00057   r.re = (a.re*b.re)-(a.im*b.im);
00058   r.im = (a.im*b.re)+(a.re*b.im);
00059   return r;
00060 }
00061 
00064 Complex complex_mul_double( Complex a, double b ){
00065   a.re *= b;
00066   a.im *= b;
00067   return a;
00068 }
00069 
00072 double  complex_abs( Complex a ){
00073   return sqrt( SQR( a.re ) + SQR( a.im ) );
00074 }
00075 
00083 Complex complex_exp( Complex a ){
00084   Complex r;
00085   r = complex( cos( a.im ), sin( a.im ) );
00086   r = complex_mul_double( r, exp( a.re ) );
00087   return r;
00088 }
00089 
00092 Complex complex_conj( Complex a ){
00093   a.im = -a.im;
00094   return a;
00095 }
00096 
00099 Complex complex_neg ( Complex a ){
00100   a.re = -a.re;
00101   a.im = -a.im;
00102   return a;
00103 }
00104 
00107 Complex complex_sqrt( Complex x ){
00108   double r = complex_abs(x);
00109   Complex z = complex(sqrt(0.5 * (r + x.re)),
00110                              sqrt(0.5 * (r - x.re)));
00111   if (x.im < 0.0) z.im = -z.im;
00112   return z;
00113 }
00122 Complex complex_div( Complex a, Complex b){
00123   Complex r;
00124   r.re = (a.re*b.re + a.im*b.im)/( SQR( b.re )+SQR( b.im ) );
00125   r.im = (a.im*b.re - a.re*b.im)/( SQR( b.re )+SQR( b.im ) );
00126   return r;
00127 }
00128 
00131 Complex complex_bilinear_transform(Complex pz){
00132   return complex_div( complex_add( complex(2.0,0.0), pz ), complex_sub( complex(2.0,0.0), pz ) );
00133 }

Generated on Fri Jun 25 2010 14:10:16 for libeegtools by  doxygen 1.7.0