tx filtering and fdm upconversion working in C
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Apr 2012 06:53:50 +0000 (06:53 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 19 Apr 2012 06:53:50 +0000 (06:53 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@371 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/octave/fdmdv.m
codec2-dev/octave/fdmdv_ut.m
codec2-dev/octave/gen_rn_coeffs.m
codec2-dev/octave/tfdmdv.m
codec2-dev/src/fdmdv.c
codec2-dev/src/fdmdv.h
codec2-dev/src/fdmdv_internal.h
codec2-dev/src/rn.h
codec2-dev/unittest/tfdmdv.c

index 70aa82481f3d174a1ad87cccf3cae1fabf84860a..c295d7db88d46bc56e50befe22831a554ba3a762 100644 (file)
@@ -22,7 +22,7 @@ global Nc = 14;        % number of carriers
 global Nb = 2;         % Bits/symbol for QPSK modulation
 global Rb = Nc*Rs*Nb;  % bit rate
 global M  = Fs/Rs;     % oversampling factor
-global Nsym  = 4;      % number of symbols to filter over
+global Nsym  = 6;      % number of symbols to filter over
 global Fsep  = 75;     % Separation between carriers (Hz)
 global Fcentre = 1200; % Centre frequency, Nc/2 carriers below this, N/c carriers above (Hz)
 global Nt = 5;         % number of symbols we estimate timing over
@@ -33,7 +33,8 @@ alpha = 0.5;
 
 % root raised cosine (Root Nyquist) filter 
 
-global gt_alpha5_root = gen_rn_coeffs(alpha, T, Rs, Nsym, M);
+global gt_alpha5_root;
+gt_alpha5_root = gen_rn_coeffs(alpha, T, Rs, Nsym, M);
 
 
 % Functions ----------------------------------------------------
@@ -111,11 +112,13 @@ function tx_baseband = tx_filter(tx_symbols)
   % Efficient polyphase filter techniques used as tx_filter_memory is sparse
 
   tx_filter_memory(:,Nfilter) = sqrt(2)/2*tx_symbols;
+
   for i=1:M
     tx_baseband(:,i) = M*tx_filter_memory(:,M:M:Nfilter) * gt_alpha5_root(M-i+1:M:Nfilter)';
   end
   tx_filter_memory(:,1:Nfilter-M) = tx_filter_memory(:,M+1:Nfilter);
   tx_filter_memory(:,Nfilter-M+1:Nfilter) = zeros(Nc+1,M);
+
 endfunction
 
 
@@ -722,6 +725,23 @@ function test_bits_file(filename)
 endfunction
 
 
+% Saves RN filter coeffs to a text file in the form of a C array
+
+function rn_file(filename)
+  global gt_alpha5_root;
+  global Nfilter;
+
+  f=fopen(filename,"wt");
+  fprintf(f,"/* Generated by rn_file() Octave function */\n\n");
+  fprintf(f,"const float gt_alpha5_root[]={\n");
+  for m=1:Nfilter-1
+    fprintf(f,"  %g,\n",gt_alpha5_root(m));
+  endfor
+  fprintf(f,"  %g\n};\n",gt_alpha5_root(Nfilter));
+  fclose(f);
+endfunction
+
+
 % Initialise ----------------------------------------------------
 
 global pilot_bit;
@@ -737,11 +757,11 @@ rx_filter_memory = zeros(Nc+1, Nfilter);
 global freq;
 freq = zeros(Nc+1,1);
 for c=1:Nc/2
-  carrier_freq = (-Nc/2 - 1 + c)*Fsep + Fcentre;
+  carrier_freq = (-Nc/2 - 1 + c)*Fsep + Fcentre
   freq(c) = exp(j*2*pi*carrier_freq/Fs);
 end
 for c=Nc/2+1:Nc
-  carrier_freq = (-Nc/2 + c)*Fsep + Fcentre;
+  carrier_freq = (-Nc/2 + c)*Fsep + Fcentre
   freq(c) = exp(j*2*pi*carrier_freq/Fs);
 end
 
index ad1c6b9e4eaad31c928b18cf5b25df9f2fa56ad4..0a20a42b9033bb8b5d4139acf3b0f97b342bb589 100644 (file)
@@ -11,7 +11,7 @@ fdmdv;               % load modem code
  
 % Simulation Parameters --------------------------------------
 
-frames = 25;
+frames = 100;
 EbNo_dB = 7.3;
 Foff_hz = 0;
 modulation = 'dqpsk';
index 2a67e240eaa4b081b59412e062e7e48161100043..bfc214e0f7de7efb46fd1ee455357f68772de8d6 100644 (file)
@@ -27,7 +27,7 @@ function coeffs = gen_rn_coeffs(alpha, T, Rs, Nsym, M)
   Nfft = 4096;
   GF_alpha5 = fft(gt_alpha5,Nfft)/M;
 
-  % sqrt causes stop band to be amplifed, this hack pushes it down again
+  % sqrt causes stop band to be amplified, this hack pushes it down again
 
   for i=1:Nfft
     if (abs(GF_alpha5(i)) < 0.02)
index 3e7e7975e69fd552f180bc4b148d788868c1c6ca..2d63d1475fe3c5f19620f9d5c0722268c804b14b 100644 (file)
@@ -12,19 +12,23 @@ fdmdv; % load modem code
 % Generate reference vectors using Octave implementation of FDMDV modem
 
 passes = fails = 0;
-frames = 10;
+frames = 25;
 prev_tx_symbols = ones(Nc+1,1);
 tx_bits_log = [];
 tx_symbols_log = [];
+tx_baseband_log = [];
+tx_fdm_log = [];
 
 for f=1:frames
-
   tx_bits = get_test_bits(Nc*Nb);
   tx_bits_log = [tx_bits_log tx_bits];
   tx_symbols = bits_to_qpsk(prev_tx_symbols, tx_bits, 'dqpsk');
   prev_tx_symbols = tx_symbols;
   tx_symbols_log = [tx_symbols_log tx_symbols];
-
+  tx_baseband = tx_filter(tx_symbols);
+  tx_baseband_log = [tx_baseband_log tx_baseband];
+  tx_fdm = fdm_upconvert(tx_baseband);
+  tx_fdm_log = [tx_fdm_log tx_fdm];
 end
 
 % Compare to the output from the C version
@@ -33,13 +37,54 @@ load ../unittest/tfdmdv_out.txt
 
 figure(1)
 subplot(211)
-plot(tx_bits_log - tx_bits_tfdmdv);
+n = 28;
+stem(tx_bits_log_c(1:n));
+hold on;
+stem(tx_bits_log(1:n) - tx_bits_log_c(1:n),'g');
+hold off;
+axis([1 n -1.5 1.5])
 title('tx bits')
 subplot(212)
-plot(tx_symbols_log - tx_symbols_tfdmdv);
-title('tx symbols')
+stem(real(tx_symbols_log_c(1:n/2)));
+hold on;
+stem(tx_symbols_log(1:n/2) - tx_symbols_log_c(1:n/2),'g');
+hold off;
+axis([1 n/2 -1.5 1.5])
+title('tx symbols real')
 
-if sum(tx_bits_log - tx_bits_tfdmdv) == 0
+figure(2)
+clf;
+diff = tx_baseband_log - tx_baseband_log_c;
+subplot(211)
+c=3;
+plot(real(tx_baseband_log_c(c,:)));
+hold on;
+plot(real(sum(diff)),'g')
+hold off;
+title('tx baseband real')
+subplot(212)
+plot(imag(tx_baseband_log_c(c,:)));
+hold on;
+plot(imag(sum(diff)),'g')
+hold off;
+title('tx baseband imag')
+
+figure(3)
+clf
+subplot(211)
+plot(real(tx_fdm_log_c));
+hold on;
+plot(real(tx_fdm_log - tx_fdm_log_c),'g');
+hold off;
+title('tx fdm real')
+subplot(212)
+plot(imag(tx_fdm_log_c));
+hold on;
+plot(imag(tx_fdm_log - tx_fdm_log_c),'g');
+hold off;
+title('tx fdm imag')
+
+if sum(tx_bits_log - tx_bits_log_c) == 0
   printf("fdmdv_get_test_bits..: OK\n");
   passes++;
 else;
@@ -47,7 +92,7 @@ else;
   fails++;
 end
  
-if sum(tx_symbols_log - tx_symbols_tfdmdv) == 0
+if sum(tx_symbols_log - tx_symbols_log_c) == 0
   printf("bits_to_dqpsk_symbols: OK\n");
   passes++;
 else;
@@ -55,4 +100,12 @@ else;
   fails++;
 end
 
+if sum(tx_baseband_log - tx_baseband_log_c) < 1E-3
+  printf("tx_filter............: OK\n");
+  passes++;
+else;
+  printf("tx_filter............: FAIL\n");
+  fails++;
+end
+
 printf("\npasses: %d fails: %d\n", passes, fails);
index a4d7a2ee37df37aa2b9028954d991c375667d7d6..895c6efa41c46da3e8ce16a360949e4a618ebacb 100644 (file)
@@ -1,7 +1,7 @@
 /*---------------------------------------------------------------------------*\
                                                                              
   FILE........: fdmdv.c
-  AUTHOR......: David Rowe                                                          
+  AUTHOR......: David Rowe
   DATE CREATED: April 14 2012
                                                                              
   Functions that implement a Frequency Divison Multiplexed Modem for
@@ -114,7 +114,8 @@ static void cbuf_shift_update(COMP buf[], COMP update[], int buflen, int updatel
 struct FDMDV *fdmdv_create(void)
 {
     struct FDMDV *f;
-    int           c;
+    int           c, k;
+    float         carrier_freq;
 
     assert(FDMDV_BITS_PER_FRAME == NC*NB);
     assert(FDMDV_SAMPLES_PER_FRAME == M);
@@ -128,7 +129,35 @@ struct FDMDV *fdmdv_create(void)
     for(c=0; c<NC+1; c++) {
        f->prev_tx_symbols[c].real = 1.0;
        f->prev_tx_symbols[c].imag = 0.0;
+       for(k=0; k<NFILTER; k++) {
+           f->tx_filter_memory[c][k].real = 0.0;
+           f->tx_filter_memory[c][k].imag = 0.0;
+       }
+
+       /* Spread initial FDM carrier phase out as far as possible.
+           This helped PAPR for a few dB.  We don't need to adjust rx
+           phase as DQPSK takes care of that. */
+       
+       f->phase_tx[c].real = cos(2.0*PI*c/(NC+1));
+       f->phase_tx[c].imag = sin(2.0*PI*c/(NC+1));
+
+   }
+    
+    for(c=0; c<NC/2; c++) {
+       carrier_freq = (-NC/2 + c)*FSEP + FCENTRE;
+       f->freq[c].real = cos(2.0*PI*carrier_freq/FS);
+       f->freq[c].imag = sin(2.0*PI*carrier_freq/FS);
+    }
+
+    for(c=NC/2; c<NC; c++) {
+       carrier_freq = (-NC/2 + c + 1)*FSEP + FCENTRE;
+       f->freq[c].real = cos(2.0*PI*carrier_freq/FS);
+       f->freq[c].imag = sin(2.0*PI*carrier_freq/FS);
     }
+       
+    f->freq[NC].real = cos(2.0*PI*FCENTRE/FS);
+    f->freq[NC].imag = sin(2.0*PI*FCENTRE/FS);
+
     return f;
 }
 
