piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 3 | * @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | * @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com> |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 5 | * @section LICENSE |
piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 6 | * |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 7 | * Gr-gsm is free software; you can redistribute it and/or modify |
piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 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 | * |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 12 | * Gr-gsm is distributed in the hope that it will be useful, |
piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 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 |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 18 | * along with gr-gsm; see the file COPYING. If not, write to |
piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 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 | boost::shared_ptr<Gnuplot> current_figure; |
| 33 | |
| 34 | void 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 | |
| 42 | void 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 | |
piotr | 7af92ca | 2014-07-08 16:38:42 +0200 | [diff] [blame] | 49 | (*current_figure) << current_figure->file1d(y) <<"title \'" << title << "\' with lines "; |
piotr | 4e65be9 | 2014-04-17 09:56:57 +0200 | [diff] [blame] | 50 | (*current_figure) << std::endl; |
| 51 | } |
| 52 | |
| 53 | void 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 | |
| 63 | template<typename T> |
| 64 | void plot(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(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(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 | |