Square wave generator

8 sierpnia 2010 01:41 tags:

The following code demonstrates how to use SquareGenerator class. As it is derived from SignalSource, it can be directly plotted with TextPlot. The square wave generator supports setting duty cycle as a fraction of period in which signal values are positive.

#include "aquila/source/generator/SquareGenerator.h"
#include "aquila/tools/TextPlot.h"

int main(int argc, char *argv[])
{
    Aquila::SquareGenerator generator(1000);
    generator.setFrequency(125).setAmplitude(255).generate(64);
    Aquila::TextPlot plot("Square wave");
    plot.plot(generator);

    generator.setDuty(0.25).generate(64);
    plot.setTitle("Square wave, duty cycle = 25%");
    plot.plot(generator);

    generator.setDuty(0.75).generate(64);
    plot.setTitle("Square wave, duty cycle = 75%");
    plot.plot(generator);

    return 0;
}

Output:

Square wave
****    ****    ****    ****    ****    ****    ****    ****














    ****    ****    ****    ****    ****    ****    ****    ****

Square wave, duty cycle = 25%
**      **      **      **      **      **      **      **














  ******  ******  ******  ******  ******  ******  ******  ******

Square wave, duty cycle = 75%
******  ******  ******  ******  ******  ******  ******  ******














      **      **      **      **      **      **      **      **
« Return to list