@@ -217,3 +246,124 @@ void bits_to_dqpsk_symbols(COMP tx_symbols[], COMP prev_tx_symbols[], int tx_bit
        *pilot_bit = 1;
 }
 
+/*---------------------------------------------------------------------------*\
+                                                       
+  FUNCTION....: tx_filter()         
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 17/4/2012
+
+  Given NC*NB bits construct M samples (1 symbol) of NC filtered
+  symbols streams
+
+\*---------------------------------------------------------------------------*/
+
+void tx_filter(COMP tx_baseband[NC+1][M], COMP tx_symbols[], COMP tx_filter_memory[NC+1][NFILTER])
+{
+    int     c;
+    int     i,j,k;
+    float   acc;
+    COMP    gain;
+
+    gain.real = sqrt(2.0)/2.0;
+    gain.imag = 0.0;
+
+    for(c=0; c<NC+1; c++)
+       tx_filter_memory[c][NFILTER-1] = cmult(tx_symbols[c], gain);
+
+    /* 
+       tx filter each symbol, generate M filtered output samples for each symbol.
+       Efficient polyphase filter techniques used as tx_filter_memory is sparse
+    */
+
+    for(i=0; i<M; i++) {
+       for(c=0; c<NC+1; c++) {
+
+           /* filter real sample of symbol for carrier c */
+
+           acc = 0.0;
+           for(j=M-1,k=M-i-1; j<NFILTER; j+=M,k+=M)
+               acc += M * tx_filter_memory[c][j].real * gt_alpha5_root[k];
+           tx_baseband[c][i].real = acc;       
+
+           /* filter imag sample of symbol for carrier c */
+
+           acc = 0.0;
+           for(j=M-1,k=M-i-1; j<NFILTER; j+=M,k+=M)
+               acc += M * tx_filter_memory[c][j].imag * gt_alpha5_root[k];
+           tx_baseband[c][i].imag = acc;
+
+       }
+    }
+
+    /* shift memory, inserting zeros at end */
+
+    for(i=0; i<NFILTER-M; i++)
+       for(c=0; c<NC+1; c++)
+           tx_filter_memory[c][i] = tx_filter_memory[c][i+M];
+
+    for(i=NFILTER-M; i<NFILTER; i++)
+       for(c=0; c<NC+1; c++) {
+           tx_filter_memory[c][i].real = 0.0;
+           tx_filter_memory[c][i].imag = 0.0;
+       }
+}
+
+/*---------------------------------------------------------------------------*\
+                                                       
+  FUNCTION....: fdm_upconvert()             
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 17/4/2012
+
+  Construct FDM signal by frequency shifting each filtered symbol
+  stream.  Returns complex signal so we can apply frequency offsets
+  easily.
+
+\*---------------------------------------------------------------------------*/
+
+void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], COMP freq[])
+{
+    int  i,c;
+    COMP two = {2.0, 0.0};
+    COMP pilot;
+
+    for(i=0; i<M; i++) {
+       tx_fdm[i].real = 0.0;
+       tx_fdm[i].imag = 0.0;
+    }
+
+    /* Nc/2 tones below centre freq */
+  
+    for (c=0; c<NC/2; c++) 
+       for (i=0; i<M; i++) {
+           phase_tx[c] = cmult(phase_tx[c], freq[c]);
+           tx_fdm[i] = cadd(tx_fdm[i], cmult(tx_baseband[c][i], phase_tx[c]));
+       }
+
+    /* Nc/2 tones above centre freq */
+
+    for (c=NC/2; c<NC; c++) 
+       for (i=0; i<M; i++) {
+           phase_tx[c] = cmult(phase_tx[c], freq[c]);
+           tx_fdm[i] = cadd(tx_fdm[i], cmult(tx_baseband[c][i], phase_tx[c]));
+       }
+
+    /* add centre pilot tone  */
+
+    c = NC;
+    for (i=0; i<M; i++) {
+       phase_tx[c] = cmult(phase_tx[c],  freq[c]);
+       pilot = cmult(cmult(two, tx_baseband[c][i]), phase_tx[c]);
+       tx_fdm[i] = cadd(tx_fdm[i], pilot);
+    }
+
+    /*
+      Scale such that total Carrier power C of real(tx_fdm) = Nc.  This
+      excludes the power of the pilot tone.
+      We return the complex (single sided) signal to make frequency
+      shifting for the purpose of testing easier
+    */
+
+    for (i=0; i<M; i++) 
+       tx_fdm[i] = cmult(two, tx_fdm[i]);
+
+}
index 647b87bf5bed30cb9895c1cc8293f7275cc9b9fa..702dfc6f2135036e09e2ed75868e1cf3d258b2ab 100644 (file)
@@ -33,6 +33,8 @@
 extern "C" {
 #endif
 
+#include "comp.h"
+
 #define FDMDV_BITS_PER_FRAME     28
 #define FDMDV_SAMPLES_PER_FRAME 160
 
@@ -47,11 +49,10 @@ struct FDMDV_STATS {
     float  clock_offset; /* Estimated tx/rx sample clock offset in ppm         */
 };
 
-
 struct FDMDV *fdmdv_create(void);
 void          fdmdv_destroy(struct FDMDV *fdmdv_state);
     
-void          fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[]);
+void          fdmdv_mod(struct FDMDV *fdmdv_state, COMP tx_fdm[], int tx_bits[], int *sync);
 void          fdmdv_demod(struct FDMDV *fdmdv_state, int rx_bits[], int *sync, float rx_fdm[], int *nin);
     
 void          fdmdv_get_test_bits(struct FDMDV *fdmdv_state, int tx_bits[]);
index a995a42a0d0453a540d03f5e5d58a068bd3ee804..590e4a8b77e9905e140739530cc03b9dc5ca8988 100644 (file)
 #define NB                       2  /* Bits/symbol for QPSK modulation                                      */
 #define RB              (NC*RS*NB)  /* bit rate                                                             */
 #define M                  (FS/RS)  /* oversampling factor                                                  */
