SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
misc.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // misc.h -- Miscellaneous helper functions
3 //
4 // Copyright (C) 2006-2008
5 // Dave Freese, W1HKJ
6 //
7 // This file is part of fldigi. These filters were adapted from code contained
8 // in the gmfsk source code distribution.
9 //
10 // Fldigi is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Fldigi is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with fldigi. If not, see <http://www.gnu.org/licenses/>.
22 // ----------------------------------------------------------------------------
23 
24 #ifndef _MISC_H
25 #define _MISC_H
26 
27 #include <math.h>
28 
29 #undef M_PI
30 #define M_PI 3.14159265358979323846
31 
32 inline float sinc(float x)
33 {
34  return (fabs(x) < 1e-10) ? 1.0 : (sin(M_PI * x) / (M_PI * x));
35 }
36 
37 inline float cosc(float x)
38 {
39  return (fabs(x) < 1e-10) ? 0.0 : ((1.0 - cos(M_PI * x)) / (M_PI * x));
40 }
41 
42 inline float clamp(float x, float min, float max)
43 {
44  return (x < min) ? min : ((x > max) ? max : x);
45 }
46 
48 inline float decayavg(float average, float input, int weight)
49 {
50  if (weight <= 1) return input;
51  return ( ( input - average ) / (float)weight ) + average ;
52 }
53 
54 // following are defined inline to provide best performance
55 inline float blackman(float x)
56 {
57  return (0.42 - 0.50 * cos(2 * M_PI * x) + 0.08 * cos(4 * M_PI * x));
58 }
59 
60 inline float hamming(float x)
61 {
62  return 0.54 - 0.46 * cos(2 * M_PI * x);
63 }
64 
65 inline float hanning(float x)
66 {
67  return 0.5 - 0.5 * cos(2 * M_PI * x);
68 }
69 
70 inline float rcos( float t, float T, float alpha=1.0 )
71 {
72  if( t == 0 ) return 1.0;
73  float taT = T / (2.0 * alpha);
74  if( fabs(t) == taT ) return ((alpha/2.0) * sin(M_PI/(2.0*alpha)));
75  return (sin(M_PI*t/T)/(M_PI*t/T))*cos(alpha*M_PI*t/T)/(1.0-(t/taT)*(t/taT));
76 }
77 
78 #endif
float decayavg(float average, float input, int weight)
This is always called with an int weight.
Definition: misc.h:48
float sinc(float x)
Definition: misc.h:32
Fixed< IntType, IntBits > cos(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2271
float hamming(float x)
Definition: misc.h:60
float clamp(float x, float min, float max)
Definition: misc.h:42
float blackman(float x)
Definition: misc.h:55
Fixed< IntType, IntBits > sin(Fixed< IntType, IntBits > const &x)
Definition: fixed.h:2265
float cosc(float x)
Definition: misc.h:37
float rcos(float t, float T, float alpha=1.0)
Definition: misc.h:70
float hanning(float x)
Definition: misc.h:65
#define M_PI
Definition: misc.h:30
T max(const T &x, const T &y)
Definition: framework.h:446
T min(const T &x, const T &y)
Definition: framework.h:440