Beispiel #1
0
//! \brief calculates the coefficients for lowpass FIR based on Remez
// constraints
void create_remez_lpfir(fir_coeff<float_type>& remezfir, float_type pass_edge, float_type stop_edge,
                        float_type stop_weight) {
  bool ok = true;
  std::vector<float_type> e1(4);
  std::vector<float_type> f1(4);
  std::vector<float_type> w1(4);
  long nfilt = remezfir.num_taps;
  remez_fir Remz;
  w1[0] = 1.0;
  w1[1] = stop_weight;
  e1[0] = 0;
  e1[1] = pass_edge / 2.0;
  e1[2] = stop_edge / 2.0;
  e1[3] = 0.5;
  f1[0] = 1.0;
  f1[1] = 0.0;
  std::vector<float_type> fir_coef(nfilt);
  ok = Remz.remez(fir_coef, nfilt, 2, e1, f1, w1, 1);
  if (ok) {
    for (int i = 0; i < nfilt; i++) remezfir.settap(i, fir_coef[i]);
  } else {
    for (int i = 0; i < nfilt; i++) remezfir.settap(i, 0);
    remezfir.settap(0, 1);
  }
}
void create_remez_fir(fir_coeff<float_type>& remezfir, int jtype, int nbands, std::vector<float_type>& edge,
                      std::vector<float_type>& fx, std::vector<float_type>& wtx) {
  bool ok;
  long nfilt = remezfir.number_of_taps();
  remez_fir Remz;
  std::vector<float_type> fir_coef(nfilt);
  ok = Remz.remez(fir_coef, nfilt, nbands, edge, fx, wtx, jtype);
  if (!ok) {
    for (int i = 0; i < nfilt; i++) remezfir.settap(i, 0);
    remezfir.settap(0, 1);
  } else {
    for (int i = 0; i < nfilt; i++) remezfir.settap(i, fir_coef[i]);
  }
}