-#define NSYM                     4  /* number of symbols to filter over                                     */
+#define NSYM                     6  /* number of symbols to filter over                                     */
 #define FSEP                    75  /* Separation between carriers (Hz)                                     */
 #define FCENTRE               1200  /* Centre frequency, Nc/2 carriers below this, Nc/2 carriers above (Hz) */
 #define NT                       5  /* number of symbols we estimate timing over                            */
 #define P                        4  /* oversample factor used for initial rx symbol filtering               */
-#define NFILTER            (NSYM*M) /* size of tx/rx filters at sampel rate M                               */
+#define NFILTER            (NSYM*M) /* size of tx/rx filters at sample rate M                               */
 #define NFILTERTIMING (M+Nfilter+M) /* filter memory used for resampling after timing estimation            */
 
 #define NTEST_BITS        (NC*NB*4) /* length of test bit sequence */
 
+#define PI              3.141592654
+
 /*---------------------------------------------------------------------------*\
                                                                              
                                STRUCT for States
@@ -64,6 +66,9 @@ struct FDMDV {
     int  current_test_bit;
     int  tx_pilot_bit;
     COMP prev_tx_symbols[NC+1];
+    COMP tx_filter_memory[NC+1][NFILTER];
+    COMP phase_tx[NC+1];
+    COMP freq[NC+1];
 };
 
 /*---------------------------------------------------------------------------*\
@@ -73,5 +78,7 @@ struct FDMDV {
 \*---------------------------------------------------------------------------*/
 
 void bits_to_dqpsk_symbols(COMP tx_symbols[], COMP prev_tx_symbols[], int tx_bits[], int *pilot_bit);
+void tx_filter(COMP tx_baseband[NC+1][M], COMP tx_symbols[], COMP tx_filter_memory[NC+1][NFILTER]);
+void fdm_upconvert(COMP tx_fdm[], COMP tx_baseband[NC+1][M], COMP phase_tx[], COMP freq_tx[]);
 
 #endif
index 983c2e5b70c336b940abd6b0a7c3249626079e1a..934f458406a0d17813f94f65d3dbfea1bbf2c8f3 100644 (file)
-/*---------------------------------------------------------------------------*\
-                                                                             
-  FILE........: rn.h
-  AUTHOR......: David Rowe                                                          
-  DATE CREATED: April 14 2012
-                                                                             
-  Root raised cosine (Root Nyquist) filter for FDMDV modem.
-                                                                              
-\*---------------------------------------------------------------------------*/
+/* Generated by rn_file() Octave function */
 
