From ba61340e4723abbd470deadb668bf6016a0e506b Mon Sep 17 00:00:00 2001 From: drowe67 Date: Sun, 12 Apr 2015 01:49:41 +0000 Subject: [PATCH] added BPF option to c2sim git-svn-id: https://svn.code.sf.net/p/freetel/code@2114 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2-dev/octave/bpf.m | 31 ++++++++++++ codec2-dev/src/bpf.h | 105 ++++++++++++++++++++++++++++++++++++++++ codec2-dev/src/c2sim.c | 56 +++++++++++++-------- codec2-dev/src/cohpsk.c | 9 ++-- 4 files changed, 177 insertions(+), 24 deletions(-) create mode 100644 codec2-dev/octave/bpf.m create mode 100644 codec2-dev/src/bpf.h diff --git a/codec2-dev/octave/bpf.m b/codec2-dev/octave/bpf.m new file mode 100644 index 00000000..5649a5c6 --- /dev/null +++ b/codec2-dev/octave/bpf.m @@ -0,0 +1,31 @@ +% bpf.m +% David Rowe April 2015 +% +% Design 400-2600 Hz BPF and save coeffs + +1; + +function write_c_array(filename, arrayname, vec) + + m = length(vec); + + f=fopen(filename,"wt"); + fprintf(f,"#define %s_N %d\n\n", toupper(arrayname), m); + fprintf(f,"float %s[]={\n", arrayname); + for r=1:m + if r < m + fprintf(f, " %f,\n", vec(r)); + else + fprintf(f, " %f\n};", vec(r)); + end + end + + fclose(f); +endfunction + +b=firls(100,[0 400 500 2400 2600 4000]/4000,[0.01 0.01 1 1 0.01 0.01]); +freqz(b) +write_c_array("../src/bpf.h", "bpf", b) + +% C header file of noise samples so C version gives extacly the same results + diff --git a/codec2-dev/src/bpf.h b/codec2-dev/src/bpf.h new file mode 100644 index 00000000..9cc916f5 --- /dev/null +++ b/codec2-dev/src/bpf.h @@ -0,0 +1,105 @@ +#define BPF_N 101 + +float bpf[]={ + 0.002174, + 0.003245, + 0.002147, + 0.001866, + 0.002764, + 0.000567, + -0.001641, + -0.000565, + -0.002415, + -0.005837, + -0.003620, + -0.002828, + -0.006268, + -0.002787, + 0.001963, + -0.001234, + 0.001446, + 0.009200, + 0.005331, + 0.003521, + 0.011821, + 0.006951, + -0.002015, + 0.005137, + 0.001828, + -0.013390, + -0.007058, + -0.003273, + -0.020458, + -0.014321, + 0.001751, + -0.012891, + -0.009730, + 0.018993, + 0.008544, + 0.000534, + 0.035755, + 0.029074, + -0.001192, + 0.030852, + 0.030983, + -0.029834, + -0.009550, + 0.011945, + -0.081971, + -0.082875, + 0.000423, + -0.133526, + -0.211778, + 0.182628, + 0.514906, + 0.182628, + -0.211778, + -0.133526, + 0.000423, + -0.082875, + -0.081971, + 0.011945, + -0.009550, + -0.029834, + 0.030983, + 0.030852, + -0.001192, + 0.029074, + 0.035755, + 0.000534, + 0.008544, + 0.018993, + -0.009730, + -0.012891, + 0.001751, + -0.014321, + -0.020458, + -0.003273, + -0.007058, + -0.013390, + 0.001828, + 0.005137, + -0.002015, + 0.006951, + 0.011821, + 0.003521, + 0.005331, + 0.009200, + 0.001446, + -0.001234, + 0.001963, + -0.002787, + -0.006268, + -0.002828, + -0.003620, + -0.005837, + -0.002415, + -0.000565, + -0.001641, + 0.000567, + 0.002764, + 0.001866, + 0.002147, + 0.003245, + 0.002174 +}; \ No newline at end of file diff --git a/codec2-dev/src/c2sim.c b/codec2-dev/src/c2sim.c index 1e294a7b..c80f9646 100644 --- a/codec2-dev/src/c2sim.c +++ b/codec2-dev/src/c2sim.c @@ -48,6 +48,7 @@ #include "interp.h" #include "ampexp.h" #include "phaseexp.h" +#include "bpf.h" void synth_one_frame(kiss_fft_cfg fft_inv_cfg, short buf[], MODEL *model, float Sn_[], float Pn[], int prede, float *de_mem, float gain); void print_help(const struct option *long_options, int num_opts, char* argv[]); @@ -64,8 +65,9 @@ int main(int argc, char *argv[]) FILE *fout = NULL; /* output speech file */ FILE *fin; /* input speech file */ short buf[N]; /* input/output buffer */ + float buf_float[N]; float Sn[M]; /* float input speech samples */ - float Sn_pre[M]; /* pre-emphasised input speech samples */ + float Sn_pre[N]; /* pre-emphasised input speech samples */ COMP Sw[FFT_ENC]; /* DFT of Sn[] */ kiss_fft_cfg fft_fwd_cfg; kiss_fft_cfg fft_inv_cfg; @@ -130,6 +132,8 @@ int main(int argc, char *argv[]) struct PEXP *pexp = NULL; struct AEXP *aexp = NULL; float gain = 1.0; + int bpf_en = 0; + float bpf_buf[BPF_N+N]; char* opt_string = "ho:"; struct option long_options[] = { @@ -164,6 +168,7 @@ int main(int argc, char *argv[]) { "vq_pitch_e", no_argument, &vector_quant_Wo_e, 1 }, { "rate", required_argument, NULL, 0 }, { "gain", required_argument, NULL, 0 }, + { "bpf", no_argument, &bpf_en, 1 }, #ifdef DUMP { "dump", required_argument, &dump, 1 }, #endif @@ -356,6 +361,11 @@ int main(int argc, char *argv[]) if (ampexp) aexp = amp_experiment_create(); + if (bpf_en) { + for(i=0; ipilot2[p][c], ct_symb_buf[sampling_points[p]][c])); @@ -266,7 +268,7 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, int rx_bits[], COMP ct_symb_buf[][ coh->phi_[r][c] = phi_; coh->amp_[r][c] = amp_; } -#endif +#else /* set up lin reg model and interpolate phase */ @@ -291,6 +293,7 @@ void qpsk_symbols_to_bits(struct COHPSK *coh, int rx_bits[], COMP ct_symb_buf[][ for(r=0; ramp_[r][c] = amp_; } +#endif } /* now correct phase of data symbols and make decn on bits */ -- 2.25.1