kwave  18.07.70
Kwave::FrequencyResponseWidget Class Reference

#include <FrequencyResponseWidget.h>

Inheritance diagram for Kwave::FrequencyResponseWidget:
Inheritance graph
Collaboration diagram for Kwave::FrequencyResponseWidget:
Collaboration graph

Public Member Functions

 FrequencyResponseWidget (QWidget *parent)
 
virtual ~FrequencyResponseWidget () Q_DECL_OVERRIDE
 
virtual void init (double freq, int db_min, int db_max)
 
virtual void setFilter (Kwave::TransmissionFunction *func)
 
virtual void paintEvent (QPaintEvent *) Q_DECL_OVERRIDE
 

Private Attributes

double m_f_max
 
int m_db_min
 
int m_db_max
 
int m_decades
 
Kwave::TransmissionFunctionm_function
 

Detailed Description

displays a frequency response

Definition at line 37 of file FrequencyResponseWidget.h.

Constructor & Destructor Documentation

◆ FrequencyResponseWidget()

Kwave::FrequencyResponseWidget::FrequencyResponseWidget ( QWidget *  parent)
explicit

Constructor

Definition at line 33 of file FrequencyResponseWidget.cpp.

References init().

34  :QWidget(widget), m_f_max(0), m_db_min(0), m_db_max(0),
35  m_decades(0), m_function(Q_NULLPTR)
36 {
37  init(10000, -12, +12);
38 }
virtual void init(double freq, int db_min, int db_max)
Kwave::TransmissionFunction * m_function
Here is the call graph for this function:

◆ ~FrequencyResponseWidget()

Kwave::FrequencyResponseWidget::~FrequencyResponseWidget ( )
virtual

Destructor

Definition at line 41 of file FrequencyResponseWidget.cpp.

42 {
43 }

Member Function Documentation

◆ init()

void Kwave::FrequencyResponseWidget::init ( double  freq,
int  db_min,
int  db_max 
)
virtual

Initialize the widget dimensions.

Parameters
freqhighest frequency, will be internally rounded up to the next decade if necessary
db_minlowest amplitude in decibel
db_maxhighest amplitude in decibel

Definition at line 46 of file FrequencyResponseWidget.cpp.

References m_db_max, m_db_min, m_decades, m_f_max, and Kwave::toInt().

Referenced by FrequencyResponseWidget().

47 {
48  const int base = 10;
49  m_decades = Kwave::toInt(ceil(log(freq)/log(base)));
50  m_f_max = pow(base, m_decades);
51 
52  m_db_min = db_min;
53  m_db_max = db_max;
54 }
int toInt(T x)
Definition: Utils.h:127
Here is the call graph for this function:
Here is the caller graph for this function:

◆ paintEvent()

void Kwave::FrequencyResponseWidget::paintEvent ( QPaintEvent *  )
virtual
See also
QWidget::paintEvent()

Definition at line 65 of file FrequencyResponseWidget.cpp.

References Kwave::TransmissionFunction::at(), m_db_max, m_db_min, m_f_max, m_function, rect(), and Kwave::toInt().

66 {
67 // const int base = 10;
68 // const double m_frequency = m_f_max * 2/3;
69  const int width = this->width();
70  const int height = this->height();
71 
72  Q_ASSERT(width > 0);
73  Q_ASSERT(height > 0);
74  if ((width <= 0) || (height <= 0)) return;
75 
76  QPainter p(this);
77  p.fillRect(rect(), QBrush(palette().dark()));
78 
79  double scale = static_cast<double>(height-1) /
80  static_cast<double>(m_db_max-m_db_min);
81  double min = pow(10.0, static_cast<double>(m_db_min) / 10.0);
82  double max = pow(10.0, static_cast<double>(m_db_max) / 10.0);
83  p.setPen(Qt::green);//colorGroup().text());
84 
85  for (int x=0; x < width; x++) {
86  // transform x coordinate to frequency
87 
88 // // logarithmic frequency scale, didn't look so good :-(
89 // double f = pow(base, (double)m_decades * (double)x / (double)width);
90 
91  // linear frequency scale
92  double f = (m_f_max * static_cast<double>(x) /
93  static_cast<double>(width));
94 
95  // calculate the filter function's output at the given frequency
96  f = (f / m_f_max) * M_PI;
97  double a = (m_function) ? m_function->at(f): 1.0;
98 
99  // limit to upper and lower margins
100  if (a < min) a = min;
101  if (a > max) a = max;
102 
103  // convert to logarithmic scale
104  double db = 10.0 * log10(a);
105 
106  // draw one line
107  int y = height - Kwave::toInt((db - m_db_min) * scale);
108 
109  p.drawLine(x, y+1, x, height-1);
110  }
111 
112  // draw the zero db line
113  p.setPen(palette().text().color());
114  int y = height - Kwave::toInt((0.0 - m_db_min) * scale);
115  p.drawLine(0, y, width-1, y);
116 }
Kwave::TransmissionFunction * m_function
int toInt(T x)
Definition: Utils.h:127
virtual double at(double f)=0
static double rect(double param)
Definition: Functions.cpp:29
Here is the call graph for this function:

◆ setFilter()

void Kwave::FrequencyResponseWidget::setFilter ( Kwave::TransmissionFunction func)
virtual

Set a new transmission function and update the display

Definition at line 57 of file FrequencyResponseWidget.cpp.

References m_function.

59 {
60  m_function = func;
61  repaint();
62 }
Kwave::TransmissionFunction * m_function

Member Data Documentation

◆ m_db_max

int Kwave::FrequencyResponseWidget::m_db_max
private

highest amplitude in decibel

Definition at line 73 of file FrequencyResponseWidget.h.

Referenced by init(), and paintEvent().

◆ m_db_min

int Kwave::FrequencyResponseWidget::m_db_min
private

lowest amplitude in decibel

Definition at line 70 of file FrequencyResponseWidget.h.

Referenced by init(), and paintEvent().

◆ m_decades

int Kwave::FrequencyResponseWidget::m_decades
private

number of decades, calculated from m_f_max

Definition at line 76 of file FrequencyResponseWidget.h.

Referenced by init().

◆ m_f_max

double Kwave::FrequencyResponseWidget::m_f_max
private

highest frequency, rounded up to the next decade

Definition at line 67 of file FrequencyResponseWidget.h.

Referenced by init(), and paintEvent().

◆ m_function

Kwave::TransmissionFunction* Kwave::FrequencyResponseWidget::m_function
private

Pointer to a transmission function object, used for painting the frequency response.

Definition at line 82 of file FrequencyResponseWidget.h.

Referenced by paintEvent(), and setFilter().


The documentation for this class was generated from the following files: