RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
msdcost.cpp
Go to the documentation of this file.
1 //
2 // file = msdcost.cpp
3 //
4 // computes cost (in terms of arithmetic operations)
5 // of multistage decimator implementations
6 //
7 
8 #include <fstream>
9 #include <iostream>
10 #include <math.h>
11 #include <stdlib.h>
12 
13 #include "filtmath.h"
14 #include "msdcost.h"
15 
16 void
17 MultistageDecimCost(int num_stages, int* stage_decim_rate,
18  double orig_samp_rate, double passband_edge_freq,
19  double passband_ripple, double stopband_ripple,
20  int num_taps_must_be_odd)
21 {
22  double delta_p, d_sub_inf;
23  int decim_factor, stage;
24  double samp_rate, stage_output_rate;
25  double trans_width, stopband_edge_freq;
26  double total_mult_rate;
27 
28  int* num_taps = new int[num_stages];
29  double* mult_rate = new double[num_stages];
30 
31  delta_p = passband_ripple / num_stages;
32  d_sub_inf = DSubInf(delta_p, stopband_ripple);
33  std::cout << "D_inf is " << d_sub_inf << std::endl;
34 
35  decim_factor = 1;
36  for (stage = 0; stage < num_stages; stage++)
37  decim_factor *= stage_decim_rate[stage];
38 
39  stopband_edge_freq = orig_samp_rate / decim_factor / 2.0;
40 
41  samp_rate = orig_samp_rate;
42  total_mult_rate = 0.0;
43  double f_dp_ds;
44  int new_num_taps;
45  for (stage = 0; stage < num_stages; stage++) {
46  stage_output_rate = samp_rate / stage_decim_rate[stage];
47  trans_width = stage_output_rate - stopband_edge_freq - passband_edge_freq;
48  std::cout << "trans_width = " << trans_width << std::endl;
49 
50  // new stuff for better estimate
51  f_dp_ds = 11.01217 + 0.51244 * log10(delta_p / stopband_ripple);
52  new_num_taps = (int)ceil((d_sub_inf * samp_rate / trans_width) -
53  (f_dp_ds * trans_width / samp_rate) + 1);
54  f_dp_ds = (f_dp_ds * trans_width / samp_rate) + 1.0;
55  // end of new stuff
56 
57  num_taps[stage] = (int)ceil(d_sub_inf * samp_rate / trans_width);
58  if ((num_taps[stage] % 2 != 1) && num_taps_must_be_odd)
59  num_taps[stage]++;
60 
61  mult_rate[stage] = num_taps[stage] * stage_output_rate / 2.0;
62  total_mult_rate += mult_rate[stage];
63 
64  std::cout << "num taps for stage " << stage << " = " << num_taps[stage]
65  << std::endl;
66  std::cout << "new way num taps is " << new_num_taps << std::endl;
67  std::cout << "f(dp, ds) term is " << f_dp_ds << std::endl;
68  std::cout << "mult rate = " << mult_rate[stage] << std::endl;
69  samp_rate = stage_output_rate;
70  }
71  std::cout << "total mult rate = " << total_mult_rate << std::endl;
72  delete[] num_taps;
73  delete[] mult_rate;
74  return;
75 }
double DSubInf(double delta_p, double delta_s)
Definition: filtmath.cpp:15
void MultistageDecimCost(int num_stages, int *stage_decim_rate, double orig_samp_rate, double passband_edge_freq, double passband_ripple, double stopband_ripple, int num_taps_must_be_odd)
Definition: msdcost.cpp:17