99 qreal norm1 = tf_matrix.maxCoeff();
100 qreal mnorm = tf_matrix.minCoeff();
101 if(std::fabs(mnorm) > norm1) norm1 = mnorm;
105 QImage * image_to_tf_plot =
new QImage(tf_matrix.cols(), tf_matrix.rows(), QImage::Format_RGB32);
109 for ( qint32 y = 0; y < tf_matrix.rows(); y++ ) {
110 for ( qint32 x = 0; x < tf_matrix.cols(); x++ ) {
131 image_to_tf_plot->setPixel(x, tf_matrix.rows() - 1 - y, color.rgb());
135 *image_to_tf_plot = image_to_tf_plot->scaled(tf_matrix.cols(), tf_matrix.cols()/2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
136 *image_to_tf_plot = image_to_tf_plot->scaledToWidth( 1026, Qt::SmoothTransformation);
138 QGraphicsPixmapItem *tf_pixmap =
new QGraphicsPixmapItem(QPixmap::fromImage(*image_to_tf_plot));
140 QGraphicsScene *tf_scene =
new QGraphicsScene();
141 tf_scene->addItem(tf_pixmap);
143 QImage * coeffs_image =
new QImage(10, tf_matrix.rows(), QImage::Format_RGB32);
144 qreal norm = tf_matrix.maxCoeff();
145 for(qint32 it = 0; it < tf_matrix.rows(); it++) {
146 for ( qint32 x = 0; x < 10; x++ ) {
167 coeffs_image->setPixel(x, tf_matrix.rows() - 1 - it, color.rgb());
171 *coeffs_image = coeffs_image->scaled(10, tf_matrix.cols()/2, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
172 *coeffs_image = coeffs_image->scaledToHeight(image_to_tf_plot->height(), Qt::SmoothTransformation);
174 QLayout * layout =
new QGridLayout();
175 QGraphicsView * view =
new QGraphicsView();
176 view->setObjectName(
"tf_view");
177 view->setScene(tf_scene);
178 QLinearGradient lgrad(tf_scene->sceneRect().topLeft(), tf_scene->sceneRect().bottomRight());
179 lgrad.setColorAt(0.0, Qt::white);
180 lgrad.setColorAt(1.0, Qt::lightGray);
182 tf_scene->setBackgroundBrush(lgrad);
185 QGraphicsTextItem *x_axis_name =
new QGraphicsTextItem(
"time [sec]", tf_pixmap);
186 x_axis_name->setFont(QFont(
"arial", 14));
188 QList<QGraphicsItem *> x_axis_values;
189 QList<QGraphicsItem *> x_axis_lines;
191 qreal scaleXText = (tf_matrix.cols() - 1) / sample_rate / 20.0;
193 for(qint32 j = 0; j < 21; j++) {
194 QGraphicsTextItem *text_item =
new QGraphicsTextItem(QString::number(j * scaleXText,
'f', 2), tf_pixmap);
195 text_item->setFont(QFont(
"arial", 10));
196 x_axis_values.append(text_item);
197 QGraphicsLineItem *x_line_item =
new QGraphicsLineItem(tf_pixmap);
198 x_line_item->setLine(0,-3,0,3);
199 x_line_item->setPen(QPen(Qt::darkGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
200 x_axis_lines.append(x_line_item);
203 x_axis_name->setPos(tf_pixmap->boundingRect().width()/2 - x_axis_name->boundingRect().width()/2,
204 tf_pixmap->boundingRect().height() + 0.8 * x_axis_values.at(0)->boundingRect().height());
206 qreal scale_x = qreal(tf_pixmap->boundingRect().width()) / qreal(x_axis_values.length()-1);
208 for(qint32 i = 0; i < x_axis_values.length(); i++) {
209 x_axis_values.at(i)->setPos(qreal(i)*scale_x - x_axis_values.at(0)->boundingRect().width()/2,
210 tf_pixmap->boundingRect().height());
211 x_axis_lines.at(i)->setPos(qreal(i)*scale_x,
212 tf_pixmap->boundingRect().height());
217 QGraphicsTextItem *y_axis_name =
new QGraphicsTextItem(
"frequency [Hz]", tf_pixmap);
218 y_axis_name->setFont(QFont(
"arial", 14));
220 QList<QGraphicsItem *> y_axis_values;
221 QList<QGraphicsItem *> y_axis_lines;
223 qreal scale_y_text = 0;
225 if(lower_frq == 0 && upper_frq == 0) {
226 scale_y_text = 0.5* sample_rate / 10.0;
228 scale_y_text = (upper_frq - lower_frq) / 10.0;
231 for(qint32 j = 0; j < 11; j++) {
232 QGraphicsTextItem *text_item =
new QGraphicsTextItem(QString::number(lower_frq + j*scale_y_text,
234 text_item->setFont(QFont(
"arial", 10));
235 y_axis_values.append(text_item);
236 QGraphicsLineItem *y_line_item =
new QGraphicsLineItem(tf_pixmap);
237 y_line_item->setLine(-3,0,3,0);
238 y_line_item->setPen(QPen(Qt::darkGray, 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin));
239 y_axis_lines.append(y_line_item);
242 y_axis_name->setPos(- x_axis_values.at(0)->boundingRect().width() - y_axis_name->boundingRect().height(),
243 tf_pixmap->boundingRect().height()/2 + y_axis_name->boundingRect().height()/2);
244 y_axis_name->setRotation(-90);
246 qreal scale_y = qreal(tf_pixmap->boundingRect().height()) / qreal(y_axis_values.length()-1);
248 for(qint32 i = 0; i < y_axis_values.length(); i++) {
249 y_axis_values.at(i)->setPos( -y_axis_values.last()->boundingRect().width()
250 -0.5*y_axis_lines.last()->boundingRect().width()
252 ,tf_pixmap->boundingRect().height()
253 - y_axis_values.last()->boundingRect().height()/2
255 y_axis_lines.at(i)->setPos(0, qreal(i)*scale_y);
259 QGraphicsPixmapItem * coeffs_item = tf_scene->addPixmap(QPixmap::fromImage(*coeffs_image));
260 coeffs_item->setParentItem(tf_pixmap);
261 coeffs_item->setPos(tf_pixmap->boundingRect().width() +5, 0);
263 QGraphicsSimpleTextItem *axis_name_item =
new QGraphicsSimpleTextItem(
"coefficients", coeffs_item);
264 QGraphicsSimpleTextItem *axis_zero_item =
new QGraphicsSimpleTextItem(
"0", coeffs_item);
265 QGraphicsSimpleTextItem *axis_one_item =
new QGraphicsSimpleTextItem(
"1", coeffs_item);
266 axis_name_item->setFont(QFont(
"arial", 14));
267 axis_zero_item->setFont(QFont(
"arial", 10));
268 axis_one_item->setFont(QFont(
"arial", 10));
270 axis_name_item->setPos(coeffs_item->boundingRect().width() + 1,
271 coeffs_item->boundingRect().height()/2 + axis_name_item->boundingRect().height()/2);
272 axis_name_item->setRotation(-90);
273 axis_zero_item->setPos( 1 + coeffs_item->boundingRect().width(),
274 coeffs_item->boundingRect().height()- axis_zero_item->boundingRect().height());
275 axis_one_item->setPos( 1 + coeffs_item->boundingRect().width(), 0);
278 view->fitInView(layout->contentsRect(),Qt::KeepAspectRatio);
279 layout->addWidget(view);
280 this->setLayout(layout);