Implemented complex-number-based hann window calculation for better perf
authorbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 4 Dec 2016 09:32:22 +0000 (09:32 +0000)
committerbaobrien <baobrien@01035d8c-6547-0410-b346-abe4f91aad63>
Sun, 4 Dec 2016 09:32:22 +0000 (09:32 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2921 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/fsk.c

index ef64b67e60e7b01bfe9e3230ad4755fd41d65d37..3523c26595ad336758cefa7f7e1f00408a7bfed3 100644 (file)
 */
 static void fsk_generate_hann_table(struct FSK* fsk){
     int Ndft = fsk->Ndft;
+    /* Set up complex oscilator to calculate hann function */
+    COMP dphi = comp_exp_j((2*M_PI)/((float)Ndft-1));
+    COMP rphi = {.5,0};
+    
+    rphi = cmult(cconj(dphi),rphi);
+    
     for(size_t i=0; i<Ndft; i++){
-        float hann = 1-cosf((2*M_PI*(float)(i))/((float)Ndft-1));
-        fsk->hann_table[i] = hann;
+        rphi = cmult(dphi,rphi);
+        float hannc = .5-rphi.real;
+        //float hann = .5-(.5*cosf((2*M_PI*(float)(i))/((float)Ndft-1)));
+        
+        fsk->hann_table[i] = hannc;
     }  
 }
 #endif
@@ -460,6 +469,12 @@ void fsk_demod_freq_est(struct FSK *fsk, COMP fsk_in[],float *freqs,int M){
     kiss_fft_cpx *fftin  = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*Ndft);
     kiss_fft_cpx *fftout = (kiss_fft_cpx*)malloc(sizeof(kiss_fft_cpx)*Ndft);
     #endif
+    
+    #ifndef USE_HANN_TABLE
+    COMP dphi = comp_exp_j((2*M_PI)/((float)Ndft-1));
+    COMP rphi = {.5,0};
+    rphi = cmult(cconj(dphi),rphi);
+    #endif
 
     fft_samps = Ndft;
     
@@ -477,10 +492,12 @@ void fsk_demod_freq_est(struct FSK *fsk, COMP fsk_in[],float *freqs,int M){
             #ifdef USE_HANN_TABLE
             hann = fsk->hann_table[i];
             #else
-            hann = 1-cosf((2*M_PI*(float)(i))/((float)fft_samps-1));
+            //hann = 1-cosf((2*M_PI*(float)(i))/((float)fft_samps-1));
+            rphi = cmult(dphi,rphi);
+            hann = .5-rphi.real;
             #endif
-            fftin[i].r = 0.5*hann*fsk_in[i+Ndft*j].real;
-            fftin[i].i = 0.5*hann*fsk_in[i+Ndft*j].imag;
+            fftin[i].r = hann*fsk_in[i+Ndft*j].real;
+            fftin[i].i = hann*fsk_in[i+Ndft*j].imag;
         }
         /* Zero out the remaining slots */
         for(; i<Ndft;i++){