Permalink
Browse files

plots: Add amplitude plot

ref #66
  • Loading branch information...
1 parent 58136f9 commit f7a6728c3e04a5608562b2c9db68789158062e2c @miek committed Apr 24, 2016
Showing with 19 additions and 0 deletions.
  1. +17 −0 plots.cpp
  2. +2 −0 plots.h
View
@@ -19,6 +19,7 @@
#include <gnuradio/top_block.h>
#include <gnuradio/analog/quadrature_demod_cf.h>
+#include <gnuradio/blocks/complex_to_mag.h>
#include <gnuradio/blocks/threshold_ff.h>
#include "grsamplebuffer.h"
#include "memory_sink.h"
@@ -35,6 +36,22 @@ Plot* Plots::samplePlot(std::shared_ptr<AbstractSampleSource> source)
return new TracePlot(source);
}
+Plot* Plots::amplitudePlot(std::shared_ptr<AbstractSampleSource> source)
+{
+ gr::top_block_sptr tb = gr::make_top_block("amp");
+ auto memSrc = gr::blocks::memory_source::make(8);
+ auto memSink = gr::blocks::memory_sink::make(4);
+ auto complexToMag = gr::blocks::complex_to_mag::make();
+ tb->connect(memSrc, 0, complexToMag, 0);
+ tb->connect(complexToMag, 0, memSink, 0);
+
+ return new TracePlot(
+ std::make_shared<GRSampleBuffer<std::complex<float>, float>>(
+ std::dynamic_pointer_cast<SampleSource<std::complex<float>>>(source).get(), tb, memSrc, memSink
+ )
+ );
+}
+
Plot* Plots::frequencyPlot(std::shared_ptr<AbstractSampleSource> source)
{
gr::top_block_sptr quad_demod_tb = gr::make_top_block("quad_demod");
View
@@ -37,6 +37,7 @@ class Plots
static std::multimap<std::type_index, PlotInfo> plots;
static Plot* samplePlot(std::shared_ptr<AbstractSampleSource> source);
+ static Plot* amplitudePlot(std::shared_ptr<AbstractSampleSource> source);
static Plot* frequencyPlot(std::shared_ptr<AbstractSampleSource> source);
static Plot* thresholdPlot(std::shared_ptr<AbstractSampleSource> source);
@@ -45,6 +46,7 @@ class Plots
public:
_init() {
plots.emplace(typeid(std::complex<float>), PlotInfo{"sample plot", samplePlot});
+ plots.emplace(typeid(std::complex<float>), PlotInfo{"amplitude plot", amplitudePlot});
plots.emplace(typeid(std::complex<float>), PlotInfo{"frequency plot", frequencyPlot});
plots.emplace(typeid(float), PlotInfo{"threshold plot", thresholdPlot});
};

0 comments on commit f7a6728

Please sign in to comment.