1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2025-07-06 02:45:26 -04:00

WDSP: NBP (notched bandpass) use double prceision as much as possible

This commit is contained in:
f4exb 2024-07-17 00:40:00 +02:00
parent 7f1cb0e203
commit 5d68bf73b3
2 changed files with 69 additions and 69 deletions

View File

@ -46,10 +46,10 @@ namespace WDSP {
a->master_run = master_run; a->master_run = master_run;
a->maxnotches = maxnotches; a->maxnotches = maxnotches;
a->nn = 0; a->nn = 0;
a->fcenter = new float[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float)); a->fcenter = new double[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float));
a->fwidth = new float[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float)); a->fwidth = new double[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float));
a->nlow = new float[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float)); a->nlow = new double[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float));
a->nhigh = new float[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float)); a->nhigh = new double[a->maxnotches]; // (float *) malloc0 (a->maxnotches * sizeof (float));
a->active = new int[a->maxnotches]; // (int *) malloc0 (a->maxnotches * sizeof (int )); a->active = new int[a->maxnotches]; // (int *) malloc0 (a->maxnotches * sizeof (int ));
return a; return a;
} }
@ -69,7 +69,7 @@ void NOTCHDB::destroy_notchdb (NOTCHDB *b)
* * * *
********************************************************************************************************/ ********************************************************************************************************/
float* NBP::fir_mbandpass (int N, int nbp, float* flow, float* fhigh, float rate, float scale, int wintype) float* NBP::fir_mbandpass (int N, int nbp, double* flow, double* fhigh, double rate, double scale, int wintype)
{ {
int i, k; int i, k;
float* impulse = new float[N * 2]; // (float *) malloc0 (N * sizeof (complex)); float* impulse = new float[N * 2]; // (float *) malloc0 (N * sizeof (complex));
@ -87,9 +87,9 @@ float* NBP::fir_mbandpass (int N, int nbp, float* flow, float* fhigh, float rate
return impulse; return impulse;
} }
float NBP::min_notch_width (NBP *a) double NBP::min_notch_width (NBP *a)
{ {
float min_width; double min_width;
switch (a->wintype) switch (a->wintype)
{ {
case 0: case 0:
@ -105,23 +105,23 @@ float NBP::min_notch_width (NBP *a)
int NBP::make_nbp ( int NBP::make_nbp (
int nn, int nn,
int* active, int* active,
float* center, double* center,
float* width, double* width,
float* nlow, double* nlow,
float* nhigh, double* nhigh,
float minwidth, double minwidth,
int autoincr, int autoincr,
float flow, double flow,
float fhigh, double fhigh,
float* bplow, double* bplow,
float* bphigh, double* bphigh,
int* havnotch int* havnotch
) )
{ {
int nbp; int nbp;
int nnbp, adds; int nnbp, adds;
int i, j, k; int i, j, k;
float nl, nh; double nl, nh;
int* del = new int[1024]; // (int *) malloc0 (1024 * sizeof (int)); int* del = new int[1024]; // (int *) malloc0 (1024 * sizeof (int));
if (fhigh > flow) if (fhigh > flow)
{ {
@ -202,8 +202,8 @@ int NBP::make_nbp (
void NBP::calc_nbp_lightweight (NBP *a) void NBP::calc_nbp_lightweight (NBP *a)
{ // calculate and set new impulse response; used when changing tune freq or shift freq { // calculate and set new impulse response; used when changing tune freq or shift freq
int i; int i;
float fl, fh; double fl, fh;
float offset; double offset;
NOTCHDB *b = a->ptraddr; NOTCHDB *b = a->ptraddr;
if (a->fnfrun) if (a->fnfrun)
{ {
@ -249,7 +249,7 @@ void NBP::calc_nbp_impulse (NBP *a)
{ // calculates impulse response; for create_fircore() and parameter changes { // calculates impulse response; for create_fircore() and parameter changes
int i; int i;
float fl, fh; float fl, fh;
float offset; double offset;
NOTCHDB *b = a->ptraddr; NOTCHDB *b = a->ptraddr;
if (a->fnfrun) if (a->fnfrun)
{ {
@ -309,11 +309,11 @@ NBP* NBP::create_nbp(
int mp, int mp,
float* in, float* in,
float* out, float* out,
float flow, double flow,
float fhigh, double fhigh,
int rate, int rate,
int wintype, int wintype,
float gain, double gain,
int autoincr, int autoincr,
int maxpb, int maxpb,
NOTCHDB* ptraddr NOTCHDB* ptraddr
@ -326,7 +326,7 @@ NBP* NBP::create_nbp(
a->size = size; a->size = size;
a->nc = nc; a->nc = nc;
a->mp = mp; a->mp = mp;
a->rate = (float)rate; a->rate = (double) rate;
a->wintype = wintype; a->wintype = wintype;
a->gain = gain; a->gain = gain;
a->in = in; a->in = in;
@ -336,8 +336,8 @@ NBP* NBP::create_nbp(
a->fhigh = fhigh; a->fhigh = fhigh;
a->maxpb = maxpb; a->maxpb = maxpb;
a->ptraddr = ptraddr; a->ptraddr = ptraddr;
a->bplow = new float[a->maxpb]; // (float *) malloc0 (a->maxpb * sizeof (float)); a->bplow = new double[a->maxpb]; // (float *) malloc0 (a->maxpb * sizeof (float));
a->bphigh = new float[a->maxpb]; // (float *) malloc0 (a->maxpb * sizeof (float)); a->bphigh = new double[a->maxpb]; // (float *) malloc0 (a->maxpb * sizeof (float));
calc_nbp_impulse (a); calc_nbp_impulse (a);
a->p = FIRCORE::create_fircore (a->size, a->in, a->out, a->nc, a->mp, a->impulse); a->p = FIRCORE::create_fircore (a->size, a->in, a->out, a->nc, a->mp, a->impulse);
// print_impulse ("nbp.txt", a->size + 1, impulse, 1, 0); // print_impulse ("nbp.txt", a->size + 1, impulse, 1, 0);
@ -433,7 +433,7 @@ void NBP::UpdateNBPFilters(RXA& rxa)
} }
} }
int NBP::NBPAddNotch (RXA& rxa, int notch, float fcenter, float fwidth, int active) int NBP::NBPAddNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active)
{ {
NOTCHDB *b; NOTCHDB *b;
int i, j; int i, j;
@ -463,7 +463,7 @@ int NBP::NBPAddNotch (RXA& rxa, int notch, float fcenter, float fwidth, int acti
return rval; return rval;
} }
int NBP::NBPGetNotch (RXA& rxa, int notch, float* fcenter, float* fwidth, int* active) int NBP::NBPGetNotch (RXA& rxa, int notch, double* fcenter, double* fwidth, int* active)
{ {
NOTCHDB *a; NOTCHDB *a;
int rval; int rval;
@ -512,7 +512,7 @@ int NBP::NBPDeleteNotch (RXA& rxa, int notch)
return rval; return rval;
} }
int NBP::NBPEditNotch (RXA& rxa, int notch, float fcenter, float fwidth, int active) int NBP::NBPEditNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active)
{ {
NOTCHDB *a; NOTCHDB *a;
int rval; int rval;
@ -539,7 +539,7 @@ void NBP::NBPGetNumNotches (RXA& rxa, int* nnotches)
*nnotches = a->nn; *nnotches = a->nn;
} }
void NBP::NBPSetTuneFrequency (RXA& rxa, float tunefreq) void NBP::NBPSetTuneFrequency (RXA& rxa, double tunefreq)
{ {
NOTCHDB *a; NOTCHDB *a;
a = rxa.ndb.p; a = rxa.ndb.p;
@ -551,7 +551,7 @@ void NBP::NBPSetTuneFrequency (RXA& rxa, float tunefreq)
} }
} }
void NBP::NBPSetShiftFrequency (RXA& rxa, float shift) void NBP::NBPSetShiftFrequency (RXA& rxa, double shift)
{ {
NOTCHDB *a; NOTCHDB *a;
a = rxa.ndb.p; a = rxa.ndb.p;
@ -589,7 +589,7 @@ void NBP::NBPSetRun (RXA& rxa, int run)
a->run = run; a->run = run;
} }
void NBP::NBPSetFreqs (RXA& rxa, float flow, float fhigh) void NBP::NBPSetFreqs (RXA& rxa, double flow, double fhigh)
{ {
NBP *a; NBP *a;
a = rxa.nbp0.p; a = rxa.nbp0.p;
@ -651,7 +651,7 @@ void NBP::NBPSetMP (RXA& rxa, int mp)
} }
} }
void NBP::NBPGetMinNotchWidth (RXA& rxa, float* minwidth) void NBP::NBPGetMinNotchWidth (RXA& rxa, double* minwidth)
{ {
NBP *a; NBP *a;
a = rxa.nbp0.p; a = rxa.nbp0.p;

View File

@ -39,14 +39,14 @@ class WDSP_API NOTCHDB
{ {
public: public:
int master_run; int master_run;
float tunefreq; double tunefreq;
float shift; double shift;
int nn; int nn;
int* active; int* active;
float* fcenter; double* fcenter;
float* fwidth; double* fwidth;
float* nlow; double* nlow;
float* nhigh; double* nhigh;
int maxnotches; int maxnotches;
static NOTCHDB* create_notchdb (int master_run, int maxnotches); static NOTCHDB* create_notchdb (int master_run, int maxnotches);
@ -63,19 +63,19 @@ public:
int size; // buffer size int size; // buffer size
int nc; // number of filter coefficients int nc; // number of filter coefficients
int mp; // minimum phase flag int mp; // minimum phase flag
float* in; // input buffer float* in; // input buffer
float* out; // output buffer float* out; // output buffer
float flow; // low bandpass cutoff freq double flow; // low bandpass cutoff freq
float fhigh; // high bandpass cutoff freq double fhigh; // high bandpass cutoff freq
float* impulse; // filter impulse response float* impulse; // filter impulse response
float rate; // sample rate double rate; // sample rate
int wintype; // filter window type int wintype; // filter window type
float gain; // filter gain double gain; // filter gain
int autoincr; // auto-increment notch width int autoincr; // auto-increment notch width
int maxpb; // maximum number of passbands int maxpb; // maximum number of passbands
NOTCHDB* ptraddr; // ptr to addr of notch-database data structure NOTCHDB* ptraddr; // ptr to addr of notch-database data structure
float* bplow; // array of passband lows double* bplow; // array of passband lows
float* bphigh; // array of passband highs double* bphigh; // array of passband highs
int numpb; // number of passbands int numpb; // number of passbands
FIRCORE *p; FIRCORE *p;
int havnotch; int havnotch;
@ -90,11 +90,11 @@ public:
int mp, int mp,
float* in, float* in,
float* out, float* out,
float flow, double flow,
float fhigh, double fhigh,
int rate, int rate,
int wintype, int wintype,
float gain, double gain,
int autoincr, int autoincr,
int maxpb, int maxpb,
NOTCHDB* ptraddr NOTCHDB* ptraddr
@ -111,40 +111,40 @@ public:
// RXA Properties // RXA Properties
static void UpdateNBPFiltersLightWeight (RXA& rxa); static void UpdateNBPFiltersLightWeight (RXA& rxa);
static void UpdateNBPFilters(RXA& rxa); static void UpdateNBPFilters(RXA& rxa);
static int NBPAddNotch (RXA& rxa, int notch, float fcenter, float fwidth, int active); static int NBPAddNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active);
static int NBPGetNotch (RXA& rxa, int notch, float* fcenter, float* fwidth, int* active); static int NBPGetNotch (RXA& rxa, int notch, double* fcenter, double* fwidth, int* active);
static int NBPDeleteNotch (RXA& rxa, int notch); static int NBPDeleteNotch (RXA& rxa, int notch);
static int NBPEditNotch (RXA& rxa, int notch, float fcenter, float fwidth, int active); static int NBPEditNotch (RXA& rxa, int notch, double fcenter, double fwidth, int active);
static void NBPGetNumNotches (RXA& rxa, int* nnotches); static void NBPGetNumNotches (RXA& rxa, int* nnotches);
static void NBPSetTuneFrequency (RXA& rxa, float tunefreq); static void NBPSetTuneFrequency (RXA& rxa, double tunefreq);
static void NBPSetShiftFrequency (RXA& rxa, float shift); static void NBPSetShiftFrequency (RXA& rxa, double shift);
static void NBPSetNotchesRun (RXA& rxa, int run); static void NBPSetNotchesRun (RXA& rxa, int run);
static void NBPSetRun (RXA& rxa, int run); static void NBPSetRun (RXA& rxa, int run);
static void NBPSetFreqs (RXA& rxa, float flow, float fhigh); static void NBPSetFreqs (RXA& rxa, double flow, double fhigh);
static void NBPSetWindow (RXA& rxa, int wintype); static void NBPSetWindow (RXA& rxa, int wintype);
static void NBPSetNC (RXA& rxa, int nc); static void NBPSetNC (RXA& rxa, int nc);
static void NBPSetMP (RXA& rxa, int mp); static void NBPSetMP (RXA& rxa, int mp);
static void NBPGetMinNotchWidth (RXA& rxa, float* minwidth); static void NBPGetMinNotchWidth (RXA& rxa, double* minwidth);
static void NBPSetAutoIncrease (RXA& rxa, int autoincr); static void NBPSetAutoIncrease (RXA& rxa, int autoincr);
private: private:
static float* fir_mbandpass (int N, int nbp, float* flow, float* fhigh, float rate, float scale, int wintype); static float* fir_mbandpass (int N, int nbp, double* flow, double* fhigh, double rate, double scale, int wintype);
static float min_notch_width (NBP *a); static double min_notch_width (NBP *a);
static int make_nbp ( static int make_nbp (
int nn, int nn,
int* active, int* active,
float* center, double* center,
float* width, double* width,
float* nlow, double* nlow,
float* nhigh, double* nhigh,
float minwidth, double minwidth,
int autoincr, int autoincr,
float flow, double flow,
float fhigh, double fhigh,
float* bplow, double* bplow,
float* bphigh, double* bphigh,
int* havnotch int* havnotch
); );
static void calc_nbp_lightweight (NBP *a); static void calc_nbp_lightweight (NBP *a);