From 5342ba7f03773aa35af6f5f1faa75b55c5a5a3ec Mon Sep 17 00:00:00 2001 From: okcsampson Date: Wed, 12 Jul 2017 03:29:01 +0000 Subject: [PATCH] Fix bugs in tofdm.c add shift back to .m git-svn-id: https://svn.code.sf.net/p/freetel/code@3296 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/tofdm.m | 1 + codec2-dev/unittest/tofdm.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/codec2-dev/octave/tofdm.m b/codec2-dev/octave/tofdm.m index d5ca59e6..6a650c64 100644 --- a/codec2-dev/octave/tofdm.m +++ b/codec2-dev/octave/tofdm.m @@ -34,6 +34,7 @@ end % Channel simulation ---------------------------------------------- rx_log = sample_clock_offset(tx_log, sample_clock_offset_ppm); +rx_log = freq_shift(rx_log, .01, Fs); % Rx --------------------------------------------------------------- diff --git a/codec2-dev/unittest/tofdm.c b/codec2-dev/unittest/tofdm.c index b339998e..496552a0 100644 --- a/codec2-dev/unittest/tofdm.c +++ b/codec2-dev/unittest/tofdm.c @@ -51,26 +51,28 @@ DATE CREATED: May 2015 Simulates small Fs offset between mod and demod. + (Note: Won't work with float, works OK with double) \*---------------------------------------------------------------------------*/ static int fs_offset(COMP out[], COMP in[], int n, float sample_rate_ppm) { - float f; - int t1, t2; + double f; + int t1, t2; - float tin = 0.0f; + double tin = 0.0; int tout = 0; - while (tin < n) { - t1 = floorf(tin); - t2 = ceilf(tin); - f = tin - t1; + while (tin < (double) n) { + t1 = (int) floor(tin); + t2 = (int) ceil(tin); - out[tout].real = (1.0f - f) * in[t1].real + f * in[t2].real; - out[tout].imag = (1.0f - f) * in[t1].imag + f * in[t2].imag; + f = (tin - (double) t1); + + out[tout].real = (1.0 - f) * in[t1].real + f * in[t2].real; + out[tout].imag = (1.0 - f) * in[t1].imag + f * in[t2].imag; tout += 1; - tin += 1.0f + sample_rate_ppm / 1E6f; + tin += 1.0 + sample_rate_ppm / 1E6; } return tout; @@ -174,7 +176,6 @@ int main(int argc, char *argv[]) freq_shift(rx_log, rx_log, foff, &foff_phase_rect, samples_per_frame * NFRAMES); - /* --------------------------------------------------------*\ Demod \*---------------------------------------------------------*/ -- 2.25.1