/* emnr.h This file is part of a program that implements a Software-Defined Radio. Copyright (C) 2015 Warren Pratt, NR0V Copyright (C) 2024 Edouard Griffiths, F4EXB Adapted to SDRangel This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. The author can be reached by email at warren@wpratt.com */ #ifndef wdsp_emnr_h #define wdsp_emnr_h #include #include #include "fftw3.h" #include "export.h" namespace WDSP { class RXA; class WDSP_API EMNR { public: int run; int position; int bsize; float* in; float* out; int fsize; int ovrlp; int incr; std::vector window; int iasize; std::vector inaccum; std::vector forfftin; std::vector forfftout; int msize; std::vector mask; std::vector revfftin; std::vector revfftout; std::vector> save; int oasize; std::vector outaccum; double rate; int wintype; double ogain; double gain; int nsamps; int iainidx; int iaoutidx; int init_oainidx; int oainidx; int oaoutidx; int saveidx; fftwf_plan Rfor; fftwf_plan Rrev; struct G { int incr; double rate; int msize; std::vector& mask; const std::vector& y; int gain_method; int npe_method; int ae_run; std::vector lambda_y; std::vector lambda_d; std::vector prev_mask; std::vector prev_gamma; double gf1p5; double alpha; double eps_floor; double gamma_max; double q; double gmax; // std::array GG; std::array GGS; FILE* fileb; G( int incr, double rate, int msize, std::vector& mask, const std::vector& y ); G(const G&) = delete; G& operator=(const G& other) = delete; ~G() = default; void calc_gamma0(); void calc_gamma1(); void calc_gamma2(); void calc_lambda_y(); private: static double getKey(const std::array& type, double gamma, double xi); static double e1xb (double x); static double bessI0 (double x); static double bessI1 (double x); } *g; struct NP { int incr; double rate; int msize; std::vector& lambda_y; std::vector& lambda_d; double alphaCsmooth; double alphaMax; double alphaCmin; double alphaMin_max_value; double snrq; double betamax; double invQeqMax; double av; double Dtime; int U; int V; int D; std::vector p; std::vector alphaOptHat; double alphaC; std::vector alphaHat; std::vector sigma2N; std::vector pbar; std::vector p2bar; std::vector Qeq; double MofD; double MofV; std::array invQbar_points; std::array nsmax; std::vector bmin; std::vector bmin_sub; std::vector k_mod; std::vector actmin; std::vector actmin_sub; int subwc; std::vector lmin_flag; std::vector pmin_u; std::vector> actminbuff; int amb_idx; NP( int incr, double rate, int msize, std::vector& lambda_y, std::vector& lambda_d ); NP(const NP&) = delete; NP& operator=(const NP& other) = delete; ~NP() = default; void LambdaD(); private: static const std::array DVals; static const std::array MVals; static void interpM ( double* res, double x, int nvals, const std::array& xvals, const std::array& yvals ); } *np; struct NPS { int incr; double rate; int msize; const std::vector& lambda_y; std::vector& lambda_d; double alpha_pow; double alpha_Pbar; double epsH1; double epsH1r; std::vector sigma2N; std::vector PH1y; std::vector Pbar; std::vector EN2y; NPS( int incr, double rate, int msize, const std::vector& lambda_y, std::vector& lambda_d, double alpha_pow, double alpha_Pbar, double epsH1 ); NPS(const NPS&) = delete; NPS& operator=(const NPS& other) = delete; ~NPS() = default; void LambdaDs(); } *nps; struct AE { int msize; const std::vector& lambda_y; double zetaThresh; double psi; std::vector nmask; AE( int msize, const std::vector& lambda_y, double zetaThresh, double psi ); AE(const AE&) = delete; AE& operator=(const AE& other) = delete; ~AE() = default; } *ae; EMNR( int run, int position, int size, float* in, float* out, int fsize, int ovrlp, int rate, int wintype, double gain, int gain_method, int npe_method, int ae_run ); EMNR(const EMNR&) = delete; EMNR& operator=(const EMNR& other) = delete; ~EMNR(); void flush(); void execute(int pos); void setBuffers(float* in, float* out); void setSamplerate(int rate); void setSize(int size); // Public Properties void setGainMethod(int method); void setNpeMethod(int method); void setAeRun(int run); void setAeZetaThresh(double zetathresh); void setAePsi(double psi); private: void calc_window(); void calc(); void decalc(); void aepf(); void calc_gain(); }; } // namespace WDSP #endif