SigPack - the C++ signal processing library
filter_plot.cpp
Go to the documentation of this file.
1 
8 #include "sigpack.h"
9 
10 using namespace arma;
11 using namespace sp;
12 int main()
13 {
14  gplot gp;
15  gp.window("Filter plots", 10, 10, 700, 700);
16 
17  vec Mg(1024);
18  vec Ph(1024);
19  vec a, b;
20  a << 1 << endr;
21  b = fir1(44, 0.25);
22  Mg = 20 * log10(freqz(b, a, 1024));
23  Ph = phasez(b, a, 1024);
24 
25  // Plot
26  gp.set_term("qt");
27  gp.grid_on();
28  gp.send2gp("set multiplot layout 2, 1");
29  gp.send2gp("set xtics (\"0\" 1,\"0.5\" 512,\"1\" 1024)"); // Direct call to
30  // gnuplot pipe
31  gp.ylabel("Magnitude [dB]");
32  gp.xlabel("Frequency [f/Fs]");
33  gp.plot_add(Mg, "Filter");
34  gp.plot_show();
35  gp.send2gp("set xtics (\"0\" 1,\"0.5\" 512,\"1\" 1024)"); // Direct call to
36  // gnuplot pipe
37  gp.ylabel("Phase [rad]");
38  gp.xlabel("Frequency [f/Fs]");
39  gp.plot_add(Ph, "Filter");
40  gp.plot_show();
41  gp.send2gp("unset multiplot");
42 
43  return 0;
44 }
Gnuplot class.
Definition: gplot.h:25
arma_inline arma::vec phasez(const arma::vec b, const arma::vec a, const arma::uword K=512)
Frequency phase response function. Calculates the frequency phase response.
Definition: filter.h:779
Definition: base.h:7
void plot_show(void)
Show plots.
Definition: gplot.h:395
void grid_on(void)
Set grid.
Definition: gplot.h:225
void ylabel(const char *label)
Set label for X-axis.
Definition: gplot.h:248
arma_inline arma::vec freqz(const arma::vec b, const arma::vec a, const arma::uword K=512)
Frequency magnitude response function. Calculates the frequency magnitude response.
Definition: filter.h:765
void set_term(const char *ttype)
Set output terminal.
Definition: gplot.h:759
arma_inline arma::vec fir1(const arma::uword M, const double f0)
FIR lowpass design function. FIR lowpassdesign using windows method (hamming window). NB! Returns size M+1.
Definition: filter.h:607
void window(const int fig, const char *name, const int x, const int y, const int width, const int height)
Configure the figure used Windows environment.
Definition: gplot.h:182
void xlabel(const char *label)
Set label for X-axis.
Definition: gplot.h:236
void plot_add(const T1 &x, const T2 &y, const std::string lb, const std::string ls="lines")
Push plot y vs. x with label and linespec.
Definition: gplot.h:316
void send2gp(const char *cmdstr)
Send command to Gnuplot pipe.
Definition: gplot.h:141
int main()
Definition: filter_plot.cpp:12