-
Notifications
You must be signed in to change notification settings - Fork 1
/
widget.hpp
181 lines (160 loc) · 3.98 KB
/
widget.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <QComboBox>
#include <QFile>
#include <QTextStream>
#include <boost/circular_buffer.hpp>
#include <rtxi/dsp/dolph.h>
#include <rtxi/dsp/fir_dsgn.h>
#include <rtxi/dsp/firideal.h>
#include <rtxi/dsp/gen_win.h>
#include <rtxi/dsp/hamming.h>
#include <rtxi/dsp/hann.h>
#include <rtxi/dsp/kaiser.h>
#include <rtxi/dsp/lin_dsgn.h>
#include <rtxi/dsp/rectnglr.h>
#include <rtxi/dsp/trianglr.h>
#include <rtxi/widgets.hpp>
// This is an generated header file. You may change the namespace, but
// make sure to do the same in implementation (.cpp) file
namespace fir_window
{
constexpr std::string_view MODULE_NAME = "fir-window";
enum window_t : int64_t
{
RECT = 0,
TRI,
HAMM,
HANN,
CHEBY,
KAISER
};
enum filter_t : int64_t
{
LOWPASS = 0,
HIGHPASS,
BANDPASS,
BANDSTOP
};
enum PARAMETER : Widgets::Variable::Id
{
// set parameter ids here
WINDOW_TYPE = 0,
FILTER_TYPE,
TAPS,
FREQUENCY_1,
FREQUENCY_2,
CHEBYSHEV_ATTENUATION,
KAISER_ALPHA_ATTENUATION
};
inline std::vector<Widgets::Variable::Info> get_default_vars()
{
return {
{PARAMETER::WINDOW_TYPE,
"Window Type",
"Type of window to use in the filter",
Widgets::Variable::INT_PARAMETER,
fir_window::RECT},
{PARAMETER::FILTER_TYPE,
"Filter Type",
"Type of filter to use",
Widgets::Variable::INT_PARAMETER,
fir_window::LOWPASS},
{PARAMETER::TAPS,
"# Taps",
"Number of Filter Taps (Odd Number)",
Widgets::Variable::INT_PARAMETER,
int64_t {9}},
{
PARAMETER::FREQUENCY_1,
"Frequency 1 (Hz)",
"Cut off Frequency #1 as Fraction of Pi, used for Lowpass/Highpass",
Widgets::Variable::DOUBLE_PARAMETER,
0.1,
},
{
PARAMETER::FREQUENCY_2,
"Frequency 2 (Hz)",
"Cut off Frequency #1 as Fraction of Pi, not used for "
"Lowpass/Highpass",
Widgets::Variable::DOUBLE_PARAMETER,
0.6,
},
{
PARAMETER::CHEBYSHEV_ATTENUATION,
"Chebyshev (dB)",
"Attenuation Parameter for Chebyshev Window",
Widgets::Variable::DOUBLE_PARAMETER,
70.0,
},
{PARAMETER::KAISER_ALPHA_ATTENUATION,
"Kaiser Alpha",
"Attenuation Parameter for Kaiser Window",
Widgets::Variable::DOUBLE_PARAMETER,
1.5}};
}
inline std::vector<IO::channel_t> get_default_channels()
{
return {{
"Input",
"Input to Filter",
IO::INPUT,
},
{
"Output",
"Output of Filter",
IO::OUTPUT,
}};
}
class Panel : public Widgets::Panel
{
Q_OBJECT
public:
Panel(QMainWindow* main_window, Event::Manager* ev_manager);
void customizeGUI();
private:
// FIRwindow functions
QComboBox* windowShape;
QComboBox* filterType;
// Saving FIR filter data to file without Data Recorder
bool OpenFile(QString);
QFile dataFile;
QTextStream stream;
private slots:
// all custom slots
void saveFIRData(); // write filter parameters to a file
void updateWindow(int);
void updateFilterType(int);
// Any functions and data related to the GUI are to be placed here
};
class Component : public Widgets::Component
{
public:
explicit Component(Widgets::Plugin* hplugin);
void execute() override;
private:
boost::circular_buffer<double> signalin;
double* convolution;
double out;
double dt;
int n;
void initParameters();
void bookkeep();
void makeFilter();
// double* h2;
double* h3; // filter coefficients
window_t window_shape;
filter_t filter_type;
int64_t num_taps;
double lambda1; // cutoff frequencies
double lambda2;
double Kalpha; // Kaiser window sidelobe attenuation parameter
double Calpha; // Chebyshev window sidelobe attenuation parameter
private:
GenericWindow* disc_window;
FirIdealFilter* filter_design;
};
class Plugin : public Widgets::Plugin
{
public:
explicit Plugin(Event::Manager* ev_manager);
};
} // namespace fir_window