From: baobrien Date: Fri, 11 Sep 2015 03:24:21 +0000 (+0000) Subject: complex domain FM modulator written and tested X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=9eaee485b3ed5bb4a8aeb58e7b92f2ac039c99bd;p=freetel-svn-tracking.git complex domain FM modulator written and tested git-svn-id: https://svn.code.sf.net/p/freetel/code@2304 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/octave/fm.m b/codec2-dev/octave/fm.m index 99c68025..50c4099f 100644 --- a/codec2-dev/octave/fm.m +++ b/codec2-dev/octave/fm.m @@ -438,7 +438,10 @@ function test_fm_modulator system("../fm_test fm_test_sig.raw fm_test_out.raw"); ftmod = fopen("fm_test_out.raw","r"); - test_mod = fread(ftmod,"short")/16384; + test_mod_p = rot90(fread(ftmod,"short"))/16384; + test_mod_r = test_mod_p(1:2:length(test_mod_p)); + test_mod_i = test_mod_p(2:2:length(test_mod_p)); + test_mod = test_mod_r .+ i*test_mod_i; fclose(ftmod); comp_mod = analog_fm_mod(fm_states,test_sig); @@ -448,8 +451,8 @@ function test_fm_modulator size(comp_mod_real) size(test_mod) mod_diff = zeros(1,length(test_mod)); - mod_diff = rot90(test_mod) .- comp_mod_real; - plot(mod_diff); + mod_diff = test_mod .- comp_mod; + plot(real(mod_diff),test_t,imag(mod_diff),test_t); endfunction diff --git a/codec2-dev/src/codec2_fm.h b/codec2-dev/src/codec2_fm.h index 630ac23f..8b79ae4a 100644 --- a/codec2-dev/src/codec2_fm.h +++ b/codec2-dev/src/codec2_fm.h @@ -47,6 +47,7 @@ struct FM *fm_create(int nsam); void fm_destroy(struct FM *fm_states); void fm_demod(struct FM *fm, float rx_out[], float rx[]); void fm_mod(struct FM *fm, float tx_in[], float tx_out[]); +void fm_mod_comp(struct FM *fm_states, float tx_in[], COMP tx_out[]); #endif diff --git a/codec2-dev/src/fm.c b/codec2-dev/src/fm.c index d63e0999..37e7a97a 100644 --- a/codec2-dev/src/fm.c +++ b/codec2-dev/src/fm.c @@ -240,18 +240,48 @@ void fm_mod(struct FM *fm_states, float tx_in[], float tx_out[]){ fm_states->tx_phase = tx_phase; } +/*---------------------------------------------------------------------------*\ + + FUNCTION....: fm_mod + AUTHOR......: Brady O'Brien + DATE CREATED: Sept. 10 2015 + Modulate an FM signal from a baseband modulating signal + struct FM *fm - FM state structure. Can be reused from fm_demod. + float tx_in[] - nsam baseband samples to be modulated + float tx_out[] - nsam samples in which to place the modulated FM +\*---------------------------------------------------------------------------*/ +void fm_mod_comp(struct FM *fm_states, float tx_in[], COMP tx_out[]){ + float Fs = fm_states->Fs; //Sampling freq + float fc = fm_states->fc; //Center freq + float wc = 2*M_PI*fc/Fs; //Center freq in rads/samp + float fd = fm_states->fd; //Max deviation in cycles/samp + float wd = 2*M_PI*fd/Fs; //Max deviation in rads/samp + int nsam = fm_states->nsam; //Samples per batch of modulation + float tx_phase = fm_states->tx_phase; //Transmit phase in rads + float w; //Temp variable for phase of VFO during loop + int i; + + //Go through the samples, spin the oscillator, and generate some FM + for(i=0; i 2*M_PI) + tx_phase -= 2*M_PI; - - - - - - - + tx_out[i].real = cosf(tx_phase); + tx_out[i].imag = sinf(tx_phase); + } + //Save phase back into state struct + fm_states->tx_phase = tx_phase; +} diff --git a/codec2-dev/src/fm_demod.c b/codec2-dev/src/fm_demod.c index fd4301bd..58a322a0 100644 --- a/codec2-dev/src/fm_demod.c +++ b/codec2-dev/src/fm_demod.c @@ -38,15 +38,16 @@ #define N 160 -#define TEST_MOD +#define TEST_MOD_COMP int main(int argc, char *argv[]) { FILE *fin, *fout; struct FM *fm; - short buf[N]; + short buf[N*2]; float rx[N]; float rx_out[N]; + COMP out_comp[N]; int i; if (argc < 2) { @@ -81,13 +82,27 @@ int main(int argc, char *argv[]) } #ifdef TEST_MOD fm_mod(fm, rx, rx_out); +#else +#ifdef TEST_MOD_COMP + fm_mod_comp(fm, rx, out_comp); #else fm_demod(fm, rx_out, rx); #endif +#endif + + +#ifdef TEST_MOD_COMP + for(i=0; i