--- /dev/null
+% 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
+
#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[]);
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;
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[] = {
{ "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
if (ampexp)
aexp = amp_experiment_create();
+ if (bpf_en) {
+ for(i=0; i<BPF_N; i++)
+ bpf_buf[i] = 0.0;
+ }
+
/*----------------------------------------------------------------*\
Main Loop
sum_snr = 0;
while(fread(buf,sizeof(short),N,fin)) {
frames++;
- //printf("frame: %d ", frames);
- /* Read input speech */
+ for(i=0; i<N; i++)
+ buf_float[i] = buf[i];
+
+ /* optionally filter input speech */
+ if (prede) {
+ pre_emp(Sn_pre, buf_float, &pre_mem, N);
+ for(i=0; i<N; i++)
+ buf_float[i] = Sn_pre[i];
+ }
+
+ if (bpf_en) {
+ for(i=0; i<BPF_N; i++)
+ bpf_buf[i] = bpf_buf[N+i];
+ for(i=0; i<N; i++)
+ bpf_buf[BPF_N+i] = buf_float[i];
+ inverse_filter(&bpf_buf[BPF_N], bpf, N, buf_float, BPF_N);
+ }
+
+ /* shift buffer of input samples, and insert new samples */
+
for(i=0; i<M-N; i++) {
Sn[i] = Sn[i+N];
- Sn_pre[i] = Sn_pre[i+N];
}
for(i=0; i<N; i++)
- Sn[i+M-N] = buf[i];
-
- pre_emp(&Sn_pre[M-N], &Sn[M-N], &pre_mem, N);
-
+ Sn[i+M-N] = buf_float[i];
/*------------------------------------------------------------*\
/* find aks here, these are overwritten if LPC modelling is enabled */
- if (prede) {
- for(i=0; i<M; i++)
- Wn[i] = Sn_pre[i]*w[i];
- }
- else {
-
- for(i=0; i<M; i++)
- Wn[i] = Sn[i]*w[i];
- }
+ for(i=0; i<M; i++)
+ Wn[i] = Sn[i]*w[i];
autocorrelate(Wn,Rk,M,order);
levinson_durbin(Rk,ak,order);
if (lpc_model) {
- if (prede)
- e = speech_to_uq_lsps(lsps, ak, Sn_pre, w, order);
- else
- e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
+ e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
#ifdef DUMP
dump_ak(ak, order);
TODO:
- [ ] Code to plot EB/No v BER curves for
+ [ ] Code to plot EB/No v BER curves to char perf for
[ ] AWGN channel
[ ] freq offset
[ ] fading channel
[ ] freq drift
[ ] timing drift
[ ] tune perf/impl loss to get closer to ideal
+ [X] linear interp of phase for better fading perf
[ ] freq offset/drift feedback loop
[ ] smaller freq est block size to min ram req
end */
for(c=0; c<PILOTS_NC; c++) {
-#ifdef OLD
+//#define AVERAGE
+#ifdef AVERAGE
corr.real = 0.0; corr.imag = 0.0; mag = 0.0;
for(p=0; p<NPILOTSFRAME+2; p++) {
corr = cadd(corr, fcmult(coh->pilot2[p][c], ct_symb_buf[sampling_points[p]][c]));
coh->phi_[r][c] = phi_;
coh->amp_[r][c] = amp_;
}
-#endif
+#else
/* set up lin reg model and interpolate phase */
for(r=0; r<NSYMROW; r++) {
coh->amp_[r][c] = amp_;
}
+#endif
}
/* now correct phase of data symbols and make decn on bits */