Mercurial > hg > peckfft
comparison peck_fft.c @ 1:cfec79393811
cleanup
| author | Peter Meerwald <p.meerwald@bct-electronic.com> |
|---|---|
| date | Fri, 16 Sep 2011 12:57:27 +0200 |
| parents | 723f588b82ac |
| children | 2d6c49fcafcb |
comparison
equal
deleted
inserted
replaced
| 0:723f588b82ac | 1:cfec79393811 |
|---|---|
| 13 */ | 13 */ |
| 14 | 14 |
| 15 | 15 |
| 16 #include "_peck_fft_guts.h" | 16 #include "_peck_fft_guts.h" |
| 17 /* The guts header contains all the multiplication and addition macros that are defined for | 17 /* The guts header contains all the multiplication and addition macros that are defined for |
| 18 fixed or floating point complex numbers. It also delares the kf_ internal functions. | 18 * fixed or floating point complex numbers. It also delares the kf_ internal functions. |
| 19 */ | 19 */ |
| 20 | 20 |
| 21 static void kf_bfly2( | 21 static void kf_bfly2( |
| 22 peck_fft_cpx * Fout, | 22 peck_fft_cpx * Fout, |
| 23 const size_t fstride, | 23 const size_t fstride, |
| 24 const peck_fft_cfg st, | 24 const peck_fft_cfg st, |
| 25 int m | 25 int m) { |
| 26 ) | |
| 27 { | |
| 28 | 26 |
| 29 //printf("kf_bfly2\n"); | 27 //printf("kf_bfly2\n"); |
| 30 | 28 |
| 31 peck_fft_cpx * Fout2; | 29 peck_fft_cpx * Fout2; |
| 32 peck_fft_cpx * tw1 = st->twiddles; | 30 peck_fft_cpx * tw1 = st->twiddles; |
| 33 peck_fft_cpx t; | 31 peck_fft_cpx t; |
| 34 Fout2 = Fout + m; | 32 Fout2 = Fout + m; |
| 35 do{ | 33 do { |
| 36 C_FIXDIV(*Fout,2); C_FIXDIV(*Fout2,2); | 34 C_FIXDIV(*Fout, 2); |
| 37 | 35 C_FIXDIV(*Fout2, 2); |
| 38 C_MUL (t, *Fout2 , *tw1); | 36 |
| 37 C_MUL(t, *Fout2, *tw1); | |
| 39 tw1 += fstride; | 38 tw1 += fstride; |
| 40 C_SUB( *Fout2 , *Fout , t ); | 39 C_SUB(*Fout2, *Fout, t); |
| 41 C_ADDTO( *Fout , t ); | 40 C_ADDTO(*Fout, t); |
| 42 ++Fout2; | 41 ++Fout2; |
| 43 ++Fout; | 42 ++Fout; |
| 44 }while (--m); | 43 } while (--m); |
| 45 } | 44 } |
| 46 | 45 |
| 47 static void kf_bfly4( | 46 static void kf_bfly4( |
| 48 peck_fft_cpx * Fout, | 47 peck_fft_cpx * Fout, |
| 49 const size_t fstride, | 48 const size_t fstride, |
| 50 const peck_fft_cfg st, | 49 const peck_fft_cfg st, |
| 51 const size_t m | 50 const size_t m) { |
| 52 ) | |
| 53 { | |
| 54 peck_fft_cpx *tw1,*tw2,*tw3; | 51 peck_fft_cpx *tw1,*tw2,*tw3; |
| 55 peck_fft_cpx scratch[6]; | 52 peck_fft_cpx scratch[6]; |
| 56 size_t k=m; | 53 size_t k=m; |
| 57 const size_t m2=2*m; | 54 const size_t m2=2*m; |
| 58 const size_t m3=3*m; | 55 const size_t m3=3*m; |
| 59 | 56 |
| 60 //printf("kf_bfly4\n"); | 57 //printf("kf_bfly4\n"); |
| 61 | 58 |
| 62 | |
| 63 tw3 = tw2 = tw1 = st->twiddles; | 59 tw3 = tw2 = tw1 = st->twiddles; |
| 64 | 60 |
| 65 do { | 61 do { |
| 66 C_FIXDIV(*Fout,4); C_FIXDIV(Fout[m],4); C_FIXDIV(Fout[m2],4); C_FIXDIV(Fout[m3],4); | 62 C_FIXDIV(*Fout, 4); |
| 67 | 63 C_FIXDIV(Fout[m], 4); |
| 68 C_MUL(scratch[0],Fout[m] , *tw1 ); | 64 C_FIXDIV(Fout[m2], 4); |
| 69 C_MUL(scratch[1],Fout[m2] , *tw2 ); | 65 C_FIXDIV(Fout[m3], 4); |
| 70 C_MUL(scratch[2],Fout[m3] , *tw3 ); | 66 |
| 71 | 67 C_MUL(scratch[0], Fout[m], *tw1); |
| 72 C_SUB( scratch[5] , *Fout, scratch[1] ); | 68 C_MUL(scratch[1], Fout[m2], *tw2); |
| 69 C_MUL(scratch[2], Fout[m3], *tw3); | |
| 70 | |
| 71 C_SUB(scratch[5], *Fout, scratch[1]); | |
| 73 C_ADDTO(*Fout, scratch[1]); | 72 C_ADDTO(*Fout, scratch[1]); |
| 74 C_ADD( scratch[3] , scratch[0] , scratch[2] ); | 73 C_ADD(scratch[3], scratch[0], scratch[2]); |
| 75 C_SUB( scratch[4] , scratch[0] , scratch[2] ); | 74 C_SUB(scratch[4], scratch[0], scratch[2]); |
| 76 C_SUB( Fout[m2], *Fout, scratch[3] ); | 75 C_SUB(Fout[m2], *Fout, scratch[3]); |
| 77 tw1 += fstride; | 76 tw1 += fstride; |
| 78 tw2 += fstride*2; | 77 tw2 += fstride*2; |
| 79 tw3 += fstride*3; | 78 tw3 += fstride*3; |
| 80 C_ADDTO( *Fout , scratch[3] ); | 79 C_ADDTO(*Fout, scratch[3]); |
| 81 | 80 |
| 82 if(st->inverse) { | 81 if (st->inverse) { |
| 83 Fout[m].r = scratch[5].r - scratch[4].i; | 82 Fout[m].r = scratch[5].r - scratch[4].i; |
| 84 Fout[m].i = scratch[5].i + scratch[4].r; | 83 Fout[m].i = scratch[5].i + scratch[4].r; |
| 85 Fout[m3].r = scratch[5].r + scratch[4].i; | 84 Fout[m3].r = scratch[5].r + scratch[4].i; |
| 86 Fout[m3].i = scratch[5].i - scratch[4].r; | 85 Fout[m3].i = scratch[5].i - scratch[4].r; |
| 87 }else{ | 86 } else { |
| 88 Fout[m].r = scratch[5].r + scratch[4].i; | 87 Fout[m].r = scratch[5].r + scratch[4].i; |
| 89 Fout[m].i = scratch[5].i - scratch[4].r; | 88 Fout[m].i = scratch[5].i - scratch[4].r; |
| 90 Fout[m3].r = scratch[5].r - scratch[4].i; | 89 Fout[m3].r = scratch[5].r - scratch[4].i; |
| 91 Fout[m3].i = scratch[5].i + scratch[4].r; | 90 Fout[m3].i = scratch[5].i + scratch[4].r; |
| 92 } | 91 } |
| 93 ++Fout; | 92 ++Fout; |
| 94 }while(--k); | 93 } while (--k); |
| 95 } | 94 } |
| 96 | 95 |
| 97 static void kf_bfly3( | 96 static void kf_bfly3( |
| 98 peck_fft_cpx * Fout, | 97 peck_fft_cpx * Fout, |
| 99 const size_t fstride, | 98 const size_t fstride, |
| 100 const peck_fft_cfg st, | 99 const peck_fft_cfg st, |
| 101 size_t m | 100 size_t m) { |
| 102 ) | |
| 103 { | |
| 104 size_t k=m; | 101 size_t k=m; |
| 105 const size_t m2 = 2*m; | 102 const size_t m2 = 2*m; |
| 106 peck_fft_cpx *tw1,*tw2; | 103 peck_fft_cpx *tw1, *tw2; |
| 107 peck_fft_cpx scratch[5]; | 104 peck_fft_cpx scratch[5]; |
| 108 peck_fft_cpx epi3; | 105 peck_fft_cpx epi3; |
| 109 epi3 = st->twiddles[fstride*m]; | 106 epi3 = st->twiddles[fstride*m]; |
| 110 | 107 |
| 111 printf("kf_bfly3\n"); | 108 printf("kf_bfly3\n"); |
| 112 | 109 |
| 113 | 110 |
| 114 tw1=tw2=st->twiddles; | 111 tw1=tw2=st->twiddles; |
| 115 | 112 |
| 116 do{ | 113 do { |
| 117 C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3); | 114 C_FIXDIV(*Fout,3); C_FIXDIV(Fout[m],3); C_FIXDIV(Fout[m2],3); |
| 118 | 115 |
| 119 C_MUL(scratch[1],Fout[m] , *tw1); | 116 C_MUL(scratch[1],Fout[m] , *tw1); |
| 120 C_MUL(scratch[2],Fout[m2] , *tw2); | 117 C_MUL(scratch[2],Fout[m2] , *tw2); |
| 121 | 118 |
| 136 | 133 |
| 137 Fout[m].r -= scratch[0].i; | 134 Fout[m].r -= scratch[0].i; |
| 138 Fout[m].i += scratch[0].r; | 135 Fout[m].i += scratch[0].r; |
| 139 | 136 |
| 140 ++Fout; | 137 ++Fout; |
| 141 }while(--k); | 138 } while (--k); |
| 142 } | 139 } |
| 143 | 140 |
| 144 static void kf_bfly5( | 141 static void kf_bfly5( |
| 145 peck_fft_cpx * Fout, | 142 peck_fft_cpx * Fout, |
| 146 const size_t fstride, | 143 const size_t fstride, |