-/*
-  Copyright (C) 2012 David Rowe
-
-  All rights reserved.
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU Lesser General Public License version 2.1, as
-  published by the Free Software Foundation.  This program is
-  distributed in the hope that it will be useful, but WITHOUT ANY
-  WARRANTY; without even the implied warranty of MERCHANTABILITY or
-  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
-  License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with this program; if not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef __RN__
-#define RN
-float gt_alpha5_root[] = {
-    3.15800872e-04,
-    2.79727588e-04,
-    2.69639516e-04,
-    2.64546231e-04,
-    2.61383099e-04,
-    2.59190148e-04,
-    2.57492732e-04,
-    2.56064964e-04,
-    2.54747225e-04,
-    2.53454837e-04,
-    2.52113149e-04,
-    2.50682027e-04,
-    2.49119413e-04,
-    2.47403391e-04,
-    2.45507283e-04,
-    2.43417952e-04,
-    2.41117044e-04,
-    2.38596156e-04,
-    2.35841900e-04,
-    2.32848649e-04,
-    2.29606198e-04,
-    2.26110660e-04,
-    2.22353999e-04,
-    2.18333484e-04,
-    2.14042642e-04,
-    2.09479573e-04,
-    2.04639000e-04,
-    1.99519666e-04,
-    1.94117271e-04,
-    1.88431116e-04,
-    1.82457746e-04,
-    1.76196986e-04,
-    1.69646155e-04,
-    1.62805599e-04,
-    1.55673382e-04,
-    1.48250378e-04,
-    1.40535377e-04,
-    1.32529803e-04,
-    1.24233156e-04,
-    1.15647422e-04,
-    1.06772798e-04,
-    9.76118372e-05,
-    8.81654134e-05,
-    7.84366425e-05,
-    6.84270511e-05,
-    5.81403041e-05,
-    4.75785517e-05,
-    3.67459901e-05,
-    2.56453615e-05,
-    1.42813733e-05,
-    2.65732925e-06,
-    -9.22157136e-06,
-    -2.13514908e-05,
-    -3.37267535e-05,
-    -4.63430099e-05,
-    -5.91941194e-05,
-    -7.22752369e-05,
-    -8.55797626e-05,
-    -9.91023660e-05,
-    -1.12835989e-04,
-    -1.26774821e-04,
-    -1.40911341e-04,
-    -1.55239261e-04,
-    -1.69750592e-04,
-    -1.84438565e-04,
-    -1.99294715e-04,
-    -2.14311789e-04,
-    -2.29480839e-04,
-    -2.44794128e-04,
-    -2.60242212e-04,
-    -2.75816871e-04,
-    -2.91508163e-04,
-    -3.07307383e-04,
-    -3.23204088e-04,
-    -3.39189096e-04,
-    -3.55251466e-04,
-    -3.71381551e-04,
-    -3.87567920e-04,
-    -4.03800479e-04,
-    -4.20067325e-04,
-    -4.36357946e-04,
-    -4.52659989e-04,
-    -4.68962566e-04,
-    -4.85252904e-04,
-    -5.01519786e-04,
-    -5.17750064e-04,
-    -5.33932244e-04,
-    -5.50052851e-04,
-    -5.66100178e-04,
-    -5.82060470e-04,
-    -5.97921867e-04,
-    -6.13670384e-04,
-    -6.29294070e-04,
-    -6.44778745e-04,
-    -6.60112423e-04,
-    -6.75280754e-04,
-    -6.90271758e-04,
-    -7.05070925e-04,
-    -7.19666310e-04,
-    -7.34043232e-04,
-    -7.48189797e-04,
-    -7.62091120e-04,
-    -7.75735364e-04,
-    -7.89107389e-04,
-    -8.02195418e-04,
-    -8.14983993e-04,
-    -8.27461403e-04,
-    -8.39611795e-04,
-    -8.51423552e-04,
-    -8.62880344e-04,
-    -8.73970705e-04,
-    -8.84677743e-04,
-    -8.94990252e-04,
-    -9.04890675e-04,
-    -9.14368254e-04,
-    -9.23404633e-04,
-    -9.31989791e-04,
-    -9.40104365e-04,
-    -9.47739538e-04,
-    -9.54874543e-04,
-    -9.61502551e-04,
-    -9.67600584e-04,
-    -9.73165279e-04,
-    -9.78169541e-04,
-    -9.82616937e-04,
-    -9.86470692e-04,
-    -9.89753203e-04,
-    -9.92390009e-04,
-    -9.94563745e-04,
-    -9.96356035e-04,
-    -9.97190272e-04,
-    -9.97385906e-04,
-    -9.96890492e-04,
-    -9.95735721e-04,
-    -9.93890788e-04,
-    -9.91364072e-04,
-    -9.88132863e-04,
-    -9.84198040e-04,
-    -9.79540856e-04,
-    -9.74158756e-04,
-    -9.68035333e-04,
-    -9.61166225e-04,
-    -9.53536634e-04,
-    -9.45141227e-04,
-    -9.35966472e-04,
-    -9.26006585e-04,
-    -9.15249147e-04,
-    -9.03688283e-04,
-    -8.91312634e-04,
-    -8.78116505e-04,
-    -8.64089591e-04,
-    -8.49226579e-04,
-    -8.33518227e-04,
-    -8.16959761e-04,
-    -7.99543007e-04,
-    -7.81263837e-04,
-    -7.62115141e-04,
-    -7.42093505e-04,
-    -7.21192864e-04,
-    -6.99410552e-04,
-    -6.76741515e-04,
-    -6.53183844e-04,
-    -6.28733457e-04,
-    -6.03389190e-04,
-    -5.77147887e-04,
-    -5.50009115e-04,
-    -5.21970595e-04,
-    -4.93032610e-04,
-    -4.63193720e-04,
-    -4.32454909e-04,
-    -4.00815549e-04,
-    -3.68277318e-04,
-    -3.34840383e-04,
-    -3.00507122e-04,
-    -2.65278490e-04,
-    -2.29157578e-04,
-    -1.92146130e-04,
-    -1.54247973e-04,
-    -1.15465652e-04,
-    -7.58037481e-05,
-    -3.52656246e-05,
-    6.14335925e-06,
-    4.84190059e-05,
-    9.15551544e-05,
-    1.35546760e-04,
-    1.80386840e-04,
-    2.26069491e-04,
-    2.72586893e-04,
-    3.19932279e-04,
-    3.68096980e-04,
-    4.17073365e-04,
-    4.66851910e-04,
-    5.17424122e-04,
-    5.68779624e-04,
-    6.20909069e-04,
-    6.73801232e-04,
-    7.27445923e-04,
-    7.81831078e-04,
-    8.36945686e-04,
-    8.92776854e-04,
-    9.49312772e-04,
-    1.00653974e-03,
-    1.06444516e-03,
-    1.12301455e-03,
-    1.18223458e-03,
-    1.24208997e-03,
-    1.30256668e-03,
-    1.36364870e-03,
-    1.42532128e-03,
-    1.48756769e-03,
-    1.55037250e-03,
-    1.61371827e-03,
-    1.67758894e-03,
-    1.74196634e-03,
-    1.80683380e-03,
-    1.87217245e-03,
-    1.93796500e-03,
-    2.00419187e-03,
-    2.07083517e-03,
-    2.13787462e-03,
-    2.20529174e-03,
-    2.27306554e-03,
-    2.34117698e-03,
-    2.40960436e-03,
-    2.47832809e-03,
-    2.54732581e-03,
-    2.61657744e-03,
-    2.68605994e-03,
-    2.75575284e-03,
-    2.82563247e-03,
-    2.89567806e-03,
-    2.96586537e-03,
-    3.03617345e-03,
-    3.10657756e-03,
-    3.17705672e-03,
-    3.24758578e-03,
-    3.31814387e-03,
-    3.38870549e-03,
-    3.45925010e-03,
-    3.52975187e-03,
-    3.60019081e-03,
-    3.67054075e-03,
-    3.74078249e-03,
-    3.81088946e-03,
-    3.88084361e-03,
-    3.95061774e-03,
-    4.02019545e-03,
-    4.08954860e-03,
-    4.15866330e-03,
-    4.22750990e-03,
-    4.29607892e-03,
-    4.36433818e-03,
-    4.43228800e-03,
-    4.49989238e-03,
-    4.56718497e-03,
-    4.63414034e-03,
-    4.70132291e-03,
-    4.76692608e-03,
-    4.83218137e-03,
-    4.89703501e-03,
-    4.96136981e-03,
-    5.02518690e-03,
-    5.08843431e-03,
-    5.15110299e-03,
-    5.21315463e-03,
-    5.27457565e-03,
-    5.33533355e-03,
-    5.39541259e-03,
-    5.45478362e-03,
-    5.51342992e-03,
-    5.57132465e-03,
-    5.62845070e-03,
-    5.68478300e-03,
-    5.74030441e-03,
-    5.79499130e-03,
-    5.84882670e-03,
-    5.90178821e-03,
-    5.95385913e-03,
-    6.00501811e-03,
-    6.05524878e-03,
-    6.10453076e-03,
-    6.15284804e-03,
-    6.20018109e-03,
-    6.24651431e-03,
-    6.29182896e-03,
-    6.33610990e-03,
-    6.37933917e-03,
-    6.42150209e-03,
-    6.46258151e-03,
-    6.50256328e-03,
-    6.54143105e-03,
-    6.57917131e-03,
-    6.61576852e-03,
-    6.65120988e-03,
-    6.68548075e-03,
-    6.71856907e-03,
-    6.75046115e-03,
-    6.78114576e-03,
-    6.81061020e-03,
-    6.83884413e-03,
-    6.86583586e-03,
-    6.89157602e-03,
-    6.91605393e-03,
-    6.93926120e-03,
-    6.96118822e-03,
-    6.98182760e-03,
-    7.00117076e-03,
-    7.01921133e-03,
-    7.03594180e-03,
-    7.05135678e-03,
-    7.06544981e-03,
-    7.07821650e-03,
-    7.08965141e-03,
-    7.09975114e-03,
-    7.10851128e-03,
-    7.11592939e-03,
-    7.12200207e-03,
-    7.12672785e-03,
-    7.13010431e-03,
-    7.13213096e-03,
-    7.13280635e-03,
-    7.13213096e-03,
-    7.13010431e-03,
-    7.12672785e-03,
-    7.12200207e-03,
-    7.11592939e-03,
-    7.10851128e-03,
-    7.09975114e-03,
-    7.08965141e-03,
-    7.07821650e-03,
-    7.06544981e-03,
-    7.05135678e-03,
-    7.03594180e-03,
-    7.01921133e-03,
-    7.00117076e-03,
-    6.98182760e-03,
-    6.96118822e-03,
-    6.93926120e-03,
-    6.91605393e-03,
-    6.89157602e-03,
-    6.86583586e-03,
-    6.83884413e-03,
-    6.81061020e-03,
-    6.78114576e-03,
-    6.75046115e-03,
-    6.71856907e-03,
-    6.68548075e-03,
-    6.65120988e-03,
-    6.61576852e-03,
-    6.57917131e-03,
-    6.54143105e-03,
-    6.50256328e-03,
-    6.46258151e-03,
-    6.42150209e-03,
-    6.37933917e-03,
-    6.33610990e-03,
-    6.29182896e-03,
-    6.24651431e-03,
-    6.20018109e-03,
-    6.15284804e-03,
-    6.10453076e-03,
-    6.05524878e-03,
-    6.00501811e-03,
-    5.95385913e-03,
-    5.90178821e-03,
-    5.84882670e-03,
-    5.79499130e-03,
-    5.74030441e-03,
-    5.68478300e-03,
-    5.62845070e-03,
-    5.57132465e-03,
-    5.51342992e-03,
-    5.45478362e-03,
-    5.39541259e-03,
-    5.33533355e-03,
-    5.27457565e-03,
-    5.21315463e-03,
-    5.15110299e-03,
-    5.08843431e-03,
-    5.02518690e-03,
-    4.96136981e-03,
-    4.89703501e-03,
-    4.83218137e-03,
-    4.76692608e-03,
-    4.70132291e-03,
-    4.63414034e-03,
-    4.56718497e-03,
-    4.49989238e-03,
-    4.43228800e-03,
-    4.36433818e-03,
-    4.29607892e-03,
-    4.22750990e-03,
-    4.15866330e-03,
-    4.08954860e-03,
-    4.02019545e-03,
-    3.95061774e-03,
-    3.88084361e-03,
-    3.81088946e-03,
-    3.74078249e-03,
-    3.67054075e-03,
-    3.60019081e-03,
-    3.52975187e-03,
-    3.45925010e-03,
-    3.38870549e-03,
-    3.31814387e-03,
-    3.24758578e-03,
-    3.17705672e-03,
-    3.10657756e-03,
-    3.03617345e-03,
-    2.96586537e-03,
-    2.89567806e-03,
-    2.82563247e-03,
-    2.75575284e-03,
-    2.68605994e-03,
-    2.61657744e-03,
-    2.54732581e-03,
-    2.47832809e-03,
-    2.40960436e-03,
-    2.34117698e-03,
-    2.27306554e-03,
-    2.20529174e-03,
-    2.13787462e-03,
-    2.07083517e-03,
-    2.00419187e-03,
-    1.93796500e-03,
-    1.87217245e-03,
-    1.80683380e-03,
-    1.74196634e-03,
-    1.67758894e-03,
-    1.61371827e-03,
-    1.55037250e-03,
-    1.48756769e-03,
-    1.42532128e-03,
-    1.36364870e-03,
-    1.30256668e-03,
-    1.24208997e-03,
-    1.18223458e-03,
-    1.12301455e-03,
-    1.06444516e-03,
-    1.00653974e-03,
-    9.49312772e-04,
-    8.92776854e-04,
-    8.36945686e-04,
-    7.81831078e-04,
-    7.27445923e-04,
-    6.73801232e-04,
-    6.20909069e-04,
-    5.68779624e-04,
-    5.17424122e-04,
-    4.66851910e-04,
-    4.17073365e-04,
-    3.68096980e-04,
-    3.19932279e-04,
-    2.72586893e-04,
-    2.26069491e-04,
-    1.80386840e-04,
-    1.35546760e-04,
-    9.15551544e-05,
-    4.84190059e-05,
-    6.14335925e-06,
-    -3.52656246e-05,
-    -7.58037481e-05,
-    -1.15465652e-04,
-    -1.54247973e-04,
-    -1.92146130e-04,
-    -2.29157578e-04,
-    -2.65278490e-04,
-    -3.00507122e-04,
-    -3.34840383e-04,
-    -3.68277318e-04,
-    -4.00815549e-04,
-    -4.32454909e-04,
-    -4.63193720e-04,
-    -4.93032610e-04,
-    -5.21970595e-04,
-    -5.50009115e-04,
-    -5.77147887e-04,
-    -6.03389190e-04,
-    -6.28733457e-04,
-    -6.53183844e-04,
-    -6.76741515e-04,
-    -6.99410552e-04,
-    -7.21192864e-04,
-    -7.42093505e-04,
-    -7.62115141e-04,
-    -7.81263837e-04,
-    -7.99543007e-04,
-    -8.16959761e-04,
-    -8.33518227e-04,
-    -8.49226579e-04,
-    -8.64089591e-04,
-    -8.78116505e-04,
-    -8.91312634e-04,
-    -9.03688283e-04,
-    -9.15249147e-04,
-    -9.26006585e-04,
-    -9.35966472e-04,
-    -9.45141227e-04,
-    -9.53536634e-04,
-    -9.61166225e-04,
-    -9.68035333e-04,
-    -9.74158756e-04,
-    -9.79540856e-04,
-    -9.84198040e-04,
-    -9.88132863e-04,
-    -9.91364072e-04,
-    -9.93890788e-04,
-    -9.95735721e-04,
-    -9.96890492e-04,
-    -9.97385906e-04,
-    -9.97190272e-04,
-    -9.96356035e-04,
-    -9.94563745e-04,
-    -9.92390009e-04,
-    -9.89753203e-04,
-    -9.86470692e-04,
-    -9.82616937e-04,
-    -9.78169541e-04,
-    -9.73165279e-04,
-    -9.67600584e-04,
-    -9.61502551e-04,
-    -9.54874543e-04,
-    -9.47739538e-04,
-    -9.40104365e-04,
-    -9.31989791e-04,
-    -9.23404633e-04,
-    -9.14368254e-04,
-    -9.04890675e-04,
-    -8.94990252e-04,
-    -8.84677743e-04,
-    -8.73970705e-04,
-    -8.62880344e-04,
-    -8.51423552e-04,
-    -8.39611795e-04,
-    -8.27461403e-04,
-    -8.14983993e-04,
-    -8.02195418e-04,
-    -7.89107389e-04,
-    -7.75735364e-04,
-    -7.62091120e-04,
-    -7.48189797e-04,
-    -7.34043232e-04,
-    -7.19666310e-04,
-    -7.05070925e-04,
-    -6.90271758e-04,
-    -6.75280754e-04,
-    -6.60112423e-04,
-    -6.44778745e-04,
-    -6.29294070e-04,
-    -6.13670384e-04,
-    -5.97921867e-04,
-    -5.82060470e-04,
-    -5.66100178e-04,
-    -5.50052851e-04,
-    -5.33932244e-04,
-    -5.17750064e-04,
-    -5.01519786e-04,
-    -4.85252904e-04,
-    -4.68962566e-04,
-    -4.52659989e-04,
-    -4.36357946e-04,
-    -4.20067325e-04,
-    -4.03800479e-04,
-    -3.87567920e-04,
-    -3.71381551e-04,
-    -3.55251466e-04,
-    -3.39189096e-04,
-    -3.23204088e-04,
-    -3.07307383e-04,
-    -2.91508163e-04,
-    -2.75816871e-04,
-    -2.60242212e-04,
-    -2.44794128e-04,
-    -2.29480839e-04,
-    -2.14311789e-04,
-    -1.99294715e-04,
-    -1.84438565e-04,
-    -1.69750592e-04,
-    -1.55239261e-04,
-    -1.40911341e-04,
-    -1.26774821e-04,
-    -1.12835989e-04,
-    -9.91023660e-05,
-    -8.55797626e-05,
-    -7.22752369e-05,
-    -5.91941194e-05,
-    -4.63430099e-05,
-    -3.37267535e-05,
-    -2.13514908e-05,
-    -9.22157136e-06,
-    2.65732925e-06,
-    1.42813733e-05,
-    2.56453615e-05,
-    3.67459901e-05,
-    4.75785517e-05,
-    5.81403041e-05,
-    6.84270511e-05,
-    7.84366425e-05,
-    8.81654134e-05,
-    9.76118372e-05,
-    1.06772798e-04,
-    1.15647422e-04,
-    1.24233156e-04,
-    1.32529803e-04,
-    1.40535377e-04,
-    1.48250378e-04,
-    1.55673382e-04,
-    1.62805599e-04,
-    1.69646155e-04,
-    1.76196986e-04,
-    1.82457746e-04,
-    1.88431116e-04,
-    1.94117271e-04,
-    1.99519666e-04,
-    2.04639000e-04,
-    2.09479573e-04,
-    2.14042642e-04,
-    2.18333484e-04,
-    2.22353999e-04,
-    2.26110660e-04,
-    2.29606198e-04,
-    2.32848649e-04,
-    2.35841900e-04,
-    2.38596156e-04,
-    2.41117044e-04,
-    2.43417952e-04,
-    2.45507283e-04,
-    2.47403391e-04,
-    2.49119413e-04,
-    2.50682027e-04,
-    2.52113149e-04,
-    2.53454837e-04,
-    2.54747225e-04,
-    2.56064964e-04,
-    2.57492732e-04,
-    2.59190148e-04,
-    2.61383099e-04,
-    2.64546231e-04,
-    2.69639516e-04,
-    2.79727588e-04
+const float gt_alpha5_root[]={
+  2.86997e-05,
+  2.2286e-05,
+  1.82863e-05,
+  1.42303e-05,
+  1.04905e-05,
+  6.70859e-06,
+  3.05918e-06,
+  -6.22187e-07,
+  -4.22748e-06,
+  -7.85603e-06,
+  -1.14317e-05,
+  -1.50227e-05,
+  -1.85712e-05,
+  -2.21275e-05,
+  -2.56455e-05,
+  -2.91642e-05,
+  -3.26453e-05,
+  -3.61199e-05,
+  -3.95556e-05,
+  -4.29778e-05,
+  -4.63581e-05,
+  -4.97179e-05,
+  -5.3032e-05,
+  -5.63184e-05,
+  -5.95548e-05,
+  -6.27565e-05,
+  -6.59032e-05,
+  -6.90085e-05,
+  -7.20538e-05,
+  -7.50509e-05,
+  -7.7983e-05,
+  -8.08605e-05,
+  -8.36678e-05,
+  -8.64141e-05,
+  -8.9085e-05,
+  -9.16888e-05,
+  -9.42119e-05,
+  -9.66619e-05,
+  -9.9026e-05,
+  -0.000101311,
+  -0.000103505,
+  -0.000105614,
+  -0.000107627,
+  -0.00010955,
+  -0.000111372,
+  -0.000113099,
+  -0.00011472,
+  -0.000116241,
+  -0.000117652,
+  -0.000118959,
+  -0.000120152,
+  -0.000121235,
+  -0.000122201,
+  -0.000123053,
+  -0.000123784,
+  -0.000124397,
+  -0.000124884,
+  -0.00012525,
+  -0.000125487,
+  -0.000125598,
+  -0.000125578,
+  -0.000125428,
+  -0.000125145,
+  -0.000124729,
+  -0.000124185,
+  -0.000123518,
+  -0.000122709,
+  -0.000121766,
+  -0.000120685,
+  -0.000119471,
+  -0.000118119,
+  -0.000116633,
+  -0.000115009,
+  -0.000113251,
+  -0.000111356,
+  -0.000109326,
+  -0.00010716,
+  -0.00010486,
+  -0.000102424,
+  -9.98553e-05,
+  -9.71528e-05,
+  -9.43199e-05,
+  -9.13551e-05,
+  -8.82623e-05,
+  -8.50404e-05,
+  -8.16936e-05,
+  -7.82211e-05,
+  -7.46271e-05,
+  -7.09109e-05,
+  -6.70773e-05,
+  -6.31256e-05,
+  -5.90607e-05,
+  -5.48823e-05,
+  -5.05954e-05,
+  -4.62001e-05,
+  -4.17016e-05,
+  -3.71002e-05,
+  -3.24015e-05,
+  -2.7606e-05,
+  -2.27195e-05,
+  -1.77428e-05,
+  -1.2682e-05,
+  -7.53795e-06,
+  -2.31702e-06,
+  2.97965e-06,
+  8.34567e-06,
+  1.37796e-05,
+  1.9275e-05,
+  2.483e-05,
+  3.04382e-05,
+  3.60975e-05,
+  4.18011e-05,
+  4.75467e-05,
+  5.33273e-05,
+  5.91403e-05,
+  6.49787e-05,
+  7.08393e-05,
+  7.67152e-05,
+  8.26029e-05,
+  8.84957e-05,
+  9.43895e-05,
+  0.000100278,
+  0.000106157,
+  0.00011202,
+  0.000117864,
+  0.000123681,
+  0.000129468,
+  0.000135218,
+  0.000140929,
+  0.000146583,
+  0.000152183,
+  0.000157725,
+  0.000163202,
+  0.000168608,
+  0.000173938,
+  0.000179183,
+  0.00018434,
+  0.0001894,
+  0.00019436,
+  0.000199211,
+  0.000203949,
+  0.000208568,
+  0.000213063,
+  0.000217426,
+  0.000221654,
+  0.00022574,
+  0.000229678,
+  0.000233463,
+  0.000237089,
+  0.000240551,
+  0.000243843,
+  0.000246959,
+  0.000249895,
+  0.000252644,
+  0.000255202,
+  0.000257562,
+  0.000259721,
+  0.000261672,
+  0.000263411,
+  0.000264933,
+  0.000266234,
+  0.000267308,
+  0.000268152,
+  0.00026876,
+  0.000269128,
+  0.000269253,
+  0.000269129,
+  0.000268754,
+  0.000268123,
+  0.000267232,
+  0.000266079,
+  0.000264658,
+  0.000262968,
+  0.000261006,
+  0.000258767,
+  0.000256251,
+  0.000253453,
+  0.000250373,
+  0.000247007,
+  0.000243354,
+  0.000239412,
+  0.00023518,
+  0.000230655,
+  0.000225837,
+  0.000220723,
+  0.000215314,
+  0.000209608,
+  0.000203605,
+  0.000197304,
+  0.000190706,
+  0.000183812,
+  0.000176621,
+  0.000169145,
+  0.000161363,
+  0.000153275,
+  0.000144895,
+  0.000136224,
+  0.000127266,
+  0.00011802,
+  0.000108491,
+  9.8679e-05,
+  8.85877e-05,
+  7.82196e-05,
+  6.7577e-05,
+  5.66636e-05,
+  4.54822e-05,
+  3.40369e-05,
+  2.23311e-05,
+  1.03695e-05,
+  -1.844e-06,
+  -1.43041e-05,
+  -2.70061e-05,
+  -3.99444e-05,
+  -5.31139e-05,
+  -6.65082e-05,
+  -8.01218e-05,
+  -9.39481e-05,
+  -0.000107981,
+  -0.000122213,
+  -0.000136638,
+  -0.000151248,
+  -0.000166036,
+  -0.000180995,
+  -0.000196115,
+  -0.00021139,
+  -0.000226811,
+  -0.000242369,
+  -0.000258056,
+  -0.000273861,
+  -0.000289776,
+  -0.000305792,
+  -0.000321898,
+  -0.000338084,
+  -0.000354342,
+  -0.00037066,
+  -0.000387027,
+  -0.000403434,
+  -0.00041987,
+  -0.000436324,
+  -0.000452784,
+  -0.00046924,
+  -0.00048568,
+  -0.000502091,
+  -0.000518464,
+  -0.000534785,
+  -0.000551043,
+  -0.000567225,
+  -0.000583319,
+  -0.000599314,
+  -0.000615196,
+  -0.000630955,
+  -0.000646575,
+  -0.000662049,
+  -0.000677361,
+  -0.000692506,
+  -0.000707464,
+  -0.00072229,
+  -0.000736922,
+  -0.000751266,
+  -0.000765372,
+  -0.000779217,
+  -0.000792798,
+  -0.000806094,
+  -0.000819098,
+  -0.000831793,
+  -0.000844168,
+  -0.000856207,
+  -0.000867898,
+  -0.000879227,
+  -0.00089018,
+  -0.000900744,
+  -0.000910906,
+  -0.000920652,
+  -0.00092997,
+  -0.000938844,
+  -0.000947263,
+  -0.000955214,
+  -0.000962682,
+  -0.000969654,
+  -0.000976119,
+  -0.000982062,
+  -0.00098747,
+  -0.000992332,
+  -0.000996634,
+  -0.00100036,
+  -0.00100351,
+  -0.00100606,
+  -0.001008,
+  -0.00100932,
+  -0.00101,
+  -0.00101005,
+  -0.00100943,
+  -0.00100816,
+  -0.0010062,
+  -0.00100356,
+  -0.00100021,
+  -0.000996162,
+  -0.000991392,
+  -0.000985892,
+  -0.000979654,
+  -0.000972668,
+  -0.000964925,
+  -0.000956415,
+  -0.000947131,
+  -0.000937065,
+  -0.000926208,
+  -0.000914552,
+  -0.00090209,
+  -0.000888816,
+  -0.000874721,
+  -0.0008598,
+  -0.000844046,
+  -0.000827453,
+  -0.000810015,
+  -0.000791726,
+  -0.000772581,
+  -0.000752576,
+  -0.000731704,
+  -0.000709965,
+  -0.00068735,
+  -0.000663865,
+  -0.000639509,
+  -0.000614269,
+  -0.000588146,
+  -0.000561139,
+  -0.000533246,
+  -0.000504468,
+  -0.000474802,
+  -0.000444251,
+  -0.000412813,
+  -0.00038049,
+  -0.000347281,
+  -0.000313189,
+  -0.000278215,
+  -0.000242361,
+  -0.000205629,
+  -0.000168024,
+  -0.000129546,
+  -9.02024e-05,
+  -4.99954e-05,
+  -8.93026e-06,
+  3.2988e-05,
+  7.57537e-05,
+  0.000119361,
+  0.000163804,
+  0.000209075,
+  0.000255167,
+  0.000302074,
+  0.000349786,
+  0.000398297,
+  0.000447596,
+  0.000497676,
+  0.000548526,
+  0.000600136,
+  0.000652497,
+  0.000705598,
+  0.000759427,
+  0.000813972,
+  0.000869223,
+  0.000925166,
+  0.000981789,
+  0.00103908,
+  0.00109702,
+  0.00115561,
+  0.00121482,
+  0.00127464,
+  0.00133505,
+  0.00139605,
+  0.00145762,
+  0.00151973,
+  0.00158238,
+  0.00164555,
+  0.00170922,
+  0.00177337,
+  0.00183799,
+  0.00190305,
+  0.00196854,
+  0.00203445,
+  0.00210075,
+  0.00216742,
+  0.00223445,
+  0.00230181,
+  0.00236949,
+  0.00243747,
+  0.00250572,
+  0.00257423,
+  0.00264296,
+  0.00271192,
+  0.00278107,
+  0.00285039,
+  0.00291986,
+  0.00298947,
+  0.00305918,
+  0.00312898,
+  0.00319884,
+  0.00326874,
+  0.00333866,
+  0.00340857,
+  0.00347846,
+  0.00354831,
+  0.00361808,
+  0.00368775,
+  0.00375731,
+  0.00382673,
+  0.00389599,
+  0.00396506,
+  0.00403393,
+  0.00410256,
+  0.00417094,
+  0.00423904,
+  0.00430684,
+  0.00437431,
+  0.00444144,
+  0.0045082,
+  0.00457457,
+  0.00464052,
+  0.00470603,
+  0.00477108,
+  0.00483565,
+  0.00489972,
+  0.00496325,
+  0.00502623,
+  0.00508865,
+  0.00515046,
+  0.00521166,
+  0.00527223,
+  0.00533213,
+  0.00539135,
+  0.00544987,
+  0.00550766,
+  0.00556472,
+  0.005621,
+  0.00567651,
+  0.00573121,
+  0.00578508,
+  0.00583811,
+  0.00589028,
+  0.00594157,
+  0.00599196,
+  0.00604143,
+  0.00608996,
+  0.00613754,
+  0.00618415,
+  0.00622977,
+  0.00627439,
+  0.00631798,
+  0.00636054,
+  0.00640204,
+  0.0064425,
+  0.00648186,
+  0.00652009,
+  0.00655722,
+  0.00659322,
+  0.00662808,
+  0.00666179,
+  0.00669433,
+  0.00672571,
+  0.00675589,
+  0.00678488,
+  0.00681266,
+  0.00683921,
+  0.00686454,
+  0.00688863,
+  0.00691147,
+  0.00693305,
+  0.00695336,
+  0.0069724,
+  0.00699016,
+  0.00700663,
+  0.00702181,
+  0.00703569,
+  0.00704826,
+  0.00705952,
+  0.00706947,
+  0.00707809,
+  0.0070854,
+  0.00709138,
+  0.00709604,
+  0.00709937,
+  0.00710136,
+  0.00710203,
+  0.00710136,
+  0.00709937,
+  0.00709604,
+  0.00709138,
+  0.0070854,
+  0.00707809,
+  0.00706947,
+  0.00705952,
+  0.00704826,
+  0.00703569,
+  0.00702181,
+  0.00700663,
+  0.00699016,
+  0.0069724,
+  0.00695336,
+  0.00693305,
+  0.00691147,
+  0.00688863,
+  0.00686454,
+  0.00683921,
+  0.00681266,
+  0.00678488,
+  0.00675589,
+  0.00672571,
+  0.00669433,
+  0.00666179,
+  0.00662808,
+  0.00659322,
+  0.00655722,
+  0.00652009,
+  0.00648186,
+  0.0064425,
+  0.00640204,
+  0.00636054,
+  0.00631798,
+  0.00627439,
+  0.00622977,
+  0.00618415,
+  0.00613754,
+  0.00608996,
+  0.00604143,
+  0.00599196,
+  0.00594157,
+  0.00589028,
+  0.00583811,
+  0.00578508,
+  0.00573121,
+  0.00567651,
+  0.005621,
+  0.00556472,
+  0.00550766,
+  0.00544987,
+  0.00539135,
+  0.00533213,
+  0.00527223,
+  0.00521166,
+  0.00515046,
+  0.00508865,
+  0.00502623,
+  0.00496325,
+  0.00489972,
+  0.00483565,
+  0.00477108,
+  0.00470603,
+  0.00464052,
+  0.00457457,
+  0.0045082,
+  0.00444144,
+  0.00437431,
+  0.00430684,
+  0.00423904,
+  0.00417094,
+  0.00410256,
+  0.00403393,
+  0.00396506,
+  0.00389599,
+  0.00382673,
+  0.00375731,
+  0.00368775,
+  0.00361808,
+  0.00354831,
+  0.00347846,
+  0.00340857,
+  0.00333866,
+  0.00326874,
+  0.00319884,
+  0.00312898,
+  0.00305918,
+  0.00298947,
+  0.00291986,
+  0.00285039,
+  0.00278107,
+  0.00271192,
+  0.00264296,
+  0.00257423,
+  0.00250572,
+  0.00243747,
+  0.00236949,
+  0.00230181,
+  0.00223445,
+  0.00216742,
+  0.00210075,
+  0.00203445,
+  0.00196854,
+  0.00190305,
+  0.00183799,
+  0.00177337,
+  0.00170922,
+  0.00164555,
+  0.00158238,
+  0.00151973,
+  0.00145762,
+  0.00139605,
+  0.00133505,
+  0.00127464,
+  0.00121482,
+  0.00115561,
+  0.00109702,
+  0.00103908,
+  0.000981789,
+  0.000925166,
+  0.000869223,
+  0.000813972,
+  0.000759427,
+  0.000705598,
+  0.000652497,
+  0.000600136,
+  0.000548526,
+  0.000497676,
+  0.000447596,
+  0.000398297,
+  0.000349786,
+  0.000302074,
+  0.000255167,
+  0.000209075,
+  0.000163804,
+  0.000119361,
+  7.57537e-05,
+  3.2988e-05,
+  -8.93026e-06,
+  -4.99954e-05,
+  -9.02024e-05,
+  -0.000129546,
+  -0.000168024,
+  -0.000205629,
+  -0.000242361,
+  -0.000278215,
+  -0.000313189,
+  -0.000347281,
+  -0.00038049,
+  -0.000412813,
+  -0.000444251,
+  -0.000474802,
+  -0.000504468,
+  -0.000533246,
+  -0.000561139,
+  -0.000588146,
+  -0.000614269,
+  -0.000639509,
+  -0.000663865,
+  -0.00068735,
+  -0.000709965,
+  -0.000731704,
+  -0.000752576,
+  -0.000772581,
+  -0.000791726,
+  -0.000810015,
+  -0.000827453,
+  -0.000844046,
+  -0.0008598,
+  -0.000874721,
+  -0.000888816,
+  -0.00090209,
+  -0.000914552,
+  -0.000926208,
+  -0.000937065,
+  -0.000947131,
+  -0.000956415,
+  -0.000964925,
+  -0.000972668,
+  -0.000979654,
+  -0.000985892,
+  -0.000991392,
+  -0.000996162,
+  -0.00100021,
+  -0.00100356,
+  -0.0010062,
+  -0.00100816,
+  -0.00100943,
+  -0.00101005,
+  -0.00101,
+  -0.00100932,
+  -0.001008,
+  -0.00100606,
+  -0.00100351,
+  -0.00100036,
+  -0.000996634,
+  -0.000992332,
+  -0.00098747,
+  -0.000982062,
+  -0.000976119,
+  -0.000969654,
+  -0.000962682,
+  -0.000955214,
+  -0.000947263,
+  -0.000938844,
+  -0.00092997,
+  -0.000920652,
+  -0.000910906,
+  -0.000900744,
+  -0.00089018,
+  -0.000879227,
+  -0.000867898,
+  -0.000856207,
+  -0.000844168,
+  -0.000831793,
+  -0.000819098,
+  -0.000806094,
+  -0.000792798,
+  -0.000779217,
+  -0.000765372,
+  -0.000751266,
+  -0.000736922,
+  -0.00072229,
+  -0.000707464,
+  -0.000692506,
+  -0.000677361,
+  -0.000662049,
+  -0.000646575,
+  -0.000630955,
+  -0.000615196,
+  -0.000599314,
+  -0.000583319,
+  -0.000567225,
+  -0.000551043,
+  -0.000534785,
+  -0.000518464,
+  -0.000502091,
+  -0.00048568,
+  -0.00046924,
+  -0.000452784,
+  -0.000436324,
+  -0.00041987,
+  -0.000403434,
+  -0.000387027,
+  -0.00037066,
+  -0.000354342,
+  -0.000338084,
+  -0.000321898,
+  -0.000305792,
+  -0.000289776,
+  -0.000273861,
+  -0.000258056,
+  -0.000242369,
+  -0.000226811,
+  -0.00021139,
+  -0.000196115,
+  -0.000180995,
+  -0.000166036,
+  -0.000151248,
+  -0.000136638,
+  -0.000122213,
+  -0.000107981,
+  -9.39481e-05,
+  -8.01218e-05,
+  -6.65082e-05,
+  -5.31139e-05,
+  -3.99444e-05,
+  -2.70061e-05,
+  -1.43041e-05,
+  -1.844e-06,
+  1.03695e-05,
+  2.23311e-05,
+  3.40369e-05,
+  4.54822e-05,
+  5.66636e-05,
+  6.7577e-05,
+  7.82196e-05,
+  8.85877e-05,
+  9.8679e-05,
+  0.000108491,
+  0.00011802,
+  0.000127266,
+  0.000136224,
+  0.000144895,
+  0.000153275,
+  0.000161363,
+  0.000169145,
+  0.000176621,
+  0.000183812,
+  0.000190706,
+  0.000197304,
+  0.000203605,
+  0.000209608,
+  0.000215314,
+  0.000220723,
+  0.000225837,
+  0.000230655,
+  0.00023518,
+  0.000239412,
+  0.000243354,
+  0.000247007,
+  0.000250373,
+  0.000253453,
+  0.000256251,
+  0.000258767,
+  0.000261006,
+  0.000262968,
+  0.000264658,
+  0.000266079,
+  0.000267232,
+  0.000268123,
+  0.000268754,
+  0.000269129,
+  0.000269253,
+  0.000269128,
+  0.00026876,
+  0.000268152,
+  0.000267308,
+  0.000266234,
+  0.000264933,
+  0.000263411,
+  0.000261672,
+  0.000259721,
+  0.000257562,
+  0.000255202,
+  0.000252644,
+  0.000249895,
+  0.000246959,
+  0.000243843,
+  0.000240551,
+  0.000237089,
+  0.000233463,
+  0.000229678,
+  0.00022574,
+  0.000221654,
+  0.000217426,
+  0.000213063,
+  0.000208568,
+  0.000203949,
+  0.000199211,
+  0.00019436,
+  0.0001894,
+  0.00018434,
+  0.000179183,
+  0.000173938,
+  0.000168608,
+  0.000163202,
+  0.000157725,
+  0.000152183,
+  0.000146583,
+  0.000140929,
+  0.000135218,
+  0.000129468,
+  0.000123681,
+  0.000117864,
+  0.00011202,
+  0.000106157,
+  0.000100278,
+  9.43895e-05,
+  8.84957e-05,
+  8.26029e-05,
+  7.67152e-05,
+  7.08393e-05,
+  6.49787e-05,
+  5.91403e-05,
+  5.33273e-05,
+  4.75467e-05,
+  4.18011e-05,
+  3.60975e-05,
+  3.04382e-05,
+  2.483e-05,
+  1.9275e-05,
+  1.37796e-05,
+  8.34567e-06,
+  2.97965e-06,
+  -2.31702e-06,
+  -7.53795e-06,
+  -1.2682e-05,
+  -1.77428e-05,
+  -2.27195e-05,
+  -2.7606e-05,
+  -3.24015e-05,
+  -3.71002e-05,
+  -4.17016e-05,
+  -4.62001e-05,
+  -5.05954e-05,
+  -5.48823e-05,
+  -5.90607e-05,
+  -6.31256e-05,
+  -6.70773e-05,
+  -7.09109e-05,
+  -7.46271e-05,
+  -7.82211e-05,
+  -8.16936e-05,
+  -8.50404e-05,
+  -8.82623e-05,
+  -9.13551e-05,
+  -9.43199e-05,
+  -9.71528e-05,
+  -9.98553e-05,
+  -0.000102424,
+  -0.00010486,
+  -0.00010716,
+  -0.000109326,
+  -0.000111356,
+  -0.000113251,
+  -0.000115009,
+  -0.000116633,
+  -0.000118119,
+  -0.000119471,
+  -0.000120685,
+  -0.000121766,
+  -0.000122709,
+  -0.000123518,
+  -0.000124185,
+  -0.000124729,
+  -0.000125145,
+  -0.000125428,
+  -0.000125578,
+  -0.000125598,
+  -0.000125487,
+  -0.00012525,
+  -0.000124884,
+  -0.000124397,
+  -0.000123784,
+  -0.000123053,
+  -0.000122201,
+  -0.000121235,
+  -0.000120152,
+  -0.000118959,
+  -0.000117652,
+  -0.000116241,
+  -0.00011472,
+  -0.000113099,
+  -0.000111372,
+  -0.00010955,
+  -0.000107627,
+  -0.000105614,
+  -0.000103505,
+  -0.000101311,
+  -9.9026e-05,
+  -9.66619e-05,
+  -9.42119e-05,
+  -9.16888e-05,
+  -8.9085e-05,
+  -8.64141e-05,
+  -8.36678e-05,
+  -8.08605e-05,
+  -7.7983e-05,
+  -7.50509e-05,
+  -7.20538e-05,
+  -6.90085e-05,
+  -6.59032e-05,
+  -6.27565e-05,
+  -5.95548e-05,
+  -5.63184e-05,
+  -5.3032e-05,
+  -4.97179e-05,
+  -4.63581e-05,
+  -4.29778e-05,
+  -3.95556e-05,
+  -3.61199e-05,
+  -3.26453e-05,
+  -2.91642e-05,
+  -2.56455e-05,
+  -2.21275e-05,
+  -1.85712e-05,
+  -1.50227e-05,
+  -1.14317e-05,
+  -7.85603e-06,
+  -4.22748e-06,
+  -6.22187e-07,
+  3.05918e-06,
+  6.70859e-06,
+  1.04905e-05,
+  1.42303e-05,
+  1.82863e-05,
+  2.2286e-05
 };
-
-#endif
index 06b2c05bcc8905acd84ffabe70a0b7341a7a58be..4c3c5de69e16a559ed555311157bc1d9aecb286a 100644 (file)
 #include "fdmdv_internal.h"
 #include "fdmdv.h"
 
-#define FRAMES 10
+#define FRAMES 25
 
-void octave_save_int(FILE *f, char name[], int data[], int len);
-void octave_save_complex(FILE *f, char name[], COMP data[], int len);
+void octave_save_int(FILE *f, char name[], int data[], int rows, int cols);
+void octave_save_complex(FILE *f, char name[], COMP data[], int rows, int cols);
 
 int main(int argc, char *argv[])
 {
     struct FDMDV *fdmdv;
-    int           tx_bits[FDMDV_BITS_PER_FRAME*FRAMES];
-    COMP          tx_symbols[(NC+1)*FRAMES];
+    int           tx_bits[FDMDV_BITS_PER_FRAME];
+    COMP          tx_symbols[(NC+1)];
+    COMP          tx_baseband[(NC+1)][M];
+    COMP          tx_fdm[M];
+
+    int           tx_bits_log[FDMDV_BITS_PER_FRAME*FRAMES];
+    COMP          tx_symbols_log[(NC+1)*FRAMES];
+    COMP          tx_baseband_log[(NC+1)][M*FRAMES];
+    COMP          tx_fdm_log[M*FRAMES];
+
     FILE         *fout;
-    int           f,i;
+    int           f,c,i;
 
     fdmdv = fdmdv_create();
 
     for(f=0; f<FRAMES; f++) {
-       fdmdv_get_test_bits(fdmdv, &tx_bits[FDMDV_BITS_PER_FRAME*f]);
-       bits_to_dqpsk_symbols(&tx_symbols[(NC+1)*f], fdmdv->prev_tx_symbols, 
-                             &tx_bits[FDMDV_BITS_PER_FRAME*f], &fdmdv->tx_pilot_bit);
-       memcpy(fdmdv->prev_tx_symbols, &tx_symbols[(NC+1)*f], (NC+1)*sizeof(COMP));
+       fdmdv_get_test_bits(fdmdv, tx_bits);
+       bits_to_dqpsk_symbols(tx_symbols, fdmdv->prev_tx_symbols, tx_bits, &fdmdv->tx_pilot_bit);
+       memcpy(fdmdv->prev_tx_symbols, tx_symbols, sizeof(COMP)*(NC+1));
+       tx_filter(tx_baseband, tx_symbols, fdmdv->tx_filter_memory);
+       fdm_upconvert(tx_fdm, tx_baseband, fdmdv->phase_tx, fdmdv->freq);
+  
+       /* save log of outputs */
+
+       memcpy(&tx_bits_log[FDMDV_BITS_PER_FRAME*f], tx_bits, sizeof(int)*FDMDV_BITS_PER_FRAME);
+       memcpy(&tx_symbols_log[(NC+1)*f], tx_symbols, sizeof(COMP)*(NC+1));
+       for(c=0; c<NC+1; c++)
+           for(i=0; i<M; i++)
+               tx_baseband_log[c][f*M+i] = tx_baseband[c][i]; 
+       memcpy(&tx_fdm_log[M*f], tx_fdm, sizeof(COMP)*M);
     }
