예제 #1
0
void GNUPlotOut::out(const std::string& name) {
    Gnuplot plot;
    plot.set_title(name.c_str());
    plot.set_style("lines");
    plot.cmd("set terminal png size 1024,768");
    plot.cmd("set output \"" + name + ".png\"");
    plot.plot_xy(_y, _x);

    //std::cin.get();
}
예제 #2
0
파일: main.cpp 프로젝트: cco2013-1/INE5408
/**
 * Function generateGraphs
 * This function calls gnuplot to generate graphs from the
 * output files. The graphs are saved in the working directory
 * as png files.
 * The module used can be obtained at https://code.google.com/p/gnuplot-cpp/
 */
void generateGraphs(const string &outputFileInsertion, const string &outpuFileDeletion,
                    const string &graphOutputFileInsertion, const string &graphOutputFileDeletion) {
    cout << "Gerando graficos." << endl;
    Gnuplot gp;
    string cmd = "set term png";
    gp.cmd(cmd);
    cmd = "set output '" + graphOutputFileInsertion + "'";
    gp.cmd(cmd);
    cmd = "plot '" + outputFileInsertion + "'";
    gp.cmd(cmd);
    cmd = "set output '" + graphOutputFileDeletion + "'";
    gp.cmd(cmd);
    cmd = "plot '" + outpuFileDeletion + "'";
    gp.cmd(cmd);
}
예제 #3
0
파일: main.cpp 프로젝트: AE9RB/dspp
void plot_window(function<vector<double>(size_t, bool)> fn, const char* name, const char* filename) {
    Gnuplot p;
    auto w = fn(1025, true);
    auto aw = fn(8192, false);
    auto* o = new array<double, 810>;
    auto* a = new array<complex<double>, 8192>;

    double min = 0;
    for (auto i : w) if (i < min) min = i;

    double d = 0;
    for (auto i : aw) d+=i;

    // Usually, you see the Fourier transform of a window generated by placing
    // the window at the start of a zeroed array then running the dft.
    // However, it will not accurately show the side lobe attenuation.
    // This version sends an actual signal through the window and FFT.
    // The signal frequency is "wiggled" to gather 10 samples per bin.
    for (int j=0; j < 10; ++j) {
        for (int i=0; i < 8192; ++i) {
            double f = two_pi() * (i/(2.0 + (j-5)/20480.0));
            (*a)[i] = complex<double>(aw[i] * cos(f), aw[i] * sin(f));
        }
        FFT::dft(*a);
        for (int i=0; i < 81; ++i) {
            (*o)[i*10+j] = abs((*a)[i+4096-40]) / d;
        }
    }

    p.cmd("set term pngcairo size 768,240 font 'Lucida Grande,9'");
    p << "set output 'images/window_" << filename << ".png'" << endl;
    p.cmd("set title offset 0,-0.8 font ',11'");
    p.cmd("set size 0.5,1.03");
    p.cmd("set xtics offset 0,0.1");
    p.cmd("set xlabel offset 0,0.6");

    p.cmd("set grid");

    p.cmd("set multiplot");
    p.cmd("set ylabel offset 2.0,0.0");
    p.cmd("set linetype 1 lc rgb '#8B4513' lw 1.1");

    p << "set title '" << name << "'" << endl;
    p << "set yrange [" << min << ":1.04]" << endl;
    p.cmd("set ytics autofreq 0,0.1");
    p.cmd("set ylabel 'amplitude'");
    p.cmd("set xrange [0:1024]");
    p.cmd("set xtics ('0' 0, '' 128, '' 256, '' 384, '' 512, '' 640, '' 768, '' 896, 'N-1' 1024)");
    p.cmd("set xlabel 'samples'");
    p.cmd("plot '-' with lines notitle");
    for (auto v : w) {
        p << v << "\n";
    }
    p.cmd("e");

    p.cmd("set origin 0.5,0.00");
    p.cmd("set title 'Fourier transform'");
    p.cmd("set yrange [-130:5]");
    p.cmd("set ytics autofreq -130,10");
    p.cmd("set ylabel 'decibels'");
    p.cmd("set xrange [0:801]");
    p.cmd("set xtics ('-40' 0, '-30' 100, '-20' 200, '-10' 300, '0' 400, '10' 500, '20' 600, '30' 700, '40' 801)");
    p.cmd("set xlabel 'bins'");
    p.cmd("plot '-' with lines notitle");
    for (int i=5; i< 807; ++i) {
        p << 20*log10((*o)[i]) << "\n";
    }
    p.cmd("e");

    delete o;
    delete a;
}