GNU Radio's GSM Package
plotting.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * @file
4  * @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com>
5  * @section LICENSE
6  *
7  * Gr-gsm is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * Gr-gsm is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with gr-gsm; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #define USE_CXX (__cplusplus >= 201103)
24 
25 #include <vector>
26 #include <armadillo>
27 #include <string>
28 #include <boost/make_shared.hpp>
29 
30 #include "gnuplot-iostream.h"
31 
32 std::shared_ptr<Gnuplot> current_figure;
33 
34 void imagesc(const arma::mat & x){
35  Gnuplot gp;
36  gp << "set palette rgb 3,2,2;";
37  gp << "plot ";
38  gp << gp.file1d(x) << "matrix with image";
39  gp << std::endl;
40 }
41 
42 void plot(const arma::cx_mat & x, std::string title){
43  arma::mat y = arma::abs(x);
44  if(current_figure.get()==NULL){
45  current_figure = boost::make_shared<Gnuplot>();
46  }
47  (*current_figure) << "plot ";
48 
49  (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines ";
50  (*current_figure) << std::endl;
51 }
52 
53 void replot(const arma::cx_mat & x, std::string title){
54  arma::mat y = arma::abs(x);
55  if(current_figure.get()==NULL){
56  current_figure = boost::make_shared<Gnuplot>();
57  }
58  (*current_figure) << "replot ";
59  (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines ";
60  (*current_figure) << std::endl;
61 }
62 
63 template<typename T>
64 void plot(const std::vector<T> & x){
65  arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
66  plot(y,"");
67 }
68 
69 template<typename T>
70 void plot(const std::vector<T> & x, std::string title){
71  arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
72  plot(y,title);
73 }
74 
75 template<typename T>
76 void replot(const std::vector<T> & x, std::string title){
77  arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
78  replot(y,title);
79 }
80 
void imagesc(const arma::mat &x)
Definition: plotting.h:34
std::shared_ptr< Gnuplot > current_figure
Definition: plotting.h:32
void replot(const arma::cx_mat &x, std::string title)
Definition: plotting.h:53
void plot(const arma::cx_mat &x, std::string title)
Definition: plotting.h:42