blob: d4e69333958ad05704208afaa426cf33cde4751c [file] [log] [blame]
piotr4e65be92014-04-17 09:56:57 +02001/* -*- c++ -*- */
2/*
ptrkrysik529895b2014-12-02 18:07:38 +01003 * @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004 * @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com>
ptrkrysik529895b2014-12-02 18:07:38 +01005 * @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
Piotr Krysikaaac6152019-04-01 09:32:49 +020034void imagesc(const arma::mat & x){
piotr4e65be92014-04-17 09:56:57 +020035 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
Piotr Krysikaaac6152019-04-01 09:32:49 +020042void plot(const arma::cx_mat & x, std::string title){
piotr4e65be92014-04-17 09:56:57 +020043 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
Piotr Krysikaaac6152019-04-01 09:32:49 +020053void replot(const arma::cx_mat & x, std::string title){
piotr4e65be92014-04-17 09:56:57 +020054 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>
Piotr Krysikaaac6152019-04-01 09:32:49 +020064void plot(const std::vector<T> & x){
piotr4e65be92014-04-17 09:56:57 +020065 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
66 plot(y,"");
67}
68
69template<typename T>
Piotr Krysikaaac6152019-04-01 09:32:49 +020070void plot(const std::vector<T> & x, std::string title){
piotr4e65be92014-04-17 09:56:57 +020071 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
72 plot(y,title);
73}
74
75template<typename T>
Piotr Krysikaaac6152019-04-01 09:32:49 +020076void replot(const std::vector<T> & x, std::string title){
piotr4e65be92014-04-17 09:56:57 +020077 arma::cx_mat y = arma::conv_to<arma::cx_mat>::from(x);
78 replot(y,title);
79}
80