+
     codec2_destroy(fdmdv);
 
-    /* dump to Octave file for evaluation by Octave script */
+    /* dump logs to Octave file for evaluation by tfdmdv.m Octave script */
 
     fout = fopen("tfdmdv_out.txt","wt");
     assert(fout != NULL);
     fprintf(fout, "# Created by tfdmdv.c\n");
-    octave_save_int(fout, "tx_bits_tfdmdv", tx_bits, FDMDV_BITS_PER_FRAME*FRAMES);
-    octave_save_complex(fout, "tx_symbols_tfdmdv", tx_symbols, (NC+1)*FRAMES);  
+    octave_save_int(fout, "tx_bits_log_c", tx_bits_log, 1, FDMDV_BITS_PER_FRAME*FRAMES);
+    octave_save_complex(fout, "tx_symbols_log_c", tx_symbols_log, 1, (NC+1)*FRAMES);  
+    octave_save_complex(fout, "tx_baseband_log_c", (COMP*)tx_baseband_log, (NC+1), M*FRAMES);  
+    octave_save_complex(fout, "tx_fdm_log_c", (COMP*)tx_fdm_log, 1, M*FRAMES);  
     fclose(fout);
 
     return 0;
 }
 
-void octave_save_int(FILE *f, char name[], int data[], int len)
+void octave_save_int(FILE *f, char name[], int data[], int rows, int cols)
 {
-    int i;
+    int r,c;
 
     fprintf(f, "# name: %s\n", name);
     fprintf(f, "# type: matrix\n");
-    fprintf(f, "# rows: %d\n", 1);
-    fprintf(f, "# columns: %d\n", len);
+    fprintf(f, "# rows: %d\n", rows);
+    fprintf(f, "# columns: %d\n", cols);
     
-    for(i=0; i<len; i++)
-       fprintf(f, " %d", data[i]);
+    for(r=0; r<rows; r++) {
+       for(c=0; c<cols; c++)
+           fprintf(f, " %d", data[r*cols+c]);
+       fprintf(f, "\n");
+    }
 
-    fprintf(f, "\n\n\n");
+    fprintf(f, "\n\n");
 }
 
-void octave_save_complex(FILE *f, char name[], COMP data[], int len)
+void octave_save_complex(FILE *f, char name[], COMP data[], int rows, int cols)
 {
-    int i;
+    int r,c;
 
     fprintf(f, "# name: %s\n", name);
     fprintf(f, "# type: complex matrix\n");
-    fprintf(f, "# rows: %d\n", 1);
-    fprintf(f, "# columns: %d\n", len);
+    fprintf(f, "# rows: %d\n", rows);
+    fprintf(f, "# columns: %d\n", cols);
     
-    for(i=0; i<len; i++)
-       fprintf(f, " (%f,%f)", data[i].real, data[i].imag);
+    for(r=0; r<rows; r++) {
+       for(c=0; c<cols; c++)
+           fprintf(f, " (%f,%f)", data[r*cols+c].real, data[r*cols+c].imag);
+       fprintf(f, "\n");
+    }
 
-    fprintf(f, "\n\n\n");
+    fprintf(f, "\n\n");
 }