Various speed-ups, fixes and cleanups

* decay_avg
* Member modem must be initialised.
pull/1/head
Remi Chateauneu 2013-10-29 04:42:32 -05:00 zatwierdzone przez David Freese
rodzic 200db3bc48
commit e52626b284
3 zmienionych plików z 14 dodań i 15 usunięć

Wyświetl plik

@ -55,19 +55,14 @@ inline double clamp(double x, double min, double max)
return (x < min) ? min : ((x > max) ? max : x);
}
inline double decayavg(double average, double input, double weight)
/// This is always called with an int weight
inline double decayavg(double average, double input, int weight)
{
if (weight <= 1.0) return input;
return input * (1.0 / weight) + average * (1.0 - (1.0 / weight));
if (weight <= 1) return input;
return ( ( input - average ) / (double)weight ) + average ;
}
// following are defined inline to provide best performance
inline double rect(double x)
{
return 1.0;
}
inline double blackman(double x)
{
return (0.42 - 0.50 * cos(2 * M_PI * x) + 0.08 * cos(4 * M_PI * x));
@ -102,6 +97,4 @@ void BlackmanWindow(double *array, int n);
// Simple about effective as Hamming or Hanning
void TriangularWindow(double *array, int n);
#define fftabs(a,b) sqrt((a)*(a) + (b)*(b))
#endif

Wyświetl plik

@ -153,8 +153,9 @@ void RectWindow(double *array, int n) {
// Hamming - used by gmfsk
void HammingWindow(double *array, int n) {
double pwr = 0.0;
double inv_n = 1.0 / (double)n;
for (int i = 0; i < n; i++) {
array[i] = hamming((double)i/(double)n);
array[i] = hamming((double)i * inv_n);
pwr += array[i] * array[i];
}
pwr = sqrt((double)n/pwr);
@ -165,8 +166,9 @@ void HammingWindow(double *array, int n) {
// Hanning - used by winpsk
void HanningWindow(double *array, int n) {
double pwr = 0.0;
double inv_n = 1.0 / (double)n;
for (int i = 0; i < n; i++) {
array[i] = hanning((double)i/(double)n);
array[i] = hanning((double)i * inv_n);
pwr += array[i] * array[i];
}
pwr = sqrt((double)n/pwr);
@ -177,8 +179,9 @@ void HanningWindow(double *array, int n) {
// Best lob suppression - least in band ripple
void BlackmanWindow(double *array, int n) {
double pwr = 0.0;
double inv_n = 1.0 / (double)n;
for (int i = 0; i < n; i++) {
array[i] = blackman((double)i/(double)n);
array[i] = blackman((double)i * inv_n);
pwr += array[i] * array[i];
}
pwr = sqrt((double)n/pwr);
@ -190,8 +193,9 @@ void BlackmanWindow(double *array, int n) {
void TriangularWindow(double *array, int n) {
double pwr = 0.0;
for (int i = 0; i < n; i++) array[i] = 1.0;
double inv_n = 1.0 / (double)n;
for (int i = 0; i < n / 4; i++) {
array[i] = 4.0 * (double)i / (double)n;
array[i] = 4.0 * (double)i * inv_n ;
array[n-i] = array[i];
}
for (int i = 0; i < n; i++) pwr += array[i] * array[i];

Wyświetl plik

@ -201,6 +201,8 @@ modem::modem()
PTTphaseacc = 0.0;
s2n_ncount = s2n_sum = s2n_sum2 = s2n_metric = 0.0;
s2n_valid = false;
bandwidth = 0.0;
}
// modem types CW and RTTY do not use the base init()