99 qreal norm1 = tf_matrix.maxCoeff();
100 qreal mnorm = tf_matrix.minCoeff();
101 if (std::fabs(mnorm) > norm1)
106 QImage* image_to_tf_plot =
new QImage(tf_matrix.cols(), tf_matrix.rows(), QImage::Format_RGB32);
110 for (qint32 y = 0; y < tf_matrix.rows(); y++) {
111 for (qint32 x = 0; x < tf_matrix.cols(); x++) {
132 image_to_tf_plot->setPixel(x, tf_matrix.rows() - 1 - y, color.rgb());
136 *image_to_tf_plot = image_to_tf_plot->scaled(tf_matrix.cols(), tf_matrix.cols() / 2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
137 *image_to_tf_plot = image_to_tf_plot->scaledToWidth( 1026, Qt::SmoothTransformation);
139 QGraphicsPixmapItem* tf_pixmap =
new QGraphicsPixmapItem(QPixmap::fromImage(*image_to_tf_plot));
141 QGraphicsScene* tf_scene =
new QGraphicsScene();
142 tf_scene->addItem(tf_pixmap);
144 QImage* coeffs_image =
new QImage(10, tf_matrix.rows(), QImage::Format_RGB32);
145 qreal norm = tf_matrix.maxCoeff();
146 for (qint32 it = 0; it < tf_matrix.rows(); it++) {
147 for (qint32 x = 0; x < 10; x++) {
168 coeffs_image->setPixel(x, tf_matrix.rows() - 1 - it, color.rgb());
172 *coeffs_image = coeffs_image->scaled(10, tf_matrix.cols() / 2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
173 *coeffs_image = coeffs_image->scaledToHeight(image_to_tf_plot->height(), Qt::SmoothTransformation);
175 QLayout* layout =
new QGridLayout();
176 QGraphicsView* view =
new QGraphicsView();
177 view->setObjectName(
"tf_view");
178 view->setScene(tf_scene);
179 QLinearGradient lgrad(tf_scene->sceneRect().topLeft(), tf_scene->sceneRect().bottomRight());
180 lgrad.setColorAt(0.0, Qt::white);
181 lgrad.setColorAt(1.0, Qt::lightGray);
183 tf_scene->setBackgroundBrush(lgrad);
186 QGraphicsTextItem* x_axis_name =
new QGraphicsTextItem(
"time [sec]", tf_pixmap);
187 x_axis_name->setFont(QFont(
"arial", 14));
189 QList<QGraphicsItem*> x_axis_values;
190 QList<QGraphicsItem*> x_axis_lines;
192 qreal scaleXText = (tf_matrix.cols() - 1) / sample_rate / 20.0;
194 for (qint32 j = 0; j < 21; j++) {
195 QGraphicsTextItem* text_item =
new QGraphicsTextItem(QString::number(j * scaleXText,
'f', 2), tf_pixmap);
196 text_item->setFont(QFont(
"arial", 10));
197 x_axis_values.append(text_item);
198 QGraphicsLineItem* x_line_item =
new QGraphicsLineItem(tf_pixmap);
199 x_line_item->setLine(0, -3, 0, 3);
200 x_line_item->setPen(QPen(Qt::darkGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
201 x_axis_lines.append(x_line_item);
204 x_axis_name->setPos(tf_pixmap->boundingRect().width() / 2 - x_axis_name->boundingRect().width() / 2,
205 tf_pixmap->boundingRect().height() + 0.8 * x_axis_values.at(0)->boundingRect().height());
207 qreal scale_x = qreal(tf_pixmap->boundingRect().width()) / qreal(x_axis_values.length() - 1);
209 for (qint32 i = 0; i < x_axis_values.length(); i++) {
210 x_axis_values.at(i)->setPos(qreal(i) * scale_x - x_axis_values.at(0)->boundingRect().width() / 2,
211 tf_pixmap->boundingRect().height());
212 x_axis_lines.at(i)->setPos(qreal(i) * scale_x,
213 tf_pixmap->boundingRect().height());
218 QGraphicsTextItem* y_axis_name =
new QGraphicsTextItem(
"frequency [Hz]", tf_pixmap);
219 y_axis_name->setFont(QFont(
"arial", 14));
221 QList<QGraphicsItem*> y_axis_values;
222 QList<QGraphicsItem*> y_axis_lines;
224 qreal scale_y_text = 0;
226 if (lower_frq == 0 && upper_frq == 0) {
227 scale_y_text = 0.5 * sample_rate / 10.0;
229 scale_y_text = (upper_frq - lower_frq) / 10.0;
232 for (qint32 j = 0; j < 11; j++) {
233 QGraphicsTextItem* text_item =
new QGraphicsTextItem(QString::number(lower_frq + j * scale_y_text,
236 text_item->setFont(QFont(
"arial", 10));
237 y_axis_values.append(text_item);
238 QGraphicsLineItem* y_line_item =
new QGraphicsLineItem(tf_pixmap);
239 y_line_item->setLine(-3, 0, 3, 0);
240 y_line_item->setPen(QPen(Qt::darkGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
241 y_axis_lines.append(y_line_item);
244 y_axis_name->setPos(-x_axis_values.at(0)->boundingRect().width() - y_axis_name->boundingRect().height(),
245 tf_pixmap->boundingRect().height() / 2 + y_axis_name->boundingRect().height() / 2);
246 y_axis_name->setRotation(-90);
248 qreal scale_y = qreal(tf_pixmap->boundingRect().height()) / qreal(y_axis_values.length() - 1);
250 for (qint32 i = 0; i < y_axis_values.length(); i++) {
251 y_axis_values.at(i)->setPos(-y_axis_values.last()->boundingRect().width() - 0.5 * y_axis_lines.last()->boundingRect().width() - 1, tf_pixmap->boundingRect().height() - y_axis_values.last()->boundingRect().height() / 2 - qreal(i) * scale_y);
252 y_axis_lines.at(i)->setPos(0, qreal(i) * scale_y);
256 QGraphicsPixmapItem* coeffs_item = tf_scene->addPixmap(QPixmap::fromImage(*coeffs_image));
257 coeffs_item->setParentItem(tf_pixmap);
258 coeffs_item->setPos(tf_pixmap->boundingRect().width() + 5, 0);
260 QGraphicsSimpleTextItem* axis_name_item =
new QGraphicsSimpleTextItem(
"coefficients", coeffs_item);
261 QGraphicsSimpleTextItem* axis_zero_item =
new QGraphicsSimpleTextItem(
"0", coeffs_item);
262 QGraphicsSimpleTextItem* axis_one_item =
new QGraphicsSimpleTextItem(
"1", coeffs_item);
263 axis_name_item->setFont(QFont(
"arial", 14));
264 axis_zero_item->setFont(QFont(
"arial", 10));
265 axis_one_item->setFont(QFont(
"arial", 10));
267 axis_name_item->setPos(coeffs_item->boundingRect().width() + 1,
268 coeffs_item->boundingRect().height() / 2 + axis_name_item->boundingRect().height() / 2);
269 axis_name_item->setRotation(-90);
270 axis_zero_item->setPos(1 + coeffs_item->boundingRect().width(),
271 coeffs_item->boundingRect().height() - axis_zero_item->boundingRect().height());
272 axis_one_item->setPos(1 + coeffs_item->boundingRect().width(), 0);
275 view->fitInView(layout->contentsRect(), Qt::KeepAspectRatio);
276 layout->addWidget(view);
277 this->setLayout(layout);