16<->8 kHz sample rate conversion filters
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 11 Jul 2014 06:56:03 +0000 (06:56 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Fri, 11 Jul 2014 06:56:03 +0000 (06:56 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@1755 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/codec2_fdmdv.h
codec2-dev/src/fdmdv.c
codec2-dev/src/os.h
codec2-dev/unittest/CMakeLists.txt

index 02a888ede707b4454d20156a58590077fb5147dd..8dacab262b54c2375e1163c1281fc116d08e973c 100644 (file)
@@ -68,7 +68,7 @@ extern "C" {
 
 /* 8 to 48 kHz sample rate conversion */
 
-#define FDMDV_OS                 6         /* oversampling rate           */
+#define FDMDV_OS                 2         /* oversampling rate           */
 #define FDMDV_OS_TAPS           48         /* number of OS filter taps    */
 
 /* FFT points */
@@ -107,8 +107,8 @@ void           fdmdv_put_test_bits(struct FDMDV *f, int *sync, short error_patte
 void           fdmdv_get_demod_stats(struct FDMDV *fdmdv_state, struct FDMDV_STATS *fdmdv_stats);
 void           fdmdv_get_rx_spectrum(struct FDMDV *fdmdv_state, float mag_dB[], COMP rx_fdm[], int nin);
 
-void           fdmdv_8_to_48(float out48k[], float in8k[], int n);
-void           fdmdv_48_to_8(float out8k[], float in48k[], int n);
+void           fdmdv_8_to_16(float out16k[], float in8k[], int n);
+void           fdmdv_16_to_8(float out8k[], float in16k[], int n);
 
 void           fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_phase_rect, int nin);
 
index e475d4be0c2ecd2ac0315eacaaa1c792a3ae8cdd..0498aea0a353d01bf1684410ed0e095b0d408769 100644 (file)
@@ -1478,29 +1478,16 @@ void fdmdv_get_demod_stats(struct FDMDV *fdmdv, struct FDMDV_STATS *fdmdv_stats)
 
 /*---------------------------------------------------------------------------*\
                                                        
-  FUNCTION....: fdmdv_8_to_48()             
+  FUNCTION....: fdmdv_8_to_16()             
   AUTHOR......: David Rowe                           
   DATE CREATED: 9 May 2012
 
-  Changes the sample rate of a signal from 8 to 48 kHz.  Experience
-  with PC based modems has shown that PC sound cards have a more
-  accurate sample clock when set for 48 kHz than 8 kHz.
-
-  n is the number of samples at the 8 kHz rate, there are FDMDV_OS*n samples
-  at the 48 kHz rate.  A memory of FDMDV_OS_TAPS/FDMDV_OS samples is reqd for
-  in8k[] (see t48_8.c unit test as example).
-
-  This is a classic polyphase upsampler.  We take the 8 kHz samples
-  and insert (FDMDV_OS-1) zeroes between each sample, then
-  FDMDV_OS_TAPS FIR low pass filter the signal at 4kHz.  As most of
-  the input samples are zeroes, we only need to multiply non-zero
-  input samples by filter coefficients.  The zero insertion and
-  filtering are combined in the code below and I'm too lazy to explain
-  it further right now....
+  Changes the sample rate of a signal from 8 to 16 kHz.  Support function for
+  SM1000.
 
 \*---------------------------------------------------------------------------*/
 
-void fdmdv_8_to_48(float out48k[], float in8k[], int n)
+void fdmdv_8_to_16(float out16k[], float in8k[], int n)
 {
     int i,j,k,l;
 
@@ -1511,10 +1498,10 @@ void fdmdv_8_to_48(float out48k[], float in8k[], int n)
 
     for(i=0; i<n; i++) {
        for(j=0; j<FDMDV_OS; j++) {
-           out48k[i*FDMDV_OS+j] = 0.0;
+           out16k[i*FDMDV_OS+j] = 0.0;
            for(k=0,l=0; k<FDMDV_OS_TAPS; k+=FDMDV_OS,l++)
-               out48k[i*FDMDV_OS+j] += fdmdv_os_filter[k+j]*in8k[i-l];
-           out48k[i*FDMDV_OS+j] *= FDMDV_OS;
+               out16k[i*FDMDV_OS+j] += fdmdv_os_filter[k+j]*in8k[i-l];
+           out16k[i*FDMDV_OS+j] *= FDMDV_OS;
            
        }
     }  
@@ -1528,35 +1515,35 @@ void fdmdv_8_to_48(float out48k[], float in8k[], int n)
 
 /*---------------------------------------------------------------------------*\
                                                        
-  FUNCTION....: fdmdv_48_to_8()             
+  FUNCTION....: fdmdv_16_to_8()             
   AUTHOR......: David Rowe                           
   DATE CREATED: 9 May 2012
 
-  Changes the sample rate of a signal from 48 to 8 kHz.
+  Changes the sample rate of a signal from 16 to 8 kHz.
  
   n is the number of samples at the 8 kHz rate, there are FDMDV_OS*n
   samples at the 48 kHz rate.  As above however a memory of
-  FDMDV_OS_TAPS samples is reqd for in48k[] (see t48_8.c unit test as example).
+  FDMDV_OS_TAPS samples is reqd for in16k[] (see t16_8.c unit test as example).
 
-  Low pass filter the 48 kHz signal at 4 kHz using the same filter as
+  Low pass filter the 16 kHz signal at 4 kHz using the same filter as
   the upsampler, then just output every FDMDV_OS-th filtered sample.
 
 \*---------------------------------------------------------------------------*/
 
-void fdmdv_48_to_8(float out8k[], float in48k[], int n)
+void fdmdv_16_to_8(float out8k[], float in16k[], int n)
 {
     int i,j;
 
     for(i=0; i<n; i++) {
        out8k[i] = 0.0;
        for(j=0; j<FDMDV_OS_TAPS; j++)
-           out8k[i] += fdmdv_os_filter[j]*in48k[i*FDMDV_OS-j];
+           out8k[i] += fdmdv_os_filter[j]*in16k[i*FDMDV_OS-j];
     }
 
     /* update filter memory */
 
     for(i=-FDMDV_OS_TAPS; i<0; i++)
-       in48k[i] = in48k[i + n*FDMDV_OS];
+       in16k[i] = in16k[i + n*FDMDV_OS];
 }
 
 /*---------------------------------------------------------------------------*\
index 0dae9bfd24ef452cd56052cf8f025e0a70d98eda..ee2502862b9b38fa117513a8d6b6cca5cdc83abb 100644 (file)
@@ -1,53 +1,53 @@
-/* Generate using fir1(47,1/6) in Octave */
+/* Generate using fir1(47,1/2) in Octave */
 
 const float fdmdv_os_filter[]= {
-    -3.55606818e-04,
-    -8.98615286e-04,
-    -1.40119781e-03,
-    -1.71713852e-03,
-    -1.56471179e-03,
-    -6.28128960e-04,
-    1.24522223e-03,
-    3.83138676e-03,
-    6.41309478e-03,
-    7.85893186e-03,
-    6.93514929e-03,
-    2.79361991e-03,
-    -4.51051400e-03,
-    -1.36671853e-02,
-    -2.21034939e-02,
-    -2.64084653e-02,
-    -2.31425052e-02,
-    -9.84218694e-03,
-    1.40648474e-02,
-    4.67316298e-02,
-    8.39615986e-02,
-    1.19925275e-01,
-    1.48381174e-01,
-    1.64097819e-01,
-    1.64097819e-01,
-    1.48381174e-01,
-    1.19925275e-01,
-    8.39615986e-02,
-    4.67316298e-02,
-    1.40648474e-02,
-    -9.84218694e-03,
-    -2.31425052e-02,
-    -2.64084653e-02,
-    -2.21034939e-02,
-    -1.36671853e-02,
-    -4.51051400e-03,
-    2.79361991e-03,
-    6.93514929e-03,
-    7.85893186e-03,
-    6.41309478e-03,
-    3.83138676e-03,
-    1.24522223e-03,
-    -6.28128960e-04,
-    -1.56471179e-03,
-    -1.71713852e-03,
-    -1.40119781e-03,
-    -8.98615286e-04,
-    -3.55606818e-04
+    -0.0008215855034550382,
+    -0.0007833023901802921,
+     0.001075563790768233,
+     0.001199092367787555,
+    -0.001765309502928316,
+    -0.002055372115328064,
+     0.002986877604154257,
+     0.003462567920638414,
+    -0.004856570111126334,
+    -0.005563143845031497,
+     0.007533613299748122,
+     0.008563932468880897,
+    -0.01126857129039911,
+    -0.01280782411693687,
+     0.01651443896361847,
+     0.01894875110322284,
+    -0.02421604439474981,
+    -0.02845107338464062,
+     0.03672973563400258,
+     0.04542046150312214,
+    -0.06189165826716491,
+    -0.08721876380763803,
+     0.1496157094199961,
+     0.4497962274137046,
+     0.4497962274137046,
+     0.1496157094199961,
+    -0.08721876380763803,
+    -0.0618916582671649,
+     0.04542046150312216,
+     0.03672973563400257,
+    -0.02845107338464062,
+    -0.02421604439474984,
+     0.01894875110322284,
+     0.01651443896361848,
+    -0.01280782411693687,
+    -0.0112685712903991,
+     0.008563932468880899,
+     0.007533613299748123,
+    -0.005563143845031501,
+    -0.004856570111126346,
+     0.003462567920638419,
+     0.002986877604154259,
+    -0.002055372115328063,
+    -0.001765309502928318,
+     0.001199092367787557,
+     0.001075563790768233,
+    -0.0007833023901802925,
+    -0.0008215855034550383
 };
 
index 85653dae487e9ee1e7ad72e3e0fba1d25099ae2e..6977fef330b3d45269e245744530f2904d6a42e9 100644 (file)
@@ -51,8 +51,8 @@ target_link_libraries(scalarlsptest codec2)
 add_executable(tfdmdv tfdmdv.c ../src/fdmdv.c ../src/kiss_fft.c ../src/octave.c)
 target_link_libraries(tfdmdv codec2)
 
-add_executable(t48_8 t48_8.c ../src/fdmdv.c ../src/kiss_fft.c)
-target_link_libraries(t48_8 codec2)
+add_executable(t16_8 t16_8.c ../src/fdmdv.c ../src/kiss_fft.c)
+target_link_libraries(t16_8 codec2)
 
 add_executable(lspsync lspsync.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/kiss_fft.c ../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c ../src/pack.c ${CODEBOOKS})
 target_link_libraries(lspsync codec2)