sin波にノイズを足したグラフ

sin波に正規分布から取った値を足した点を表示する。
plot.cpp

#include "plot.h"
#include <qwt_plot_curve.h>
#include <qwt_legend.h>
#include <random>

Plot::Plot(QWidget *parent) :
    QwtPlot(parent)
{
    setCanvasBackground(QColor(Qt::white));
    // 凡例
    insertLegend(new QwtLegend(), QwtPlot::BottomLegend);

    // 曲線の設定
    curve1_ = new QwtPlotCurve("sine");
    curve1_->setRenderHint(QwtPlotItem::RenderAntialiased);
    curve1_->setPen(QPen(Qt::red));
    curve1_->attach(this);

    dots1_ = new QwtPlotCurve("sine+noise");
    dots1_->setRenderHint(QwtPlotItem::RenderAntialiased);
    dots1_->setPen(QPen(Qt::blue, 5, Qt::SolidLine, Qt::RoundCap));
    dots1_->setStyle(QwtPlotCurve::Dots);
    dots1_->attach(this);

    // 曲線の描画
    plotCurve();
}

void Plot::plotCurve()
{
    const int kArraySize = 1000;
    const int kNumDots = 10;

    double x[kArraySize] = {}; // x
    double y[kArraySize] = {}; // y

    double xdots[kNumDots] = {};
    double ydots[kNumDots] = {}; 

    std::mt19937 engine( static_cast<unsigned long>(time(0)) );
    std::normal_distribution<double> dist(0.0, 0.2);

    for (int i = 0; i < kArraySize; ++i) {
        x[i] = i / (kArraySize-1.0);
        y[i] = sin(2.0*M_PI*x[i]);
    }

    for (int i = 0; i < kNumDots; ++i) {
        xdots[i] = i / (kNumDots-1.0);
        ydots[i] = sin(2.0*M_PI*xdots[i]) + dist(engine);
    }

    curve1_->setSamples(x, y, kArraySize);
    dots1_->setSamples(xdots, ydots, kNumDots);
}

正規分布c++0xの機能を使っているので、
QMAKE_CXXFLAGS += -std=c++0x
とproファイルに入力する。

点から元のsin波を推定したくなってくる。