blob: ff37fec02b0c9a8477805ad1b37e28fb38f7ddae [file] [log] [blame]
piotr4e65be92014-04-17 09:56:57 +02001/* -*- c++ -*- */
2/*
ptrkrysik529895b2014-12-02 18:07:38 +01003 * @file
4 * @author Piotr Krysik <ptrkrysik@gmail.com>
5 * @section LICENSE
piotr4e65be92014-04-17 09:56:57 +02006 *
ptrkrysik529895b2014-12-02 18:07:38 +01007 * Gr-gsm is free software; you can redistribute it and/or modify
piotr4e65be92014-04-17 09:56:57 +02008 * 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 *
ptrkrysik529895b2014-12-02 18:07:38 +010012 * Gr-gsm is distributed in the hope that it will be useful,
piotr4e65be92014-04-17 09:56:57 +020013 * 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
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
piotr4e65be92014-04-17 09:56:57 +020019 * 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
32boost::shared_ptr<Gnuplot> current_figure;
33
34void imagesc(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
42void plot(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
piotr7af92ca2014-07-08 16:38:42 +020049 (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines ";
piotr4e65be92014-04-17 09:56:57 +020050 (*current_figure) << std::endl;
51}
52
53void replot(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
63template<typename T>
64void plot(std::vector<T> & x){
65 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
66 plot(y,"");
67}
68
69template<typename T>
70void plot(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
75template<typename T>
76void replot(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