00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #if !defined(_COMPLEX_H_)
00040 #define _COMPLEX_H_
00041
00042
00043
00044
00045 typedef struct
00046 {
00047 float re;
00048 float im;
00049 } complex_t;
00050
00051
00052
00053
00054 typedef struct
00055 {
00056 int re;
00057 int im;
00058 } icomplex_t;
00059
00060
00061
00062
00063 typedef struct
00064 {
00065 int16_t re;
00066 int16_t im;
00067 } i16complex_t;
00068
00069
00070
00071
00072 typedef struct
00073 {
00074 int32_t re;
00075 int32_t im;
00076 } i32complex_t;
00077
00078 #ifdef __cplusplus
00079 extern "C" {
00080 #endif
00081
00082 static inline complex_t complex_set(float re, float im)
00083 {
00084 complex_t z;
00085
00086 z.re = re;
00087 z.im = im;
00088 return z;
00089 }
00090
00091
00092 static inline icomplex_t icomplex_set(int re, int im)
00093 {
00094 icomplex_t z;
00095
00096 z.re = re;
00097 z.im = im;
00098 return z;
00099 }
00100
00101
00102 static inline complex_t complex_add(const complex_t *x, const complex_t *y)
00103 {
00104 complex_t z;
00105
00106 z.re = x->re + y->re;
00107 z.im = x->im + y->im;
00108 return z;
00109 }
00110
00111
00112 static inline icomplex_t icomplex_add(const icomplex_t *x, const icomplex_t *y)
00113 {
00114 icomplex_t z;
00115
00116 z.re = x->re + y->re;
00117 z.im = x->im + y->im;
00118 return z;
00119 }
00120
00121
00122 static inline complex_t complex_sub(const complex_t *x, const complex_t *y)
00123 {
00124 complex_t z;
00125
00126 z.re = x->re - y->re;
00127 z.im = x->im - y->im;
00128 return z;
00129 }
00130
00131
00132 static inline icomplex_t icomplex_sub(const icomplex_t *x, const icomplex_t *y)
00133 {
00134 icomplex_t z;
00135
00136 z.re = x->re - y->re;
00137 z.im = x->im - y->im;
00138 return z;
00139 }
00140
00141
00142 static inline complex_t complex_mul(const complex_t *x, const complex_t *y)
00143 {
00144 complex_t z;
00145
00146 z.re = x->re*y->re - x->im*y->im;
00147 z.im = x->re*y->im + x->im*y->re;
00148 return z;
00149 }
00150
00151
00152 static inline complex_t complex_div(const complex_t *x, const complex_t *y)
00153 {
00154 complex_t z;
00155 float f;
00156
00157 f = y->re*y->re + y->im*y->im;
00158 z.re = ( x->re*y->re + x->im*y->im)/f;
00159 z.im = (-x->re*y->im + x->im*y->re)/f;
00160 return z;
00161 }
00162
00163
00164 static inline complex_t complex_conj(const complex_t *x)
00165 {
00166 complex_t z;
00167
00168 z.re = x->re;
00169 z.im = -x->im;
00170 return z;
00171 }
00172
00173
00174 static inline icomplex_t icomplex_conj(const icomplex_t *x)
00175 {
00176 icomplex_t z;
00177
00178 z.re = x->re;
00179 z.im = -x->im;
00180 return z;
00181 }
00182
00183
00184 static inline float power(const complex_t *x)
00185 {
00186 return x->re*x->re + x->im*x->im;
00187 }
00188
00189
00190 #ifdef __cplusplus
00191 }
00192 #endif
00193
00194 #endif
00195