From cada39a002fbbe9bc848f963c3eb7faa65122228 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Sun, 19 Jan 2003 21:11:59 +0000 Subject: "" svn path=/trunk/; revision=345 --- externals/grill/fftease/src/leanconvert.c | 57 ++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-) (limited to 'externals/grill/fftease/src/leanconvert.c') diff --git a/externals/grill/fftease/src/leanconvert.c b/externals/grill/fftease/src/leanconvert.c index ecb6bc54..0c567ca8 100644 --- a/externals/grill/fftease/src/leanconvert.c +++ b/externals/grill/fftease/src/leanconvert.c @@ -1,23 +1,49 @@ #include "pv.h" -void leanconvert( float *S, float *C, int N2 ) +void leanconvert( float *S, float *C, int N2 , int amp, int ph) { +#if 1 register int i; - float a = S[0]; // real value at f=0 - float b = S[1]; // real value at f=Nyquist + float a = fabs(S[0]); // real value at f=0 + float b = fabs(S[1]); // real value at f=Nyquist - C[0] = fabs(a); + C[0] = a; C[1] = 0; S += 2,C += 2; - for ( i = 1; i < N2; i++,S += 2,C += 2 ) { - C[0] = hypot( S[0], S[1] ); - C[1] = -atan2( S[1], S[0] ); + if(amp && ph) { + for ( i = 1; i < N2; i++,S += 2,C += 2 ) { + C[0] = hypot( S[0], S[1] ); + C[1] = -atan2( S[1], S[0] ); + } + } + else if(amp) { + for ( i = 1; i < N2; i++,S += 2,C += 2 ) + C[0] = hypot( S[0], S[1] ); + } + else if(ph) { + for ( i = 1; i < N2; i++,S += 2,C += 2 ) + C[1] = -atan2( S[1], S[0] ); } - C[0] = fabs(b); + C[0] = b; C[1] = 0; +#else + + int real, imag, + amp, phase; + float a, b; + int i; + + for ( i = 0; i <= N2; i++ ) { + imag = phase = ( real = amp = i<<1 ) + 1; + a = ( i == N2 ? S[1] : S[real] ); + b = ( i == 0 || i == N2 ? 0. : S[imag] ); + C[amp] = hypot( a, b ); + C[phase] = -atan2( b, a ); + } +#endif } @@ -29,6 +55,7 @@ void leanconvert( float *S, float *C, int N2 ) void leanunconvert( float *C, float *S, int N2 ) { +#if 1 register int i; S[0] = fabs(C[0]); @@ -39,5 +66,19 @@ void leanunconvert( float *C, float *S, int N2 ) S[0] = C[0] * cos( C[1] ); S[1] = -C[0] * sin( C[1] ); } +#else + int real, imag, + amp, phase; + float a, b; + register int i; + + for ( i = 0; i <= N2; i++ ) { + imag = phase = ( real = amp = i<<1 ) + 1; + S[real] = *(C+amp) * cos( *(C+phase) ); + if ( i != N2 ) + S[imag] = -*(C+amp) * sin( *(C+phase) ); + } + +#endif } -- cgit v1.2.1