From 4d31985c774ea21c294f6d6447a960736a94e897 Mon Sep 17 00:00:00 2001 From: hobbes1069 Date: Mon, 16 Jun 2014 19:45:27 +0000 Subject: [PATCH] Update codec2 from codec2-dev to build with fdmdv2 again. Bump codec2 minor version for ABI incompatible change. git-svn-id: https://svn.code.sf.net/p/freetel/code@1657 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/CMakeLists.txt | 2 +- codec2/CMakeLists.txt | 2 +- codec2/src/codec2_fdmdv.h | 2 +- codec2/src/fdmdv.c | 67 +++++++++++++++++++++---------------- codec2/src/fdmdv_internal.h | 2 -- codec2/src/pilot_coeff.h | 60 ++++++++++++++++----------------- codec2/unittest/tfdmdv.c | 59 +++++++++++++++++++------------- 7 files changed, 107 insertions(+), 87 deletions(-) diff --git a/codec2-dev/CMakeLists.txt b/codec2-dev/CMakeLists.txt index 9186f81e..ae10d9c2 100644 --- a/codec2-dev/CMakeLists.txt +++ b/codec2-dev/CMakeLists.txt @@ -29,7 +29,7 @@ project(codec2) # file at some point. # set(CODEC2_VERSION_MAJOR 0) -set(CODEC2_VERSION_MINOR 2) +set(CODEC2_VERSION_MINOR 3) # Set to patch level is needed, otherwise leave FALSE. set(CODEC2_VERSION_PATCH FALSE) set(CODEC2_VERSION "${CODEC2_VERSION_MAJOR}.${CODEC2_VERSION_MINOR}") diff --git a/codec2/CMakeLists.txt b/codec2/CMakeLists.txt index e9ef2262..1e29675b 100644 --- a/codec2/CMakeLists.txt +++ b/codec2/CMakeLists.txt @@ -29,7 +29,7 @@ project(codec2) # file at some point. # set(CODEC2_VERSION_MAJOR 0) -set(CODEC2_VERSION_MINOR 2) +set(CODEC2_VERSION_MINOR 3) # Set to patch level is needed, otherwise leave FALSE. set(CODEC2_VERSION_PATCH FALSE) set(CODEC2_VERSION "${CODEC2_VERSION_MAJOR}.${CODEC2_VERSION_MINOR}") diff --git a/codec2/src/codec2_fdmdv.h b/codec2/src/codec2_fdmdv.h index 543b4d04..5938c642 100644 --- a/codec2/src/codec2_fdmdv.h +++ b/codec2/src/codec2_fdmdv.h @@ -110,7 +110,7 @@ void CODEC2_WIN32SUPPORT fdmdv_get_rx_spectrum(struct FDMDV *fdmdv_sta void CODEC2_WIN32SUPPORT fdmdv_8_to_48(float out48k[], float in8k[], int n); void CODEC2_WIN32SUPPORT fdmdv_48_to_8(float out8k[], float in48k[], int n); -void CODEC2_WIN32SUPPORT fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_rect, COMP *foff_phase_rect, int nin); +void CODEC2_WIN32SUPPORT fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_phase_rect, int nin); /* debug/development function(s) */ diff --git a/codec2/src/fdmdv.c b/codec2/src/fdmdv.c index 880cabb2..757da9b5 100644 --- a/codec2/src/fdmdv.c +++ b/codec2/src/fdmdv.c @@ -106,7 +106,7 @@ static COMP cadd(COMP a, COMP b) static float cabsolute(COMP a) { - return sqrt(pow(a.real, 2.0) + pow(a.imag, 2.0)); + return sqrt(a.real*a.real + a.imag*a.imag); } /*---------------------------------------------------------------------------*\ @@ -211,8 +211,6 @@ struct FDMDV * CODEC2_WIN32SUPPORT fdmdv_create(int Nc) } f->foff = 0.0; - f->foff_rect.real = 1.0; - f->foff_rect.imag = 0.0; f->foff_phase_rect.real = 1.0; f->foff_phase_rect.imag = 0.0; @@ -447,9 +445,10 @@ void tx_filter(COMP tx_baseband[NC+1][M], int Nc, COMP tx_symbols[], COMP tx_fil void fdm_upconvert(COMP tx_fdm[], int Nc, COMP tx_baseband[NC+1][M], COMP phase_tx[], COMP freq[]) { - int i,c; - COMP two = {2.0, 0.0}; - COMP pilot; + int i,c; + COMP two = {2.0, 0.0}; + COMP pilot; + float mag; for(i=0; ipilot_baseband1[j] = cmult(rx_fdm[i], cconj(pilot[i])); + f->pilot_baseband1[j] = cmult(rx_fdm[i], cconj(pilot[i])); f->pilot_baseband2[j] = cmult(rx_fdm[i], cconj(prev_pilot[i])); } @@ -760,21 +762,24 @@ float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin) \*---------------------------------------------------------------------------*/ void CODEC2_WIN32SUPPORT fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, - COMP *foff_rect, COMP *foff_phase_rect, int nin) + COMP *foff_phase_rect, int nin) { + COMP foff_rect; + float mag; int i; - foff_rect->real = cos(2.0*PI*foff/FS); - foff_rect->imag = sin(2.0*PI*foff/FS); + foff_rect.real = cos(2.0*PI*foff/FS); + foff_rect.imag = sin(2.0*PI*foff/FS); for(i=0; ireal /= cabsolute(*foff_phase_rect); - foff_phase_rect->imag /= cabsolute(*foff_phase_rect); + mag = cabsolute(*foff_phase_rect); + foff_phase_rect->real /= mag; + foff_phase_rect->imag /= mag; } /*---------------------------------------------------------------------------*\ @@ -789,7 +794,8 @@ void CODEC2_WIN32SUPPORT fdmdv_freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], fl void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin) { - int i,c; + int i,c; + float mag; /* maximum number of input samples to demod */ @@ -822,8 +828,9 @@ void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP /* normalise digital oscilators as the magnitude can drift over time */ for (c=0; csync == 0) fdmdv->foff = foff_coarse; - fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, -fdmdv->foff, &fdmdv->foff_rect, &fdmdv->foff_phase_rect, *nin); + fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, -fdmdv->foff, &fdmdv->foff_phase_rect, *nin); /* baseband processing */ @@ -1561,7 +1570,7 @@ void CODEC2_WIN32SUPPORT fdmdv_dump_osc_mags(struct FDMDV *f) fprintf(stderr,"\nfreq[]:\n"); for(i=0; i<=f->Nc; i++) fprintf(stderr," %1.3f", cabsolute(f->freq[i])); - fprintf(stderr,"\nfoff_rect %1.3f foff_phase_rect: %1.3f", cabsolute(f->foff_rect), cabsolute(f->foff_phase_rect)); + fprintf(stderr,"\nfoff_phase_rect: %1.3f", cabsolute(f->foff_phase_rect)); fprintf(stderr,"\nphase_rx[]:\n"); for(i=0; i<=f->Nc; i++) fprintf(stderr," %1.3f", cabsolute(f->phase_rx[i])); diff --git a/codec2/src/fdmdv_internal.h b/codec2/src/fdmdv_internal.h index e9b355d4..5957e3d4 100644 --- a/codec2/src/fdmdv_internal.h +++ b/codec2/src/fdmdv_internal.h @@ -114,7 +114,6 @@ struct FDMDV { /* freq offset correction states */ float foff; - COMP foff_rect; COMP foff_phase_rect; /* Demodulator */ @@ -158,7 +157,6 @@ void generate_pilot_fdm(COMP *pilot_fdm, int *bit, float *symbol, float *filter_ void generate_pilot_lut(COMP pilot_lut[], COMP *pilot_freq); float rx_est_freq_offset(struct FDMDV *f, COMP rx_fdm[], int nin); void lpf_peak_pick(float *foff, float *max, COMP pilot_baseband[], COMP pilot_lpf[], kiss_fft_cfg fft_pilot_cfg, COMP S[], int nin); -void freq_shift(COMP rx_fdm_fcorr[], COMP rx_fdm[], float foff, COMP *foff_rect, COMP *foff_phase_rect, int nin); void fdm_downconvert(COMP rx_baseband[NC+1][M+M/P], int Nc, COMP rx_fdm[], COMP phase_rx[], COMP freq[], int nin); void rx_filter(COMP rx_filt[NC+1][P+1], int Nc, COMP rx_baseband[NC+1][M+M/P], COMP rx_filter_memory[NC+1][NFILTER], int nin); float rx_est_timing(COMP rx_symbols[], int Nc, diff --git a/codec2/src/pilot_coeff.h b/codec2/src/pilot_coeff.h index 66e7501d..b284af93 100644 --- a/codec2/src/pilot_coeff.h +++ b/codec2/src/pilot_coeff.h @@ -1,34 +1,34 @@ /* Generated by pilot_coeff_file() Octave function */ const float pilot_coeff[]={ - 0.00204705, - 0.00276339, - 0.00432595, - 0.00697042, - 0.0108452, - 0.0159865, - 0.0223035, - 0.029577, - 0.0374709, - 0.045557, - 0.0533491, - 0.0603458, - 0.0660751, - 0.070138, - 0.0722452, - 0.0722452, - 0.070138, - 0.0660751, - 0.0603458, - 0.0533491, - 0.045557, - 0.0374709, - 0.029577, - 0.0223035, - 0.0159865, - 0.0108452, - 0.00697042, - 0.00432595, - 0.00276339, - 0.00204705 + 0.00223001, + 0.00301037, + 0.00471258, + 0.0075934, + 0.0118145, + 0.0174153, + 0.0242969, + 0.0322204, + 0.0408199, + 0.0496286, + 0.0581172, + 0.0657392, + 0.0719806, + 0.0764066, + 0.0787022, + 0.0787022, + 0.0764066, + 0.0719806, + 0.0657392, + 0.0581172, + 0.0496286, + 0.0408199, + 0.0322204, + 0.0242969, + 0.0174153, + 0.0118145, + 0.0075934, + 0.00471258, + 0.00301037, + 0.00223001 }; diff --git a/codec2/unittest/tfdmdv.c b/codec2/unittest/tfdmdv.c index 707cd19b..256ae556 100644 --- a/codec2/unittest/tfdmdv.c +++ b/codec2/unittest/tfdmdv.c @@ -42,11 +42,13 @@ #define FRAMES 25 #define CHANNEL_BUF_SIZE (10*M) +extern float pilot_coeff[]; + int main(int argc, char *argv[]) { struct FDMDV *fdmdv; int tx_bits[FDMDV_BITS_PER_FRAME]; - COMP tx_symbols[NC+1]; + COMP tx_symbols[FDMDV_NC+1]; COMP tx_baseband[NC+1][M]; COMP tx_fdm[M]; float channel[CHANNEL_BUF_SIZE]; @@ -59,13 +61,13 @@ int main(int argc, char *argv[]) COMP rx_filt[NC+1][P+1]; float rx_timing; float env[NT*P]; - COMP rx_symbols[NC+1]; + COMP rx_symbols[FDMDV_NC+1]; int rx_bits[FDMDV_BITS_PER_FRAME]; float foff_fine; int sync_bit, reliable_sync_bit; int tx_bits_log[FDMDV_BITS_PER_FRAME*FRAMES]; - COMP tx_symbols_log[(NC+1)*FRAMES]; + COMP tx_symbols_log[(FDMDV_NC+1)*FRAMES]; COMP tx_baseband_log[(NC+1)][M*FRAMES]; COMP tx_fdm_log[M*FRAMES]; COMP pilot_baseband1_log[NPILOTBASEBAND*FRAMES]; @@ -82,9 +84,10 @@ int main(int argc, char *argv[]) int rx_filt_log_col_index; float env_log[NT*P*FRAMES]; float rx_timing_log[FRAMES]; - COMP rx_symbols_log[NC+1][FRAMES]; - float sig_est_log[NC+1][FRAMES]; - float noise_est_log[NC+1][FRAMES]; + COMP rx_symbols_log[FDMDV_NC+1][FRAMES]; + COMP phase_difference_log[FDMDV_NC+1][FRAMES]; + float sig_est_log[FDMDV_NC+1][FRAMES]; + float noise_est_log[FDMDV_NC+1][FRAMES]; int rx_bits_log[FDMDV_BITS_PER_FRAME*FRAMES]; float foff_fine_log[FRAMES]; int sync_bit_log[FRAMES]; @@ -104,14 +107,14 @@ int main(int argc, char *argv[]) printf("sizeof FDMDV states: %d bytes\n", sizeof(struct FDMDV)); for(f=0; fprev_tx_symbols, tx_bits, &fdmdv->tx_pilot_bit, 0); - memcpy(fdmdv->prev_tx_symbols, tx_symbols, sizeof(COMP)*(NC+1)); + memcpy(fdmdv->prev_tx_symbols, tx_symbols, sizeof(COMP)*(FDMDV_NC+1)); tx_filter(tx_baseband, FDMDV_NC, tx_symbols, fdmdv->tx_filter_memory); fdm_upconvert(tx_fdm, FDMDV_NC, tx_baseband, fdmdv->phase_tx, fdmdv->freq); @@ -128,6 +131,7 @@ int main(int argc, char *argv[]) if ((f !=2) && (f != 3)) nin = M; */ + nin = M; /* add M tx samples to end of buffer */ assert((channel_count + M) < CHANNEL_BUF_SIZE); @@ -155,9 +159,11 @@ int main(int argc, char *argv[]) /* freq offset estimation and correction */ foff_coarse = rx_est_freq_offset(fdmdv, rx_fdm, nin); + foff_coarse = 0; + fdmdv->sync = 0; if (fdmdv->sync == 0) fdmdv->foff = foff_coarse; - fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, fdmdv->foff, &fdmdv->foff_rect, &fdmdv->foff_phase_rect, nin); + fdmdv_freq_shift(rx_fdm_fcorr, rx_fdm, foff_coarse, &fdmdv->foff_phase_rect, nin); /* baseband processing */ @@ -165,8 +171,13 @@ int main(int argc, char *argv[]) rx_filter(rx_filt, FDMDV_NC, rx_baseband, fdmdv->rx_filter_memory, nin); rx_timing = rx_est_timing(rx_symbols, FDMDV_NC, rx_filt, rx_baseband, fdmdv->rx_filter_mem_timing, env, fdmdv->rx_baseband_mem_timing, nin); foff_fine = qpsk_to_bits(rx_bits, &sync_bit, FDMDV_NC, fdmdv->phase_difference, fdmdv->prev_rx_symbols, rx_symbols, 0); + //for(i=0; iprev_rx_symbols[i].real, fdmdv->prev_rx_symbols[i].imag, fdmdv->phase_difference[i].real, fdmdv->phase_difference[i].imag); + //if (f==1) + // exit(0); snr_update(fdmdv->sig_est, fdmdv->noise_est, FDMDV_NC, fdmdv->phase_difference); - memcpy(fdmdv->prev_rx_symbols, rx_symbols, sizeof(COMP)*(NC+1)); + memcpy(fdmdv->prev_rx_symbols, rx_symbols, sizeof(COMP)*(FDMDV_NC+1)); next_nin = M; @@ -184,14 +195,12 @@ int main(int argc, char *argv[]) \*---------------------------------------------------------*/ 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; cpilot_baseband1, sizeof(COMP)*NPILOTBASEBAND); memcpy(&pilot_baseband2_log[f*NPILOTBASEBAND], fdmdv->pilot_baseband2, sizeof(COMP)*NPILOTBASEBAND); memcpy(&pilot_lpf1_log[f*NPILOTLPF], fdmdv->pilot_lpf1, sizeof(COMP)*NPILOTLPF); @@ -222,13 +231,15 @@ int main(int argc, char *argv[]) memcpy(&env_log[NT*P*f], env, sizeof(float)*NT*P); rx_timing_log[f] = rx_timing; nin_log[f] = nin; - for(c=0; cphase_difference[c]; + } /* qpsk_to_bits() */ memcpy(&rx_bits_log[FDMDV_BITS_PER_FRAME*f], rx_bits, sizeof(int)*FDMDV_BITS_PER_FRAME); - for(c=0; csig_est[c]; noise_est_log[c][f] = fdmdv->noise_est[c]; } @@ -248,25 +259,27 @@ int main(int argc, char *argv[]) assert(fout != NULL); fprintf(fout, "# Created by tfdmdv.c\n"); 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, (NC+1)*FRAMES); - octave_save_complex(fout, "tx_baseband_log_c", (COMP*)tx_baseband_log, (NC+1), M*FRAMES, M*FRAMES); + octave_save_complex(fout, "tx_symbols_log_c", tx_symbols_log, 1, (FDMDV_NC+1)*FRAMES, (FDMDV_NC+1)*FRAMES); + octave_save_complex(fout, "tx_baseband_log_c", (COMP*)tx_baseband_log, (FDMDV_NC+1), M*FRAMES, M*FRAMES); octave_save_complex(fout, "tx_fdm_log_c", (COMP*)tx_fdm_log, 1, M*FRAMES, M*FRAMES); octave_save_complex(fout, "pilot_lut_c", (COMP*)fdmdv->pilot_lut, 1, NPILOT_LUT, NPILOT_LUT); octave_save_complex(fout, "pilot_baseband1_log_c", pilot_baseband1_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); octave_save_complex(fout, "pilot_baseband2_log_c", pilot_baseband2_log, 1, NPILOTBASEBAND*FRAMES, NPILOTBASEBAND*FRAMES); + octave_save_float(fout, "pilot_coeff_c", pilot_coeff, 1, NPILOTCOEFF, NPILOTCOEFF); octave_save_complex(fout, "pilot_lpf1_log_c", pilot_lpf1_log, 1, NPILOTLPF*FRAMES, NPILOTLPF*FRAMES); octave_save_complex(fout, "pilot_lpf2_log_c", pilot_lpf2_log, 1, NPILOTLPF*FRAMES, NPILOTLPF*FRAMES); octave_save_complex(fout, "S1_log_c", S1_log, 1, MPILOTFFT*FRAMES, MPILOTFFT*FRAMES); octave_save_complex(fout, "S2_log_c", S2_log, 1, MPILOTFFT*FRAMES, MPILOTFFT*FRAMES); octave_save_float(fout, "foff_log_c", foff_log, 1, FRAMES, FRAMES); octave_save_float(fout, "foff_coarse_log_c", foff_coarse_log, 1, FRAMES, FRAMES); - octave_save_complex(fout, "rx_baseband_log_c", (COMP*)rx_baseband_log, (NC+1), rx_baseband_log_col_index, (M+M/P)*FRAMES); - octave_save_complex(fout, "rx_filt_log_c", (COMP*)rx_filt_log, (NC+1), rx_filt_log_col_index, (P+1)*FRAMES); + octave_save_complex(fout, "rx_baseband_log_c", (COMP*)rx_baseband_log, (FDMDV_NC+1), rx_baseband_log_col_index, (M+M/P)*FRAMES); + octave_save_complex(fout, "rx_filt_log_c", (COMP*)rx_filt_log, (FDMDV_NC+1), rx_filt_log_col_index, (P+1)*FRAMES); octave_save_float(fout, "env_log_c", env_log, 1, NT*P*FRAMES, NT*P*FRAMES); octave_save_float(fout, "rx_timing_log_c", rx_timing_log, 1, FRAMES, FRAMES); - octave_save_complex(fout, "rx_symbols_log_c", (COMP*)rx_symbols_log, (NC+1), FRAMES, FRAMES); - octave_save_float(fout, "sig_est_log_c", (float*)sig_est_log, (NC+1), FRAMES, FRAMES); - octave_save_float(fout, "noise_est_log_c", (float*)noise_est_log, (NC+1), FRAMES, FRAMES); + octave_save_complex(fout, "rx_symbols_log_c", (COMP*)rx_symbols_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_complex(fout, "phase_difference_log_c", (COMP*)phase_difference_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_float(fout, "sig_est_log_c", (float*)sig_est_log, (FDMDV_NC+1), FRAMES, FRAMES); + octave_save_float(fout, "noise_est_log_c", (float*)noise_est_log, (FDMDV_NC+1), FRAMES, FRAMES); octave_save_int(fout, "rx_bits_log_c", rx_bits_log, 1, FDMDV_BITS_PER_FRAME*FRAMES); octave_save_float(fout, "foff_fine_log_c", foff_fine_log, 1, FRAMES, FRAMES); octave_save_int(fout, "sync_bit_log_c", sync_bit_log, 1, FRAMES); -- 2.25.1